import type { ILivechatUnitMonitor } from '@rocket.chat/core-typings'; import type { ILivechatUnitMonitorsModel } from '@rocket.chat/model-typings'; import { BaseRaw } from '@rocket.chat/models'; import type { Db, FindCursor, UpdateResult, DeleteResult, IndexDescription } from 'mongodb'; export class LivechatUnitMonitorsRaw extends BaseRaw implements ILivechatUnitMonitorsModel { constructor(db: Db) { super(db, 'livechat_unit_monitors'); } protected override modelIndexes(): IndexDescription[] { return [ { key: { unitId: 1, }, }, { key: { monitorId: 1, }, }, ]; } findByUnitId(unitId: string): FindCursor { return this.find({ unitId }); } findByMonitorId(monitorId: string): FindCursor { return this.find({ monitorId }); } saveMonitor(monitor: { monitorId: string; unitId: string; username: string }): Promise { return this.updateOne( { monitorId: monitor.monitorId, unitId: monitor.unitId, }, { $set: { monitorId: monitor.monitorId, unitId: monitor.unitId, username: monitor.username, }, }, { upsert: true }, ); } removeByUnitIdAndMonitorId(unitId: string, monitorId: string): Promise { return this.deleteMany({ unitId, monitorId }); } removeByUnitId(unitId: string): Promise { return this.deleteMany({ unitId }); } removeByMonitorId(monitorId: string): Promise { return this.deleteMany({ monitorId }); } }