From 4f589c75acb7d61215e0c760b3a2960a414ff14e Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Wed, 19 Jul 2023 19:03:15 -0300 Subject: [PATCH] types --- apps/meteor/app/importer/server/classes/ImporterBase.ts | 4 ++-- apps/meteor/app/importer/server/startImportOperation.ts | 7 ++++++- .../client/views/admin/import/ImportOperationSummary.js | 7 +------ apps/meteor/server/models/raw/Imports.ts | 8 ++------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/apps/meteor/app/importer/server/classes/ImporterBase.ts b/apps/meteor/app/importer/server/classes/ImporterBase.ts index f528c68a514d..cd6654752853 100644 --- a/apps/meteor/app/importer/server/classes/ImporterBase.ts +++ b/apps/meteor/app/importer/server/classes/ImporterBase.ts @@ -1,7 +1,6 @@ import type { MatchKeysAndValues } from 'mongodb'; import { Settings, ImportData, Imports } from '@rocket.chat/models'; import type { IImport, IImportRecordType, IImportData, IImportChannel, IImportUser, IImportProgress } from '@rocket.chat/core-typings'; -import { Meteor } from 'meteor/meteor'; import AdmZip from 'adm-zip'; import { Progress } from './ImporterProgress'; @@ -331,7 +330,8 @@ export class Importer { } await Imports.update({ _id: this.importRecord._id }, { $set: fields }); - this.importRecord = await Imports.findOne(this.importRecord._id); + // #TODO: Remove need for the typecast + this.importRecord = (await Imports.findOne(this.importRecord._id)) as IImport; return this.importRecord; } diff --git a/apps/meteor/app/importer/server/startImportOperation.ts b/apps/meteor/app/importer/server/startImportOperation.ts index 9b700f7df7c4..e532ac04976a 100644 --- a/apps/meteor/app/importer/server/startImportOperation.ts +++ b/apps/meteor/app/importer/server/startImportOperation.ts @@ -16,5 +16,10 @@ export const startImportOperation = async (info: ImporterInfo, userId: IUser['_i }) ).insertedId; - return Imports.findOne(importId); + const operation = await Imports.findOne(importId); + if (!operation) { + throw new Error('Failed to start import operation'); + } + + return operation; }; diff --git a/apps/meteor/client/views/admin/import/ImportOperationSummary.js b/apps/meteor/client/views/admin/import/ImportOperationSummary.js index 322f6901f122..ddb21c01b07e 100644 --- a/apps/meteor/client/views/admin/import/ImportOperationSummary.js +++ b/apps/meteor/client/views/admin/import/ImportOperationSummary.js @@ -19,12 +19,7 @@ function ImportOperationSummary({ file = '', user, small, - count: { users = 0, channels = 0, messages = 0, total = 0 } = { - users: null, - channels: null, - messages: null, - total: null, - }, + count: { users = 0, channels = 0, messages = 0, total = 0 } = {}, valid, }) { const t = useTranslation(); diff --git a/apps/meteor/server/models/raw/Imports.ts b/apps/meteor/server/models/raw/Imports.ts index de666cf68ec1..7538edf49886 100644 --- a/apps/meteor/server/models/raw/Imports.ts +++ b/apps/meteor/server/models/raw/Imports.ts @@ -13,14 +13,10 @@ export class ImportsModel extends BaseRaw implements IImportsModel { return [{ key: { ts: -1 } }, { key: { valid: 1 } }]; } - async findLastImport(): Promise { + async findLastImport(): Promise { const imports = await this.find({}, { sort: { ts: -1 }, limit: 1 }).toArray(); - if (imports?.length) { - return imports.shift(); - } - - return undefined; + return imports.shift() || null; } async hasValidOperationInStatus(allowedStatus: IImport['status'][]): Promise {