mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
fix: return wrong response
This commit is contained in:
@@ -8,10 +8,9 @@ import {
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
Res,
|
||||
Next,
|
||||
UseInterceptors,
|
||||
UploadedFile,
|
||||
HttpCode,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||
import { ImportResourceApplication } from './ImportResourceApplication';
|
||||
@@ -27,59 +26,44 @@ export class ImportController {
|
||||
* Imports xlsx/csv to the given resource type.
|
||||
*/
|
||||
@Post('/file')
|
||||
@HttpCode(200)
|
||||
@ApiOperation({ summary: 'Upload import file' })
|
||||
@ApiResponse({ status: 200, description: 'File uploaded successfully' })
|
||||
@UseInterceptors(
|
||||
FileInterceptor('file', uploadImportFileMulterOptions),
|
||||
)
|
||||
@UseInterceptors(FileInterceptor('file', uploadImportFileMulterOptions))
|
||||
async fileUpload(
|
||||
@Res() res: Response,
|
||||
@Next() next: NextFunction,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Body('resource') resource: string,
|
||||
@Body('params') rawParams?: string,
|
||||
) {
|
||||
const params = defaultTo(parseJsonSafe(rawParams), {});
|
||||
|
||||
try {
|
||||
const data = await this.importResourceApp.import(
|
||||
resource,
|
||||
file.filename,
|
||||
params,
|
||||
);
|
||||
return res.status(200).send(data);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
return this.importResourceApp.import(resource, file.filename, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the columns of the imported file.
|
||||
*/
|
||||
@Post('/:import_id/mapping')
|
||||
@HttpCode(200)
|
||||
@ApiOperation({ summary: 'Map import columns' })
|
||||
@ApiResponse({ status: 200, description: 'Mapping successful' })
|
||||
async mapping(
|
||||
@Res() res: Response,
|
||||
@Param('import_id') importId: string,
|
||||
@Body('mapping')
|
||||
mapping: Array<{ group?: string; from: string; to: string }>,
|
||||
) {
|
||||
const result = await this.importResourceApp.mapping(importId, mapping);
|
||||
|
||||
return res.status(200).send(result);
|
||||
return this.importResourceApp.mapping(importId, mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview the imported file before actual importing.
|
||||
*/
|
||||
@Get('/:import_id/preview')
|
||||
@HttpCode(200)
|
||||
@ApiOperation({ summary: 'Preview import data' })
|
||||
@ApiResponse({ status: 200, description: 'Preview data' })
|
||||
async preview(@Res() res: Response, @Param('import_id') importId: string) {
|
||||
const preview = await this.importResourceApp.preview(importId);
|
||||
|
||||
return res.status(200).send(preview);
|
||||
async preview(@Param('import_id') importId: string) {
|
||||
return this.importResourceApp.preview(importId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,10 +72,8 @@ export class ImportController {
|
||||
@Post('/:import_id/import')
|
||||
@ApiOperation({ summary: 'Process import' })
|
||||
@ApiResponse({ status: 200, description: 'Import processed successfully' })
|
||||
async import(@Res() res: Response, @Param('import_id') importId: string) {
|
||||
const result = await this.importResourceApp.process(importId);
|
||||
|
||||
return res.status(200).send(result);
|
||||
async import(@Param('import_id') importId: string) {
|
||||
return this.importResourceApp.process(importId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,13 +83,10 @@ export class ImportController {
|
||||
@ApiOperation({ summary: 'Get import sample' })
|
||||
@ApiResponse({ status: 200, description: 'Sample data' })
|
||||
async downloadImportSample(
|
||||
@Res() res: Response,
|
||||
@Query('resource') resource: string,
|
||||
@Query('format') format?: 'csv' | 'xlsx',
|
||||
) {
|
||||
const result = await this.importResourceApp.sample(resource, format);
|
||||
|
||||
return res.status(200).send(result);
|
||||
return this.importResourceApp.sample(resource, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,11 +95,7 @@ export class ImportController {
|
||||
@Get('/:import_id')
|
||||
@ApiOperation({ summary: 'Get import metadata' })
|
||||
@ApiResponse({ status: 200, description: 'Import metadata' })
|
||||
async getImportFileMeta(
|
||||
@Res() res: Response,
|
||||
@Param('import_id') importId: string,
|
||||
) {
|
||||
const result = await this.importResourceApp.importMeta(importId);
|
||||
return res.status(200).send(result);
|
||||
async getImportFileMeta(@Param('import_id') importId: string) {
|
||||
return this.importResourceApp.importMeta(importId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user