Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/nestjs-backend/src/event-emitter/events/event.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export enum Events {

AUDIT_LOG_SAVED = 'audit-log.saved',

IMPORT_TABLE_COMPLETE = 'import.table.complete',
// IMPORT_TABLE_COMPLETE = 'import.table.complete',

BASE_IMPORT_COMPLETE = 'base.import.complete',
// BASE_IMPORT_COMPLETE = 'base.import.complete',

NOTIFY_MAIL_MERGE = 'notify.mail.merge',
}
20 changes: 10 additions & 10 deletions apps/nestjs-backend/src/features/base/base-import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as unzipper from 'unzipper';
import { IThresholdConfig, ThresholdConfig } from '../../configs/threshold.config';
import { InjectDbProvider } from '../../db-provider/db.provider';
import { IDbProvider } from '../../db-provider/db.provider.interface';
import { Events } from '../../event-emitter/events';
// import { Events } from '../../event-emitter/events';
import type { IClsStore } from '../../types/cls';
import StorageAdapter from '../attachments/plugins/adapter';
import { InjectStorageAdapter } from '../attachments/plugins/storage';
Expand Down Expand Up @@ -131,17 +131,17 @@ export class BaseImportService {
);

// emit base import complete event for audit log
const userId = this.cls.get('user.id');
const origin = this.cls.get('origin');
// const userId = this.cls.get('user.id');
// const origin = this.cls.get('origin');

this.logger.log(`Base import structure completed, emitting event for baseId: ${base.id}`);
await this.cls.run(async () => {
this.cls.set('origin', origin!);
this.cls.set('user.id', userId);
await this.eventEmitter.emitAsync(Events.BASE_IMPORT_COMPLETE, {
importBaseRo,
});
});
// await this.cls.run(async () => {
// this.cls.set('origin', origin!);
// this.cls.set('user.id', userId);
// await this.eventEmitter.emitAsync(Events.BASE_IMPORT_COMPLETE, {
// importBaseRo,
// });
// });

return {
base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Papa from 'papaparse';
import type { CreateOp } from 'sharedb';
import type { LocalPresence } from 'sharedb/lib/client';
import { EventEmitterService } from '../../../event-emitter/event-emitter.service';
import { Events } from '../../../event-emitter/events';
// import { Events } from '../../../event-emitter/events';
import { ShareDbService } from '../../../share-db/share-db.service';
import type { IClsStore } from '../../../types/cls';
import StorageAdapter from '../../attachments/plugins/adapter';
Expand Down Expand Up @@ -101,16 +101,16 @@ export class ImportTableCsvQueueProcessor extends WorkerHost {
});

// emit event to audit log
this.cls.run(async () => {
this.cls.set('origin', origin!);
this.cls.set('user.id', userId);
await this.eventEmitterService.emitAsync(Events.IMPORT_TABLE_COMPLETE, {
ro,
recordsLength: range?.at(-1),
baseId,
tableId: table.id,
});
});
// this.cls.run(async () => {
// this.cls.set('origin', origin!);
// this.cls.set('user.id', userId);
// await this.eventEmitterService.emitAsync(Events.IMPORT_TABLE_COMPLETE, {
// ro,
// recordsLength: range?.at(-1),
// baseId,
// tableId: table.id,
// });
// });

this.setImportStatus(localPresence, false);
localPresence.destroy();
Expand Down
44 changes: 22 additions & 22 deletions apps/nestjs-backend/test/table-import.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {
} from '@teable/openapi';
import dayjs, { extend } from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import { noop } from 'lodash';
// import { noop } from 'lodash';
import * as XLSX from 'xlsx';
import { EventEmitterService } from '../src/event-emitter/event-emitter.service';
import { Events } from '../src/event-emitter/events';
// import { EventEmitterService } from '../src/event-emitter/event-emitter.service';
// import { Events } from '../src/event-emitter/events';
import StorageAdapter from '../src/features/attachments/plugins/adapter';
import { CsvImporter } from '../src/features/import/open-api/import.class';
import { createAwaitWithEventWithResult } from './utils/event-promise';
// import { createAwaitWithEventWithResult } from './utils/event-promise';
import { initApp, permanentDeleteTable, getTable as apiGetTableById } from './utils/init-app';

extend(timezone);
Expand Down Expand Up @@ -169,12 +169,12 @@ const assertHeaders = [

describe('OpenAPI ImportController (e2e)', () => {
const bases: [string, string][] = [];
let eventEmitterService: EventEmitterService;
// let eventEmitterService: EventEmitterService;

beforeAll(async () => {
const appCtx = await initApp();
app = appCtx.app;
eventEmitterService = app.get(EventEmitterService);
// eventEmitterService = app.get(EventEmitterService);
testFiles = await genTestFiles();
});

Expand Down Expand Up @@ -230,15 +230,15 @@ describe('OpenAPI ImportController (e2e)', () => {
});

describe('/import/{baseId} OpenAPI ImportController (e2e) (Post)', () => {
let awaitWithEvent: <T>(fn: () => Promise<T>) => Promise<void>;
// let awaitWithEvent: <T>(fn: () => Promise<T>) => Promise<void>;

it.each(testFileFormats.filter((format) => format !== TestFileFormat.TXT))(
'should create a new Table from %s file',
async (format) => {
awaitWithEvent = createAwaitWithEventWithResult<void>(
eventEmitterService,
Events.IMPORT_TABLE_COMPLETE
);
// awaitWithEvent = createAwaitWithEventWithResult<void>(
// eventEmitterService,
// Events.IMPORT_TABLE_COMPLETE
// );
const spaceRes = await apiCreateSpace({ name: `test${format}` });
const spaceId = spaceRes?.data?.id;
const baseRes = await apiCreateBase({ spaceId });
Expand Down Expand Up @@ -280,9 +280,9 @@ describe('OpenAPI ImportController (e2e)', () => {
name: field.name,
}));

await awaitWithEvent(async () => {
noop();
});
// await awaitWithEvent(async () => {
// noop();
// });

const { records } = await apiGetTableById(baseId, table.data[0].id, {
includeContent: true,
Expand All @@ -297,13 +297,13 @@ describe('OpenAPI ImportController (e2e)', () => {
});

describe('/import/{baseId}/{tableId} OpenAPI ImportController (e2e) (Patch)', () => {
let awaitWithEvent: <T>(fn: () => Promise<T>) => Promise<void>;
// let awaitWithEvent: <T>(fn: () => Promise<T>) => Promise<void>;

it('should import data into Table from file', async () => {
awaitWithEvent = createAwaitWithEventWithResult<void>(
eventEmitterService,
Events.IMPORT_TABLE_COMPLETE
);
// awaitWithEvent = createAwaitWithEventWithResult<void>(
// eventEmitterService,
// Events.IMPORT_TABLE_COMPLETE
// );
const spaceRes = await apiCreateSpace({ name: 'test1' });
const spaceId = spaceRes?.data?.id;
const baseRes = await apiCreateBase({ spaceId });
Expand Down Expand Up @@ -367,9 +367,9 @@ describe('OpenAPI ImportController (e2e)', () => {
},
});

await awaitWithEvent(async () => {
noop();
});
// await awaitWithEvent(async () => {
// noop();
// });

const { records } = await apiGetTableById(baseId, tableId, {
includeContent: true,
Expand Down
Loading