Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | import { Controller, Get, Post, Param, Body, Request, UseGuards, } from '@nestjs/common'; import { ImportExportService } from './import-export.service'; import { ApiTags, ApiBearerAuth, ApiOperation, ApiResponse, } from '@nestjs/swagger'; import { PermissionGuard } from '../../../platform/permissions/permission.guard'; import { RequirePermission } from '../../../platform/permissions/permission.decorator'; @ApiTags('HR - Employee Import/Export') @ApiBearerAuth() @UseGuards(PermissionGuard) @Controller('api/v1/hr/employees') export class ImportExportController { constructor(private readonly importExportService: ImportExportService) {} @Get('import-template') @RequirePermission('hr.employee', 'import') @ApiOperation({ summary: 'Get template operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getTemplate() { return { success: true, data: this.importExportService.getImportTemplate(), }; } @Post('import/validate') @RequirePermission('hr.employee', 'import') @ApiOperation({ summary: 'Validate import operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async validateImport( @Request() req: any, @Body() body: { fileId: string; columnMapping: any; rows: any[] }, ) { const job = await this.importExportService.createImportJob( req.user.tenantId, body.fileId, body.columnMapping, true, req.user.userId, ); const result = await this.importExportService.validateImportRows( req.user.tenantId, job.id, body.rows, ); return { success: true, data: result }; } @Post('import') @RequirePermission('hr.employee', 'import') @ApiOperation({ summary: 'Run import operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async runImport( @Request() req: any, @Body() body: { fileId: string; columnMapping: any; rows: any[] }, ) { const job = await this.importExportService.createImportJob( req.user.tenantId, body.fileId, body.columnMapping, false, req.user.userId, ); const result = await this.importExportService.validateImportRows( req.user.tenantId, job.id, body.rows, ); return { success: true, data: result }; } @Get('import/:jobId') @RequirePermission('hr.employee', 'import') @ApiOperation({ summary: 'Get import job operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getImportJob(@Request() req: any, @Param('jobId') jobId: string) { return { success: true, data: await this.importExportService.getImportJob( req.user.tenantId, jobId, ), }; } @Get('import/:jobId/errors') @RequirePermission('hr.employee', 'import') @ApiOperation({ summary: 'Get import errors operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getImportErrors( @Request() req: any, @Param('jobId') jobId: string, ): Promise<any> { return { success: true, data: await this.importExportService.getImportErrors( req.user.tenantId, jobId, ), }; } @Post('export') @RequirePermission('hr.employee', 'export') @ApiOperation({ summary: 'Create export operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async createExport( @Request() req: any, @Body() body: { filters: any; selectedColumns: string[]; format: string }, ) { return { success: true, data: await this.importExportService.createExportJob( req.user.tenantId, body.filters, body.selectedColumns, body.format || 'csv', req.user.userId, ), }; } } |