The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/models/server/raw/CustomUserStatus.ts

57 lines
1.4 KiB

import { Cursor, FindOneOptions, InsertOneWriteOpResult, UpdateWriteOpResult, WithId, WithoutProjection } from 'mongodb';
import { BaseRaw, IndexSpecification } from './BaseRaw';
import { ICustomUserStatus as T } from '../../../../definition/ICustomUserStatus';
export class CustomUserStatusRaw extends BaseRaw<T> {
protected indexes: IndexSpecification[] = [{ key: { name: 1 } }];
// find one by name
async findOneByName(name: string, options: WithoutProjection<FindOneOptions<T>>): Promise<T | null> {
return this.findOne({ name }, options);
}
// find
findByName(name: string, options: WithoutProjection<FindOneOptions<T>>): Cursor<T> {
const query = {
name,
};
return this.find(query, options);
}
findByNameExceptId(name: string, except: string, options: WithoutProjection<FindOneOptions<T>>): Cursor<T> {
const query = {
_id: { $nin: [except] },
name,
};
return this.find(query, options);
}
// update
setName(_id: string, name: string): Promise<UpdateWriteOpResult> {
const update = {
$set: {
name,
},
};
return this.updateOne({ _id }, update);
}
setStatusType(_id: string, statusType: string): Promise<UpdateWriteOpResult> {
const update = {
$set: {
statusType,
},
};
return this.updateOne({ _id }, update);
}
// INSERT
create(data: T): Promise<InsertOneWriteOpResult<WithId<T>>> {
return this.insertOne(data);
}
}