Skip to content

Commit

Permalink
refactor: removes redundant findOneById model implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogarim committed May 14, 2024
1 parent 6c38385 commit 94da5a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 2 additions & 6 deletions apps/meteor/server/models/raw/Permissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IPermission, IRole, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { IPermissionsModel } from '@rocket.chat/model-typings';
import type { Collection, Db, FindCursor, FindOptions, IndexDescription } from 'mongodb';
import type { Collection, Db, FindCursor, IndexDescription } from 'mongodb';

import { BaseRaw } from './BaseRaw';

Expand Down Expand Up @@ -39,7 +39,7 @@ export class PermissionsRaw extends BaseRaw<IPermission> implements IPermissions
}

async create(id: string, roles: IRole['_id'][]): Promise<IPermission['_id']> {
const exists = await super.findOneById(id, { projection: { _id: 1 } });
const exists = await this.findOneById(id, { projection: { _id: 1 } });
if (exists) {
return exists._id;
}
Expand All @@ -61,10 +61,6 @@ export class PermissionsRaw extends BaseRaw<IPermission> implements IPermissions
await this.updateOne({ _id: permission, roles: role }, { $pull: { roles: role } });
}

async findOneById(_id: IPermission['_id'], options?: FindOptions<IPermission>): Promise<IPermission | null> {
return super.findOneById(_id, options);
}

findByLevel(level: 'settings', settingId?: string): FindCursor<IPermission> {
return this.find({ level, ...(settingId && { settingId }) });
}
Expand Down
3 changes: 1 addition & 2 deletions packages/model-typings/src/models/IPermissionsModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IPermission, IRole } from '@rocket.chat/core-typings';
import type { FindCursor, FindOptions } from 'mongodb';
import type { FindCursor } from 'mongodb';

import type { IBaseModel } from './IBaseModel';

Expand All @@ -10,6 +10,5 @@ export interface IPermissionsModel extends IBaseModel<IPermission> {
setRoles(permission: string, roles: IRole['_id'][]): Promise<void>;
removeRole(permission: string, role: IRole['_id']): Promise<void>;
findByLevel(level: 'settings', settingId?: string): FindCursor<IPermission>;
findOneById(id: IPermission['_id'], options?: FindOptions<IPermission>): Promise<IPermission | null>;
findOneByGroupPermissionId(groupPermissionId: IPermission['groupPermissionId']): Promise<IPermission | null>;
}

0 comments on commit 94da5a2

Please sign in to comment.