Skip to content

Commit

Permalink
Chore: Upgrade mongodb typings (#27424)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
  • Loading branch information
tassoevan and ggazzo authored Dec 5, 2022
1 parent 410ce05 commit af3ec69
Show file tree
Hide file tree
Showing 35 changed files with 1,109 additions and 200 deletions.
1 change: 0 additions & 1 deletion apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ API.v1.addRoute(
return API.v1.unauthorized();
}

// @ts-expect-error recursive types are causing issues here
const { cursor, totalCount } = Messages.findPaginated(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/apps/server/storage/AppGridFSSourceStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MongoInternals } from 'meteor/mongo';
import { ObjectId } from 'mongodb';
import type { GridFSBucket, GridFSBucketWriteStream } from 'mongodb';
import type { GridFSBucketWriteStream } from 'mongodb';
import { ObjectId, GridFSBucket } from 'mongodb';
import type { IAppStorageItem } from '@rocket.chat/apps-engine/server/storage';
import { AppSourceStorage } from '@rocket.chat/apps-engine/server/storage';

Expand All @@ -14,7 +14,6 @@ export class AppGridFSSourceStorage extends AppSourceStorage {
constructor() {
super();

const { GridFSBucket } = MongoInternals.NpmModules.mongodb.module;
const { db } = MongoInternals.defaultRemoteCollectionDriver().mongo;

this.bucket = new GridFSBucket(db, {
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api/lib/inquiries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export async function findInquiries({
],
};

// @ts-ignore - LivechatInquiry has a ref to messages
const { cursor, totalCount } = LivechatInquiry.findPaginated(filter, options);

const [inquiries, total] = await Promise.all([cursor.toArray(), totalCount]);
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api/lib/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function findLivechatTransferHistory({
rid: string;
pagination: { offset: number; count: number; sort: Record<string, number> };
}): Promise<PaginatedResult<{ history: IOmnichannelSystemMessage['transferData'][] }>> {
// @ts-ignore - Messages destroys everything it touches
const { cursor, totalCount } = Messages.findPaginated(
{ rid, t: 'livechat_transfer_history' },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import moment from 'moment-timezone';
import type { ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { ILivechatBusinessHoursModel, IUsersModel } from '@rocket.chat/model-typings';
import { LivechatBusinessHours, Users } from '@rocket.chat/models';
import type { UpdateFilter } from 'mongodb';

import type { IWorkHoursCronJobsWrapper } from '../../../../server/models/raw/LivechatBusinessHours';

Expand Down Expand Up @@ -62,7 +63,9 @@ export abstract class AbstractBusinessHourType {
businessHourData.active = Boolean(businessHourData.active);
businessHourData = this.convertWorkHours(businessHourData);
if (businessHourData._id) {
await this.BusinessHourRepository.updateOne({ _id: businessHourData._id }, { $set: businessHourData });
await this.BusinessHourRepository.updateOne({ _id: businessHourData._id }, {
$set: businessHourData,
} as UpdateFilter<ILivechatBusinessHour>); // TODO: Remove this cast when TypeScript is updated
return businessHourData._id;
}
const { insertedId } = await this.BusinessHourRepository.insertOne(businessHourData);
Expand Down
8 changes: 3 additions & 5 deletions apps/meteor/app/ui/client/lib/ChatMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,15 @@ export class ChatMessages {
readMessage.readNow(rid);
readMessage.refreshUnreadMark(rid);

const message = await onClientBeforeSendMessage({
const message = (await onClientBeforeSendMessage({
_id: Random.id(),
rid,
tshow,
tmid,
msg,
});
})) as IMessage;

try {
// @ts-ignore
await this.processMessageSend(message);
this.quotedMessages.clear();
} catch (error) {
Expand All @@ -405,8 +404,7 @@ export class ChatMessages {

try {
if (message.attachments && message.attachments?.length > 0) {
// @ts-ignore
await this.processMessageEditing({ _id: this.editing.id, rid, msg: '' });
await this.processMessageEditing({ _id: this.editing.id, rid, msg: '' } as IMessage);
return;
}

Expand Down
14 changes: 5 additions & 9 deletions apps/meteor/ee/server/lib/registerServiceModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,24 @@ import { EmailInboxRaw } from '../../../server/models/raw/EmailInbox';
import { PbxEventsRaw } from '../../../server/models/raw/PbxEvents';

// TODO add trash param to appropiate model instances
export function registerServiceModels(db: Db, trash?: Collection): void {
export function registerServiceModels(db: Db, trash?: Collection<RocketChatRecordDeleted<any>>): void {
registerModel('IRolesModel', () => new RolesRaw(db));
registerModel('IRoomsModel', () => new RoomsRaw(db));
registerModel('ISettingsModel', () => new SettingsRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ISetting>>));
registerModel(
'ISubscriptionsModel',
() => new SubscriptionsRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ISubscription>>),
);
registerModel('ISettingsModel', () => new SettingsRaw(db, trash as Collection<RocketChatRecordDeleted<ISetting>>));
registerModel('ISubscriptionsModel', () => new SubscriptionsRaw(db, trash as Collection<RocketChatRecordDeleted<ISubscription>>));
registerModel('ITeamModel', () => new TeamRaw(db));
registerModel('ITeamMemberModel', () => new TeamMemberRaw(db));
registerModel('IUsersModel', () => new UsersRaw(db));

// @ts-ignore-error
registerModel('IMessagesModel', () => new MessagesRaw(db));

registerModel(
'ILivechatInquiryModel',
() => new LivechatInquiryRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ILivechatInquiryRecord>>),
() => new LivechatInquiryRaw(db, trash as Collection<RocketChatRecordDeleted<ILivechatInquiryRecord>>),
);
registerModel(
'ILivechatDepartmentAgentsModel',
() => new LivechatDepartmentAgentsRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ILivechatDepartmentAgents>>),
() => new LivechatDepartmentAgentsRaw(db, trash as Collection<RocketChatRecordDeleted<ILivechatDepartmentAgents>>),
);
registerModel('IUsersSessionsModel', () => new UsersSessionsRaw(db));
registerModel('IPermissionsModel', () => new PermissionsRaw(db));
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/ee/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ declare module '@rocket.chat/model-typings' {
}
}

// Note: Expect a circular dependency error here 😓
export class LivechatRoomsRawEE extends LivechatRoomsRaw implements ILivechatRoomsModel {
async unsetAllPredictedVisitorAbandonment(): Promise<void> {
return this.updateMany(
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"jaeger-client": "^3.19.0",
"mem": "^8.1.1",
"moleculer": "^0.14.21",
"mongodb": "^4.3.1",
"mongodb": "^4.12.1",
"nats": "^2.6.1",
"pino": "^7.11.0",
"sodium-native": "^3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
"moleculer": "^0.14.21",
"moment": "^2.29.4",
"moment-timezone": "^0.5.34",
"mongodb": "^4.3.1",
"mongodb": "^4.12.1",
"mongodb-memory-server": "^7.6.3",
"nats": "^2.6.1",
"node-dogstatsd": "^0.0.7",
Expand Down
Loading

0 comments on commit af3ec69

Please sign in to comment.