Skip to content

Commit

Permalink
create getVisitorActiveForPeriodUpdateQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Aug 9, 2024
1 parent 1cf5983 commit a7fe604
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions apps/meteor/app/livechat/server/hooks/markRoomResponded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ export async function markRoomResponded(
}

if (!room.v?.activity?.includes(monthYear)) {
const [, livechatInquiry] = await Promise.all([
LivechatRooms.markVisitorActiveForPeriod(room._id, monthYear),
LivechatInquiry.markInquiryActiveForPeriod(room._id, monthYear),
]);
LivechatRooms.getVisitorActiveForPeriodUpdateQuery(monthYear, roomUpdater);
const livechatInquiry = await LivechatInquiry.markInquiryActiveForPeriod(room._id, monthYear);

if (livechatInquiry) {
void notifyOnLivechatInquiryChanged(livechatInquiry, 'updated', { v: livechatInquiry.v });
Expand Down
13 changes: 6 additions & 7 deletions apps/meteor/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2435,18 +2435,17 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
return this.updateOne(query, update);
}

getVisitorActiveForPeriodUpdateQuery(period: string, updater: Updater<IOmnichannelRoom> = this.getUpdater()): Updater<IOmnichannelRoom> {
return updater.addToSet('v.activity', period);
}

markVisitorActiveForPeriod(rid: string, period: string): Promise<UpdateResult> {
const query = {
_id: rid,
};
const updater = this.getVisitorActiveForPeriodUpdateQuery(period);

const update = {
$addToSet: {
'v.activity': period,
},
};

return this.updateOne(query, update);
return this.updateOne(query, updater.getUpdateFilter());
}

async getMACStatisticsForPeriod(period: string): Promise<MACStats[]> {
Expand Down
1 change: 1 addition & 0 deletions packages/model-typings/src/models/ILivechatRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export interface ILivechatRoomsModel extends IBaseModel<IOmnichannelRoom> {
changeVisitorByRoomId(roomId: string, visitor: { _id: string; username: string; token: string }): Promise<UpdateResult>;
unarchiveOneById(roomId: string): Promise<UpdateResult>;
markVisitorActiveForPeriod(rid: string, period: string): Promise<UpdateResult>;
getVisitorActiveForPeriodUpdateQuery(period: string, updater?: Updater<IOmnichannelRoom>): Updater<IOmnichannelRoom>;
getMACStatisticsForPeriod(period: string): Promise<MACStats[]>;
getMACStatisticsBetweenDates(start: Date, end: Date): Promise<MACStats[]>;
}

0 comments on commit a7fe604

Please sign in to comment.