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/apps/meteor/server/models/raw/OEmbedCache.ts

34 lines
951 B

import type { IOEmbedCache, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { IOEmbedCacheModel } from '@rocket.chat/model-typings';
import type { Collection, Db, DeleteResult, IndexDescription } from 'mongodb';
import { BaseRaw } from './BaseRaw';
export class OEmbedCacheRaw extends BaseRaw<IOEmbedCache> implements IOEmbedCacheModel {
constructor(db: Db, trash?: Collection<RocketChatRecordDeleted<IOEmbedCache>>) {
super(db, 'oembed_cache', trash);
}
protected modelIndexes(): IndexDescription[] {
return [{ key: { updatedAt: 1 } }];
}
async createWithIdAndData(_id: string, data: any): Promise<IOEmbedCache> {
const record = {
_id,
data,
updatedAt: new Date(),
};
record._id = (await this.insertOne(record)).insertedId;
return record;
}
removeAfterDate(date: Date): Promise<DeleteResult> {
const query = {
updatedAt: {
$lte: date,
},
};
return this.deleteMany(query);
}
}