Skip to content

Commit

Permalink
Add back auth guard
Browse files Browse the repository at this point in the history
  • Loading branch information
catalin-oancea committed Oct 31, 2024
1 parent 69db03e commit 5d8358e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions api/src/modules/import/import.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import { GetUser } from '@api/modules/auth/decorators/get-user.decorator';
import { User } from '@shared/entities/users/user.entity';

@Controller()
// @UseGuards(JwtAuthGuard, RolesGuard)
@UseGuards(JwtAuthGuard, RolesGuard)
export class ImportController {
constructor(private readonly service: ImportService) {}
// TODO: File validation following:
// https://docs.nestjs.com/techniques/file-upload

@TsRestHandler(adminContract.uploadFile)
@UseInterceptors(FileInterceptor('file'))
// @RequiredRoles(ROLES.ADMIN)
@RequiredRoles(ROLES.ADMIN)
async uploadFile(
@UploadXlsm() file: Express.Multer.File,
// @GetUser() user: User,
@GetUser() user: User,
): Promise<ControllerResponse> {
return tsRestHandler(adminContract.uploadFile, async () => {
const importedData = await this.service.import(file.buffer);
const importedData = await this.service.import(file.buffer, user.id);
return {
status: 201,
body: importedData,
Expand Down
8 changes: 4 additions & 4 deletions api/src/modules/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ export class ImportService {
private readonly eventBus: EventBus,
) {}

async import(fileBuffer: Buffer) {
async import(fileBuffer: Buffer, userId: string) {
this.logger.warn('Excel file import started...');
// this.registerImportEvent(userId, this.eventMap.STARTED);
this.registerImportEvent(userId, this.eventMap.STARTED);
try {
const parsedSheets = await this.excelParser.parseExcel(fileBuffer);
const parsedDBEntities = this.preprocessor.toDbEntities(parsedSheets);
await this.importRepo.ingest(parsedDBEntities);
this.logger.warn('Excel file import completed successfully');
// this.registerImportEvent(userId, this.eventMap.SUCCESS);
this.registerImportEvent(userId, this.eventMap.SUCCESS);
} catch (e) {
this.logger.error('Excel file import failed', e);
// this.registerImportEvent(userId, this.eventMap.FAILED);
this.registerImportEvent(userId, this.eventMap.FAILED);
}
}

Expand Down

0 comments on commit 5d8358e

Please sign in to comment.