Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-lehnen-rc committed Jul 19, 2023
1 parent 7654bbd commit 4f589c7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/app/importer/server/classes/ImporterBase.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion apps/meteor/app/importer/server/startImportOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions apps/meteor/server/models/raw/Imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ export class ImportsModel extends BaseRaw<IImport> implements IImportsModel {
return [{ key: { ts: -1 } }, { key: { valid: 1 } }];
}

async findLastImport(): Promise<IImport | undefined> {
async findLastImport(): Promise<IImport | null> {
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<boolean> {
Expand Down

0 comments on commit 4f589c7

Please sign in to comment.