Skip to content

Commit 108d44a

Browse files
committed
Update getPhoneNumber.ts
1 parent a52a8c8 commit 108d44a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

router/caller/getPhoneNumber.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,22 @@ export default async function getPhoneNumber(req: Request<any>, res: Response<an
131131
as: 'calls'
132132
}
133133
},
134+
{
135+
$addFields: {
136+
nbCalls: { $size: '$calls' },
137+
lastCall: { $ifNull: [{ $arrayElemAt: ['$calls.start', -1] }, null] },
138+
lastStatus: { $ifNull: [{ $arrayElemAt: ['$calls.status', -1] }, null] }
139+
}
140+
},
134141
{
135142
$match: {
136143
$and: [
137-
{ $or: [{ 'calls.status': 'to recall' }, { calls: { $size: 0 } }] }, // keep only client with status to recall or not called
144+
{ trashUser: { $ne: caller._id } }, // not a trash
145+
{ $or: [{ lastStatus: 'to recall' }, { calls: { $size: 0 } }] }, // keep only client with status to recall or not called
138146
{ campaigns: campaign._id } // only client from the campaign
139147
]
140148
}
141149
},
142-
{
143-
$addFields: {
144-
nbCalls: { $size: '$calls' },
145-
lastCall: { $ifNull: [{ $arrayElemAt: ['$calls.start', -1] }, null] }
146-
}
147-
},
148150
{
149151
$match: {
150152
$and: [

0 commit comments

Comments
 (0)