Skip to content

Commit

Permalink
fix models
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Dec 27, 2024
1 parent 3be0d68 commit 9071dbf
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/model-typings/src/models/IInstanceStatusModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IInstanceStatus } from '@rocket.chat/core-typings';
import type { DeleteResult, ModifyResult, UpdateResult } from 'mongodb';
import type { DeleteResult, UpdateResult } from 'mongodb';

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

Expand All @@ -8,6 +8,6 @@ export interface IInstanceStatusModel extends IBaseModel<IInstanceStatus> {
getActiveInstancesAddress(): Promise<string[]>;
removeInstanceById(_id: IInstanceStatus['_id']): Promise<DeleteResult>;
setDocumentHeartbeat(documentId: string): Promise<UpdateResult>;
upsertInstance(instance: Partial<IInstanceStatus>): Promise<ModifyResult<IInstanceStatus>>;
upsertInstance(instance: Partial<IInstanceStatus>): Promise<IInstanceStatus | null>;
updateConnections(_id: IInstanceStatus['_id'], conns: number): Promise<UpdateResult>;
}
2 changes: 1 addition & 1 deletion packages/model-typings/src/models/IMessagesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export interface IMessagesModel extends IBaseModel<IMessage> {
removeThreadFollowerByThreadId(tmid: string, userId: string): Promise<UpdateResult>;

findThreadsByRoomId(rid: string, skip: number, limit: number): FindCursor<IMessage>;
decreaseReplyCountById(_id: string, inc?: number): Promise<ModifyResult<IMessage>>;
decreaseReplyCountById(_id: string, inc?: number): Promise<IMessage | null>;
countPinned(options?: CountDocumentsOptions): Promise<number>;
countStarred(options?: CountDocumentsOptions): Promise<number>;
}
4 changes: 2 additions & 2 deletions packages/models/src/dummy/BaseDummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export class BaseDummy<
return this.collectionName;
}

async findOneAndDelete(): Promise<T | null> {
async findOneAndDelete(): Promise<WithId<T> | null> {
return null;
}

async findOneAndUpdate(): Promise<T | null> {
async findOneAndUpdate(): Promise<WithId<T> | null> {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/models/InstanceStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IInstanceStatus } from '@rocket.chat/core-typings';
import type { IInstanceStatusModel } from '@rocket.chat/model-typings';
import type { Db, ModifyResult, UpdateResult, DeleteResult } from 'mongodb';
import type { Db, UpdateResult, DeleteResult } from 'mongodb';

import { BaseRaw } from './BaseRaw';

Expand Down Expand Up @@ -31,7 +31,7 @@ export class InstanceStatusRaw extends BaseRaw<IInstanceStatus> implements IInst
return this.updateOne({ _id: documentId }, { $currentDate: { _updatedAt: true } });
}

async upsertInstance(instance: Partial<IInstanceStatus>): Promise<ModifyResult<IInstanceStatus>> {
async upsertInstance(instance: Partial<IInstanceStatus>): Promise<IInstanceStatus | null> {
return this.findOneAndUpdate(
{
_id: instance._id,
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/models/LivechatContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
{ $set: { ...data, unknown: false, ...(data.channels && { preRegistration: !data.channels.length }) } },
{ returnDocument: 'after', ...options },
);
return updatedValue.value as ILivechatContact;
return updatedValue as ILivechatContact;
}

updateById(contactId: string, update: UpdateFilter<ILivechatContact>, options?: UpdateOptions): Promise<Document | UpdateResult> {
Expand Down Expand Up @@ -278,7 +278,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
async addEmail(contactId: string, email: string): Promise<ILivechatContact | null> {
const updatedContact = await this.findOneAndUpdate({ _id: contactId }, { $addToSet: { emails: { address: email } } });

return updatedContact.value;
return updatedContact;
}

countByContactInfo({ contactId, email, phone }: { contactId?: string; email?: string; phone?: string }): Promise<number> {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ export class MessagesRaw extends BaseRaw<IMessage> implements IMessagesModel {
return this.col.countDocuments(query);
}

decreaseReplyCountById(_id: string, inc = -1): Promise<ModifyResult<IMessage>> {
decreaseReplyCountById(_id: string, inc = -1): Promise<IMessage | null> {
const query = { _id };
const update: UpdateFilter<IMessage> = {
$inc: {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/Nps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class NpsRaw extends BaseRaw<INps> implements INpsModel {
status: NPSStatus.SENDING,
},
};
const { value } = await this.findOneAndUpdate(query, update, { sort: { expireAt: 1 } });
const value = await this.findOneAndUpdate(query, update, { sort: { expireAt: 1 } });

return value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/VideoConference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class VideoConferenceRaw extends BaseRaw<VideoConference> implements IVid
const { externalId, ...data } = call;

const doc = await this.findOneAndUpdate({ externalId }, { $set: data }, { upsert: true, returnDocument: 'after' });
return doc.value?._id;
return doc?._id;
}

public updateOneById(
Expand Down

0 comments on commit 9071dbf

Please sign in to comment.