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/BaseRaw.js

52 lines
1.2 KiB

export class BaseRaw {
constructor(col) {
this.col = col;
}
_ensureDefaultFields(options) {
if (!this.defaultFields) {
return options;
}
if (!options) {
return { projection: this.defaultFields };
}
// TODO: change all places using "fields" for raw models and remove the additional condition here
if ((options.projection != null && Object.keys(options.projection).length > 0)
|| (options.fields != null && Object.keys(options.fields).length > 0)) {
return options;
}
return {
...options,
projection: this.defaultFields,
};
}
findOneById(_id, options = {}) {
return this.findOne({ _id }, options);
}
findOne(query = {}, options = {}) {
const optionsDef = this._ensureDefaultFields(options);
return this.col.findOne(query, optionsDef);
}
findUsersInRoles() {
throw new Error('overwrite-function', 'You must overwrite this function in the extended classes');
}
find(query = {}, options = {}) {
const optionsDef = this._ensureDefaultFields(options);
return this.col.find(query, optionsDef);
}
update(...args) {
return this.col.update(...args);
}
removeById(_id) {
return this.col.deleteOne({ _id });
}
}