Skip to content

Commit

Permalink
fix(model): return entities instead of response data during attr resolve
Browse files Browse the repository at this point in the history
and also utilize dnis attr to resolve dnis prior to inbound/outbound
  • Loading branch information
BradenM committed Dec 7, 2021
1 parent 517872f commit ce6513f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/models/PhoneDnis.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// @flow
import moment from 'moment';
import { parsePhoneNumberFromString } from 'libphonenumber-js';
import CCUModel from '@/models/model';

export default class PhoneDnis extends CCUModel<PhoneDnis> {
export default class PhoneDnis extends CCUModel {
static entity = 'phone_dnis';

static fields() {
Expand Down
19 changes: 16 additions & 3 deletions src/models/phone/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export default class Contact extends Model {
}

get isReady(): boolean {
return this.hasResolvedCases && this.dnis !== null;
const target = this.isInbound ? this.inbound : this.outbound;
return this.hasResolvedCases && !_.isNil(target) && !_.isNil(this.dnis);
}

get mostRecentWorksite(): typeof Worksite | null {
Expand Down Expand Up @@ -678,7 +679,12 @@ export default class Contact extends Model {
);
Log.debug(`resolving <${model.entity}> @ [${itemIds}]`);
// TODO: Implement stale-while-revalidate caching method.
return model.fetchById(itemIds);
return model.fetchById(itemIds).then(() =>
model
.query()
.findIn(itemIds)
.filter((i) => !_.isNil(i)),
);
}

async getCallDuration() {
Expand Down Expand Up @@ -735,7 +741,14 @@ export default class Contact extends Model {
inbound: typeof PhoneInbound | null,
outbound: typeof PhoneOutbound | null,
} = {}): Promise<PhoneDnis | null> {
// first check for contact attr.
const _dnis = await this.resolveAttributeModels<typeof PhoneDnis>(
ContactAttributes.CALLER_DNIS_ID,
PhoneDnis,
);
if (!_.isNil(_dnis)) {
return _dnis;
}
// check for contact attr.
let _number = _.get(
this.contactAttributes,
ContactAttributes.INBOUND_NUMBER,
Expand Down

0 comments on commit ce6513f

Please sign in to comment.