RocketChat/Rocket.Chat

View on GitHub
apps/meteor/server/models/raw/Reports.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { IMessage, IReport, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { IReportsModel } from '@rocket.chat/model-typings';
import type { Db, Collection } from 'mongodb';

import { BaseRaw } from './BaseRaw';

export class ReportsRaw extends BaseRaw<IReport> implements IReportsModel {
    constructor(db: Db, trash?: Collection<RocketChatRecordDeleted<IReport>>) {
        super(db, 'reports', trash);
    }

    createWithMessageDescriptionAndUserId(message: IMessage, description: string, userId: string): ReturnType<BaseRaw<IReport>['insertOne']> {
        const record: Pick<IReport, 'message' | 'description' | 'ts' | 'userId'> = {
            message,
            description,
            ts: new Date(),
            userId,
        };
        return this.insertOne(record);
    }
}