import type { IEmojiCustom, RocketChatRecordDeleted } from '@rocket.chat/core-typings'; import type { IEmojiCustomModel, InsertionModel } from '@rocket.chat/model-typings'; import type { Collection, FindCursor, Db, FindOptions, IndexDescription, InsertOneResult, UpdateResult, WithId } from 'mongodb'; import { BaseRaw } from './BaseRaw'; export class EmojiCustomRaw extends BaseRaw implements IEmojiCustomModel { constructor(db: Db, trash?: Collection>) { super(db, 'custom_emoji', trash); } protected modelIndexes(): IndexDescription[] { return [{ key: { name: 1 } }, { key: { aliases: 1 } }, { key: { extension: 1 } }]; } // find findByNameOrAlias(emojiName: string, options?: FindOptions): FindCursor { let name = emojiName; if (typeof emojiName === 'string') { name = emojiName.replace(/:/g, ''); } const query = { $or: [{ name }, { aliases: name }], }; return this.find(query, options); } findByNameOrAliasExceptID(name: string, except: string, options?: FindOptions): FindCursor { const query = { _id: { $nin: [except] }, $or: [{ name }, { aliases: name }], }; return this.find(query, options); } // update setName(_id: string, name: string): Promise { const update = { $set: { name, }, }; return this.updateOne({ _id }, update); } setAliases(_id: string, aliases: string[]): Promise { const update = { $set: { aliases, }, }; return this.updateOne({ _id }, update); } setExtension(_id: string, extension: string): Promise { const update = { $set: { extension, }, }; return this.updateOne({ _id }, update); } // INSERT create(data: InsertionModel): Promise>> { return this.insertOne(data); } }