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/Invites.ts

30 lines
712 B

import type { UpdateWriteOpResult } from 'mongodb';
import { BaseRaw } from './BaseRaw';
import { IInvite } from '../../../../definition/IInvite';
type T = IInvite;
export class InvitesRaw extends BaseRaw<T> {
findOneByUserRoomMaxUsesAndExpiration(userId: string, rid: string, maxUses: number, daysToExpire: number): Promise<T | null> {
return this.findOne({
rid,
userId,
days: daysToExpire,
maxUses,
...(daysToExpire > 0 ? { expires: { $gt: new Date() } } : {}),
...(maxUses > 0 ? { uses: { $lt: maxUses } } : {}),
});
}
increaseUsageById(_id: string, uses = 1): Promise<UpdateWriteOpResult> {
return this.updateOne(
{ _id },
{
$inc: {
uses,
},
},
);
}
}