Skip to content

Commit

Permalink
archiveDepartment
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 12, 2023
1 parent 7a0e2fc commit 2048242
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
3 changes: 2 additions & 1 deletion apps/meteor/app/livechat/imports/server/rest/departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../../../server/api/lib/departments';
import { DepartmentHelper } from '../../../server/lib/Departments';
import { Livechat } from '../../../server/lib/Livechat';
import { Livechat as LivechatTs } from '../../../server/lib/LivechatTyped';

API.v1.addRoute(
'livechat/department',
Expand Down Expand Up @@ -192,7 +193,7 @@ API.v1.addRoute(
},
{
async post() {
await Livechat.archiveDepartment(this.urlParams._id);
await LivechatTs.archiveDepartment(this.urlParams._id);

return API.v1.success();
},
Expand Down
18 changes: 0 additions & 18 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,24 +733,6 @@ export const Livechat = {
return LivechatDepartmentRaw.unarchiveDepartment(_id);
},

async archiveDepartment(_id) {
check(_id, String);

const department = await LivechatDepartmentRaw.findOneById(_id, { projection: { _id: 1 } });

if (!department) {
throw new Meteor.Error('department-not-found', 'Department not found', {
method: 'livechat:removeDepartment',
});
}

await LivechatDepartmentAgents.disableAgentsByDepartmentId(_id);
await LivechatDepartmentRaw.archiveDepartment(_id);

this.logger.debug({ msg: 'Running livechat.afterDepartmentArchived callback for department:', departmentId: _id });
await callbacks.run('livechat.afterDepartmentArchived', department);
},

showConnecting() {
const { showConnecting } = RoutingManager.getConfig();
return showConnecting;
Expand Down
12 changes: 12 additions & 0 deletions apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,18 @@ class LivechatClass {
sort: { ts: 1 },
}).toArray();
}

async archiveDepartment(_id: string) {
const department = await LivechatDepartment.findOneById(_id, { projection: { _id: 1 } });

if (!department) {
throw new Error('department-not-found');
}

await Promise.all([LivechatDepartmentAgents.disableAgentsByDepartmentId(_id), LivechatDepartment.archiveDepartment(_id)]);

await callbacks.run('livechat.afterDepartmentArchived', department);
}
}

export const Livechat = new LivechatClass();
2 changes: 2 additions & 0 deletions packages/model-typings/src/models/ILivechatDepartmentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ export interface ILivechatDepartmentModel extends IBaseModel<ILivechatDepartment
checkIfMonitorIsMonitoringDepartmentById(monitorId: string, departmentId: string): Promise<boolean>;
countArchived(): Promise<number>;
findEnabledInIds(departmentsIds: string[], options?: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment>;
archiveDepartment(_id: string): Promise<Document | UpdateResult>;
unarchiveDepartment(_id: string): Promise<Document | UpdateResult>;
}

0 comments on commit 2048242

Please sign in to comment.