Skip to content

Commit

Permalink
refactor: removes removeById from model and renames findActiveEmailIn…
Browse files Browse the repository at this point in the history
…boxes to findActive
  • Loading branch information
ricardogarim committed May 28, 2024
1 parent 7df2f55 commit e1bbd83
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/server/features/EmailInbox/EmailInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Inbox = {
export const inboxes = new Map<string, Inbox>();

export async function configureEmailInboxes(): Promise<void> {
const emailInboxesCursor = EmailInbox.findActiveEmailInboxes();
const emailInboxesCursor = EmailInbox.findActive();

logger.info('Clearing old email inbox registrations');
for (const { imap } of inboxes.values()) {
Expand Down
8 changes: 2 additions & 6 deletions apps/meteor/server/models/raw/EmailInbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IEmailInbox, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { IEmailInboxModel } from '@rocket.chat/model-typings';
import type { Collection, Db, DeleteResult, FindCursor, IndexDescription, InsertOneResult, ModifyResult, UpdateFilter } from 'mongodb';
import type { Collection, Db, FindCursor, IndexDescription, InsertOneResult, ModifyResult, UpdateFilter } from 'mongodb';

import { BaseRaw } from './BaseRaw';

Expand All @@ -17,10 +17,6 @@ export class EmailInboxRaw extends BaseRaw<IEmailInbox> implements IEmailInboxMo
return this.findOneAndUpdate({ _id: id, active: true }, { $set: { active: false } }, { returnDocument: 'after' });
}

async removeById(id: IEmailInbox['_id']): Promise<DeleteResult> {
return this.deleteOne({ _id: id });
}

async create(emailInbox: IEmailInbox): Promise<InsertOneResult<IEmailInbox>> {
return this.insertOne(emailInbox);
}
Expand All @@ -29,7 +25,7 @@ export class EmailInboxRaw extends BaseRaw<IEmailInbox> implements IEmailInboxMo
return this.findOneAndUpdate({ _id: id }, data, { returnDocument: 'after', projection: { _id: 1 } });
}

findActiveEmailInboxes(): FindCursor<IEmailInbox> {
findActive(): FindCursor<IEmailInbox> {
return this.find({ active: true });
}

Expand Down
5 changes: 2 additions & 3 deletions packages/model-typings/src/models/IEmailInboxModel.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { IEmailInbox } from '@rocket.chat/core-typings';
import type { DeleteResult, FindCursor, InsertOneResult, ModifyResult, UpdateFilter } from 'mongodb';
import type { FindCursor, InsertOneResult, ModifyResult, UpdateFilter } from 'mongodb';

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

export interface IEmailInboxModel extends IBaseModel<IEmailInbox> {
setDisabledById(id: IEmailInbox['_id']): Promise<ModifyResult<IEmailInbox>>;
removeById(id: IEmailInbox['_id']): Promise<DeleteResult>;
create(emailInbox: Omit<IEmailInbox, '_id'>): Promise<InsertOneResult<IEmailInbox>>;
updateById(id: IEmailInbox['_id'], data: UpdateFilter<IEmailInbox>): Promise<ModifyResult<IEmailInbox>>;
findActiveEmailInboxes(): FindCursor<IEmailInbox>;
findActive(): FindCursor<IEmailInbox>;
findByEmail(email: IEmailInbox['email']): Promise<IEmailInbox | null>;
findById(id: IEmailInbox['_id']): Promise<IEmailInbox | null>;
}

0 comments on commit e1bbd83

Please sign in to comment.