fix: return wrong response

This commit is contained in:
Ahmed Bouhuolia
2025-05-11 00:40:43 +02:00
parent a42143a996
commit 9ebd967fe7
23 changed files with 153 additions and 215 deletions

View File

@@ -13,6 +13,7 @@ import {
Controller, Controller,
Delete, Delete,
Get, Get,
HttpCode,
Param, Param,
Post, Post,
Res, Res,
@@ -47,6 +48,7 @@ export class AttachmentsController {
* Uploads the attachments to S3 and store the file metadata to DB. * Uploads the attachments to S3 and store the file metadata to DB.
*/ */
@Post() @Post()
@HttpCode(200)
@UseInterceptors(FileInterceptor('file')) @UseInterceptors(FileInterceptor('file'))
@ApiConsumes('multipart/form-data') @ApiConsumes('multipart/form-data')
@ApiOperation({ summary: 'Upload attachment to S3' }) @ApiOperation({ summary: 'Upload attachment to S3' })
@@ -59,11 +61,7 @@ export class AttachmentsController {
status: 401, status: 401,
description: 'Unauthorized - File upload failed', description: 'Unauthorized - File upload failed',
}) })
async uploadAttachment( async uploadAttachment(@UploadedFile() file: Express.Multer.File) {
@UploadedFile() file: Express.Multer.File,
res: Response,
next: NextFunction,
): Promise<Response | void> {
if (!file) { if (!file) {
throw new UnauthorizedException({ throw new UnauthorizedException({
errorType: 'FILE_UPLOAD_FAILED', errorType: 'FILE_UPLOAD_FAILED',
@@ -72,11 +70,11 @@ export class AttachmentsController {
} }
const data = await this.attachmentsApplication.upload(file); const data = await this.attachmentsApplication.upload(file);
return res.status(200).send({ return {
status: 200, status: 200,
message: 'The document has uploaded successfully.', message: 'The document has uploaded successfully.',
data, data,
}); };
} }
/** /**
@@ -112,15 +110,14 @@ export class AttachmentsController {
description: 'The document has been deleted successfully', description: 'The document has been deleted successfully',
}) })
async deleteAttachment( async deleteAttachment(
@Res() res: Response,
@Param('id') documentId: string, @Param('id') documentId: string,
): Promise<Response | void> { ) {
await this.attachmentsApplication.delete(documentId); await this.attachmentsApplication.delete(documentId);
return res.status(200).send({ return {
status: 200, status: 200,
message: 'The document has been delete successfully.', message: 'The document has been delete successfully.',
}); };
} }
/** /**
@@ -137,18 +134,17 @@ export class AttachmentsController {
async linkDocument( async linkDocument(
@Body() linkDocumentDto: LinkAttachmentDto, @Body() linkDocumentDto: LinkAttachmentDto,
@Param('id') documentId: string, @Param('id') documentId: string,
@Res() res: Response, ) {
): Promise<Response | void> {
await this.attachmentsApplication.link( await this.attachmentsApplication.link(
documentId, documentId,
linkDocumentDto.modelRef, linkDocumentDto.modelRef,
linkDocumentDto.modelId, linkDocumentDto.modelId,
); );
return res.status(200).send({ return {
status: 200, status: 200,
message: 'The document has been linked successfully.', message: 'The document has been linked successfully.',
}); };
} }
/** /**
@@ -165,18 +161,17 @@ export class AttachmentsController {
async unlinkDocument( async unlinkDocument(
@Body() unlinkDto: UnlinkAttachmentDto, @Body() unlinkDto: UnlinkAttachmentDto,
@Param('id') documentId: string, @Param('id') documentId: string,
@Res() res: Response, ) {
): Promise<Response | void> {
await this.attachmentsApplication.link( await this.attachmentsApplication.link(
documentId, documentId,
unlinkDto.modelRef, unlinkDto.modelRef,
unlinkDto.modelId, unlinkDto.modelId,
); );
return res.status(200).send({ return {
status: 200, status: 200,
message: 'The document has been linked successfully.', message: 'The document has been linked successfully.',
}); };
} }
/** /**
@@ -189,14 +184,10 @@ export class AttachmentsController {
status: 200, status: 200,
description: 'Returns the presigned URL for the attachment', description: 'Returns the presigned URL for the attachment',
}) })
async getAttachmentPresignedUrl( async getAttachmentPresignedUrl(@Param('id') documentKey: string) {
@Param('id') documentKey: string,
res: Response,
next: NextFunction,
): Promise<Response | void> {
const presignedUrl = const presignedUrl =
await this.attachmentsApplication.getPresignedUrl(documentKey); await this.attachmentsApplication.getPresignedUrl(documentKey);
return res.status(200).send({ presignedUrl }); return { presignedUrl };
} }
} }

View File

@@ -29,7 +29,7 @@ export class ExportController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(data); res.send(data);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx'); res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
@@ -37,7 +37,7 @@ export class ExportController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(data); res.send(data);
// Retrieve the pdf format. // Retrieve the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
res.set({ res.set({

View File

@@ -21,7 +21,7 @@ export class APAgingSummaryController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.APAgingSummaryApp.table(filter); const table = await this.APAgingSummaryApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const csv = await this.APAgingSummaryApp.csv(filter); const csv = await this.APAgingSummaryApp.csv(filter);
@@ -29,7 +29,7 @@ export class APAgingSummaryController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(csv); res.send(csv);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.APAgingSummaryApp.xlsx(filter); const buffer = await this.APAgingSummaryApp.xlsx(filter);
@@ -39,7 +39,7 @@ export class APAgingSummaryController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.APAgingSummaryApp.pdf(filter); const pdfContent = await this.APAgingSummaryApp.pdf(filter);
@@ -48,12 +48,12 @@ export class APAgingSummaryController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.APAgingSummaryApp.sheet(filter); const sheet = await this.APAgingSummaryApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -27,12 +27,12 @@ export class ARAgingSummaryController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the table format. // Retrieves the table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.ARAgingSummaryApp.table(filter); const table = await this.ARAgingSummaryApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.ARAgingSummaryApp.csv(filter); const buffer = await this.ARAgingSummaryApp.csv(filter);
@@ -40,7 +40,7 @@ export class ARAgingSummaryController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.ARAgingSummaryApp.pdf(filter); const pdfContent = await this.ARAgingSummaryApp.pdf(filter);
@@ -49,12 +49,12 @@ export class ARAgingSummaryController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.ARAgingSummaryApp.sheet(filter); const sheet = await this.ARAgingSummaryApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -28,7 +28,7 @@ export class BalanceSheetStatementController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.balanceSheetApp.table(query); const table = await this.balanceSheetApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.balanceSheetApp.csv(query); const buffer = await this.balanceSheetApp.csv(query);
@@ -36,7 +36,7 @@ export class BalanceSheetStatementController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.balanceSheetApp.xlsx(query); const buffer = await this.balanceSheetApp.xlsx(query);
@@ -46,7 +46,7 @@ export class BalanceSheetStatementController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.balanceSheetApp.pdf(query); const pdfContent = await this.balanceSheetApp.pdf(query);
@@ -59,7 +59,7 @@ export class BalanceSheetStatementController {
} else { } else {
const sheet = await this.balanceSheetApp.sheet(query); const sheet = await this.balanceSheetApp.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -22,7 +22,7 @@ export class CashflowController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.cashflowSheetApp.table(query); const table = await this.cashflowSheetApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.cashflowSheetApp.csv(query); const buffer = await this.cashflowSheetApp.csv(query);
@@ -30,7 +30,7 @@ export class CashflowController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.status(200).send(buffer); res.status(200).send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.cashflowSheetApp.xlsx(query); const buffer = await this.cashflowSheetApp.xlsx(query);
@@ -40,7 +40,7 @@ export class CashflowController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.cashflowSheetApp.pdf(query); const pdfContent = await this.cashflowSheetApp.pdf(query);
@@ -49,12 +49,12 @@ export class CashflowController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const cashflow = await this.cashflowSheetApp.sheet(query); const cashflow = await this.cashflowSheetApp.sheet(query);
return res.status(200).send(cashflow); res.status(200).send(cashflow);
} }
} }
} }

View File

@@ -28,18 +28,18 @@ export class CustomerBalanceSummaryController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.customerBalanceSummaryApp.csv(filter); const buffer = await this.customerBalanceSummaryApp.csv(filter);
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the json table format. // Retrieves the json table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.customerBalanceSummaryApp.table(filter); const table = await this.customerBalanceSummaryApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const buffer = await this.customerBalanceSummaryApp.pdf(filter); const buffer = await this.customerBalanceSummaryApp.pdf(filter);
@@ -48,11 +48,11 @@ export class CustomerBalanceSummaryController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': buffer.length, 'Content-Length': buffer.length,
}); });
return res.send(buffer); res.send(buffer);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.customerBalanceSummaryApp.sheet(filter); const sheet = await this.customerBalanceSummaryApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -24,7 +24,7 @@ export class GeneralLedgerController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.generalLedgerApplication.table(query); const table = await this.generalLedgerApplication.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.generalLedgerApplication.csv(query); const buffer = await this.generalLedgerApplication.csv(query);
@@ -32,7 +32,7 @@ export class GeneralLedgerController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.generalLedgerApplication.xlsx(query); const buffer = await this.generalLedgerApplication.xlsx(query);
@@ -42,7 +42,7 @@ export class GeneralLedgerController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.generalLedgerApplication.pdf(query); const pdfContent = await this.generalLedgerApplication.pdf(query);
@@ -50,12 +50,12 @@ export class GeneralLedgerController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.generalLedgerApplication.sheet(query); const sheet = await this.generalLedgerApplication.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -25,7 +25,7 @@ export class InventoryItemDetailsController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.inventoryItemDetailsApp.xlsx(query); const buffer = await this.inventoryItemDetailsApp.xlsx(query);
@@ -35,11 +35,11 @@ export class InventoryItemDetailsController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the json table format. // Retrieves the json table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.inventoryItemDetailsApp.table(query); const table = await this.inventoryItemDetailsApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const buffer = await this.inventoryItemDetailsApp.pdf(query); const buffer = await this.inventoryItemDetailsApp.pdf(query);
@@ -48,11 +48,11 @@ export class InventoryItemDetailsController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': buffer.length, 'Content-Length': buffer.length,
}); });
return res.send(buffer); res.send(buffer);
} else { } else {
const sheet = await this.inventoryItemDetailsApp.sheet(query); const sheet = await this.inventoryItemDetailsApp.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -27,7 +27,7 @@ export class InventoryValuationController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.inventoryValuationApp.table(query); const table = await this.inventoryValuationApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.inventoryValuationApp.csv(query); const buffer = await this.inventoryValuationApp.csv(query);
@@ -35,7 +35,7 @@ export class InventoryValuationController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the xslx buffer format. // Retrieves the xslx buffer format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.inventoryValuationApp.xlsx(query); const buffer = await this.inventoryValuationApp.xlsx(query);
@@ -45,7 +45,7 @@ export class InventoryValuationController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.inventoryValuationApp.pdf(query); const pdfContent = await this.inventoryValuationApp.pdf(query);
@@ -54,12 +54,12 @@ export class InventoryValuationController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.status(200).send(pdfContent); res.status(200).send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.inventoryValuationApp.sheet(query); const sheet = await this.inventoryValuationApp.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -21,7 +21,7 @@ export class JournalSheetController {
// Retrieves the json table format. // Retrieves the json table format.
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.journalSheetApp.table(query); const table = await this.journalSheetApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
@@ -30,7 +30,7 @@ export class JournalSheetController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.journalSheetApp.xlsx(query); const buffer = await this.journalSheetApp.xlsx(query);
@@ -40,7 +40,7 @@ export class JournalSheetController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the json format. // Retrieves the json format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.journalSheetApp.pdf(query); const pdfContent = await this.journalSheetApp.pdf(query);
@@ -53,7 +53,7 @@ export class JournalSheetController {
} else { } else {
const sheet = await this.journalSheetApp.sheet(query); const sheet = await this.journalSheetApp.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -33,12 +33,12 @@ export class ProfitLossSheetController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(sheet); res.send(sheet);
// Retrieves the json table format. // Retrieves the json table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.profitLossSheetApp.table(query); const table = await this.profitLossSheetApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const sheet = await this.profitLossSheetApp.xlsx(query); const sheet = await this.profitLossSheetApp.xlsx(query);
@@ -48,7 +48,7 @@ export class ProfitLossSheetController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(sheet); res.send(sheet);
// Retrieves the json format. // Retrieves the json format.
} else if (acceptHeader.includes(AcceptType.ApplicationJson)) { } else if (acceptHeader.includes(AcceptType.ApplicationJson)) {
const pdfContent = await this.profitLossSheetApp.pdf(query); const pdfContent = await this.profitLossSheetApp.pdf(query);
@@ -57,11 +57,11 @@ export class ProfitLossSheetController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
} else { } else {
const sheet = await this.profitLossSheetApp.sheet(query); const sheet = await this.profitLossSheetApp.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -24,7 +24,7 @@ export class PurchasesByItemReportController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.purchasesByItemsApp.table(filter); const table = await this.purchasesByItemsApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// CSV response format. // CSV response format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.purchasesByItemsApp.csv(filter); const buffer = await this.purchasesByItemsApp.csv(filter);
@@ -32,7 +32,7 @@ export class PurchasesByItemReportController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Xlsx response format. // Xlsx response format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.purchasesByItemsApp.xlsx(filter); const buffer = await this.purchasesByItemsApp.xlsx(filter);
@@ -42,7 +42,7 @@ export class PurchasesByItemReportController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// PDF response format. // PDF response format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.purchasesByItemsApp.pdf(filter); const pdfContent = await this.purchasesByItemsApp.pdf(filter);
@@ -51,12 +51,12 @@ export class PurchasesByItemReportController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Json response format. // Json response format.
} else { } else {
const sheet = await this.purchasesByItemsApp.sheet(filter); const sheet = await this.purchasesByItemsApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -33,12 +33,12 @@ export class SalesByItemsController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the json table format. // Retrieves the json table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.salesByItemsApp.table(filter); const table = await this.salesByItemsApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = this.salesByItemsApp.xlsx(filter); const buffer = this.salesByItemsApp.xlsx(filter);
@@ -48,7 +48,7 @@ export class SalesByItemsController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the json format. // Retrieves the json format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.salesByItemsApp.pdf(filter); const pdfContent = await this.salesByItemsApp.pdf(filter);
@@ -57,10 +57,10 @@ export class SalesByItemsController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
} else { } else {
const sheet = await this.salesByItemsApp.sheet(filter); const sheet = await this.salesByItemsApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -26,7 +26,7 @@ export class SalesTaxLiabilitySummaryController {
// Retrieves the json table format. // Retrieves the json table format.
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.salesTaxLiabilitySummaryApp.table(query); const table = await this.salesTaxLiabilitySummaryApp.table(query);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the xlsx format. // Retrieves the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.salesTaxLiabilitySummaryApp.xlsx(query); const buffer = await this.salesTaxLiabilitySummaryApp.xlsx(query);
@@ -35,14 +35,14 @@ export class SalesTaxLiabilitySummaryController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.salesTaxLiabilitySummaryApp.csv(query); const buffer = await this.salesTaxLiabilitySummaryApp.csv(query);
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves the json format. // Retrieves the json format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.salesTaxLiabilitySummaryApp.pdf(query); const pdfContent = await this.salesTaxLiabilitySummaryApp.pdf(query);
@@ -50,10 +50,10 @@ export class SalesTaxLiabilitySummaryController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.status(200).send(pdfContent); res.status(200).send(pdfContent);
} else { } else {
const sheet = await this.salesTaxLiabilitySummaryApp.sheet(query); const sheet = await this.salesTaxLiabilitySummaryApp.sheet(query);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -23,7 +23,7 @@ export class TransactionsByCustomerController {
// Retrieves the json table format. // Retrieves the json table format.
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.transactionsByCustomersApp.table(filter); const table = await this.transactionsByCustomersApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieve the csv format. // Retrieve the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
@@ -32,7 +32,7 @@ export class TransactionsByCustomerController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(csv); res.send(csv);
// Retrieve the xlsx format. // Retrieve the xlsx format.
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
@@ -42,7 +42,7 @@ export class TransactionsByCustomerController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieve the json format. // Retrieve the json format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
@@ -51,10 +51,10 @@ export class TransactionsByCustomerController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
} else { } else {
const sheet = await this.transactionsByCustomersApp.sheet(filter); const sheet = await this.transactionsByCustomersApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -27,7 +27,7 @@ export class TransactionsByVendorController {
res.setHeader('Content-Type', 'application/vnd.openxmlformats'); res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=report.xlsx'); res.setHeader('Content-Disposition', 'attachment; filename=report.xlsx');
return res.send(buffer); res.send(buffer);
// Retrieves the csv format. // Retrieves the csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.transactionsByVendorsApp.csv(filter); const buffer = await this.transactionsByVendorsApp.csv(filter);
@@ -35,12 +35,12 @@ export class TransactionsByVendorController {
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=report.csv'); res.setHeader('Content-Disposition', 'attachment; filename=report.csv');
return res.send(buffer); res.send(buffer);
// Retrieves the json table format. // Retrieves the json table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.transactionsByVendorsApp.table(filter); const table = await this.transactionsByVendorsApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.transactionsByVendorsApp.pdf(filter); const pdfContent = await this.transactionsByVendorsApp.pdf(filter);
@@ -48,11 +48,11 @@ export class TransactionsByVendorController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.transactionsByVendorsApp.sheet(filter); const sheet = await this.transactionsByVendorsApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

@@ -29,7 +29,7 @@ export class TrialBalanceSheetController {
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const { table, meta, query } = const { table, meta, query } =
await this.trialBalanceSheetApp.table(filter); await this.trialBalanceSheetApp.table(filter);
return res.status(200).send({ table, meta, query }); res.status(200).send({ table, meta, query });
// Retrieves in xlsx format // Retrieves in xlsx format
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.trialBalanceSheetApp.xlsx(filter); const buffer = await this.trialBalanceSheetApp.xlsx(filter);
@@ -38,7 +38,7 @@ export class TrialBalanceSheetController {
'Content-Type', 'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
); );
return res.send(buffer); res.send(buffer);
// Retrieves in csv format. // Retrieves in csv format.
} else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) {
const buffer = await this.trialBalanceSheetApp.csv(filter); const buffer = await this.trialBalanceSheetApp.csv(filter);
@@ -46,7 +46,7 @@ export class TrialBalanceSheetController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
// Retrieves in pdf format. // Retrieves in pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.trialBalanceSheetApp.pdf(filter); const pdfContent = await this.trialBalanceSheetApp.pdf(filter);
@@ -59,7 +59,7 @@ export class TrialBalanceSheetController {
} else { } else {
const { data, query, meta } = const { data, query, meta } =
await this.trialBalanceSheetApp.sheet(filter); await this.trialBalanceSheetApp.sheet(filter);
return res.status(200).send({ data, query, meta }); res.status(200).send({ data, query, meta });
} }
} }
} }

View File

@@ -27,20 +27,20 @@ export class VendorBalanceSummaryController {
res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
return res.send(buffer); res.send(buffer);
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
const buffer = await this.vendorBalanceSummaryApp.xlsx(filter); const buffer = await this.vendorBalanceSummaryApp.xlsx(filter);
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx'); res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
res.setHeader('Content-Type', 'application/vnd.openxmlformats'); res.setHeader('Content-Type', 'application/vnd.openxmlformats');
return res.send(buffer); res.send(buffer);
// Retrieves the json table format. // Retrieves the json table format.
} else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
const table = await this.vendorBalanceSummaryApp.table(filter); const table = await this.vendorBalanceSummaryApp.table(filter);
return res.status(200).send(table); res.status(200).send(table);
// Retrieves the pdf format. // Retrieves the pdf format.
} else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
const pdfContent = await this.vendorBalanceSummaryApp.pdf(filter); const pdfContent = await this.vendorBalanceSummaryApp.pdf(filter);
@@ -49,11 +49,11 @@ export class VendorBalanceSummaryController {
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length, 'Content-Length': pdfContent.length,
}); });
return res.send(pdfContent); res.send(pdfContent);
// Retrieves the json format. // Retrieves the json format.
} else { } else {
const sheet = await this.vendorBalanceSummaryApp.sheet(filter); const sheet = await this.vendorBalanceSummaryApp.sheet(filter);
return res.status(200).send(sheet); res.status(200).send(sheet);
} }
} }
} }

View File

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

View File

@@ -5,12 +5,8 @@ import {
Delete, Delete,
Param, Param,
Body, Body,
Req, HttpCode,
Res,
Next,
HttpStatus,
} from '@nestjs/common'; } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { ApiTags } from '@nestjs/swagger'; import { ApiTags } from '@nestjs/swagger';
import { PaymentServicesApplication } from './PaymentServicesApplication'; import { PaymentServicesApplication } from './PaymentServicesApplication';
import { EditPaymentMethodDTO } from './types'; import { EditPaymentMethodDTO } from './types';
@@ -23,60 +19,53 @@ export class PaymentServicesController {
) {} ) {}
@Get('/') @Get('/')
async getPaymentServicesSpecificInvoice(@Res() res: Response) { async getPaymentServicesSpecificInvoice() {
const paymentServices = const paymentServices =
await this.paymentServicesApp.getPaymentServicesForInvoice(); await this.paymentServicesApp.getPaymentServicesForInvoice();
return res.status(HttpStatus.OK).send({ paymentServices }); return { paymentServices };
} }
@Get('/state') @Get('/state')
async getPaymentMethodsState(@Res() res: Response) { async getPaymentMethodsState() {
const paymentMethodsState = const paymentMethodsState =
await this.paymentServicesApp.getPaymentMethodsState(); await this.paymentServicesApp.getPaymentMethodsState();
return res.status(HttpStatus.OK).send({ data: paymentMethodsState }); return { data: paymentMethodsState };
} }
@Get('/:paymentServiceId') @Get('/:paymentServiceId')
async getPaymentService( async getPaymentService(@Param('paymentServiceId') paymentServiceId: number) {
@Param('paymentServiceId') paymentServiceId: number,
@Req() req: Request,
@Res() res: Response,
@Next() next: NextFunction,
) {
const paymentService = const paymentService =
await this.paymentServicesApp.getPaymentService(paymentServiceId); await this.paymentServicesApp.getPaymentService(paymentServiceId);
return res.status(HttpStatus.OK).send({ data: paymentService }); return { data: paymentService };
} }
@Post('/:paymentMethodId') @Post('/:paymentMethodId')
@HttpCode(200)
async updatePaymentMethod( async updatePaymentMethod(
@Param('paymentMethodId') paymentMethodId: number, @Param('paymentMethodId') paymentMethodId: number,
@Body() updatePaymentMethodDTO: EditPaymentMethodDTO, @Body() updatePaymentMethodDTO: EditPaymentMethodDTO,
@Res() res: Response,
) { ) {
await this.paymentServicesApp.editPaymentMethod( await this.paymentServicesApp.editPaymentMethod(
paymentMethodId, paymentMethodId,
updatePaymentMethodDTO, updatePaymentMethodDTO,
); );
return res.status(HttpStatus.OK).send({ return {
id: paymentMethodId, id: paymentMethodId,
message: 'The given payment method has been updated.', message: 'The given payment method has been updated.',
}); };
} }
@Delete('/:paymentMethodId') @Delete('/:paymentMethodId')
async deletePaymentMethod( @HttpCode(200)
@Param('paymentMethodId') paymentMethodId: number, async deletePaymentMethod(@Param('paymentMethodId') paymentMethodId: number) {
@Res() res: Response,
) {
await this.paymentServicesApp.deletePaymentMethod(paymentMethodId); await this.paymentServicesApp.deletePaymentMethod(paymentMethodId);
return res.status(HttpStatus.NO_CONTENT).send({ return {
id: paymentMethodId, id: paymentMethodId,
message: 'The payment method has been deleted.', message: 'The payment method has been deleted.',
}); };
} }
} }

View File

@@ -5,7 +5,6 @@ import {
Delete, Delete,
Param, Param,
Body, Body,
Req,
Res, Res,
Next, Next,
HttpStatus, HttpStatus,
@@ -35,16 +34,15 @@ export class RolesController {
description: 'Role created successfully', description: 'Role created successfully',
}) })
async createRole( async createRole(
@Res() res: Response,
@Next() next: NextFunction, @Next() next: NextFunction,
@Body() createRoleDto: CreateRoleDto, @Body() createRoleDto: CreateRoleDto,
) { ) {
const role = await this.rolesApp.createRole(createRoleDto); const role = await this.rolesApp.createRole(createRoleDto);
return res.status(HttpStatus.OK).send({ return {
data: { roleId: role.id }, data: { roleId: role.id },
message: 'The role has been created successfully.', message: 'The role has been created successfully.',
}); };
} }
@Post(':id') @Post(':id')
@@ -56,17 +54,15 @@ export class RolesController {
description: 'Role updated successfully', description: 'Role updated successfully',
}) })
async editRole( async editRole(
@Res() res: Response,
@Next() next: NextFunction,
@Param('id', ParseIntPipe) roleId: number, @Param('id', ParseIntPipe) roleId: number,
@Body() editRoleDto: EditRoleDto, @Body() editRoleDto: EditRoleDto,
) { ) {
const role = await this.rolesApp.editRole(roleId, editRoleDto); const role = await this.rolesApp.editRole(roleId, editRoleDto);
return res.status(HttpStatus.OK).send({ return {
data: { roleId }, data: { roleId },
message: 'The given role has been updated successfully.', message: 'The given role has been updated successfully.',
}); };
} }
@Delete(':id') @Delete(':id')
@@ -77,16 +73,14 @@ export class RolesController {
description: 'Role deleted successfully', description: 'Role deleted successfully',
}) })
async deleteRole( async deleteRole(
@Res() res: Response,
@Next() next: NextFunction,
@Param('id', ParseIntPipe) roleId: number, @Param('id', ParseIntPipe) roleId: number,
) { ) {
await this.rolesApp.deleteRole(roleId); await this.rolesApp.deleteRole(roleId);
return res.status(HttpStatus.OK).send({ return {
data: { roleId }, data: { roleId },
message: 'The given role has been deleted successfully.', message: 'The given role has been deleted successfully.',
}); };
} }
@Get() @Get()
@@ -95,7 +89,7 @@ export class RolesController {
async getRoles(@Res() res: Response) { async getRoles(@Res() res: Response) {
const roles = await this.rolesApp.getRoles(); const roles = await this.rolesApp.getRoles();
return res.status(HttpStatus.OK).send({ roles }); return { roles };
} }
@Get(':id') @Get(':id')
@@ -103,11 +97,10 @@ export class RolesController {
@ApiParam({ name: 'id', description: 'Role ID' }) @ApiParam({ name: 'id', description: 'Role ID' })
@ApiResponse({ status: HttpStatus.OK, description: 'Role details' }) @ApiResponse({ status: HttpStatus.OK, description: 'Role details' })
async getRole( async getRole(
@Res() res: Response,
@Param('id', ParseIntPipe) roleId: number, @Param('id', ParseIntPipe) roleId: number,
) { ) {
const role = await this.rolesApp.getRole(roleId); const role = await this.rolesApp.getRole(roleId);
return res.status(HttpStatus.OK).send({ role }); return { role };
} }
} }

View File

@@ -6,6 +6,7 @@ import {
Req, Req,
Res, Res,
Next, Next,
HttpCode,
} from '@nestjs/common'; } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express'; import { Request, Response, NextFunction } from 'express';
import { ApiOperation, ApiTags, ApiResponse, ApiBody } from '@nestjs/swagger'; import { ApiOperation, ApiTags, ApiResponse, ApiBody } from '@nestjs/swagger';
@@ -22,13 +23,15 @@ export class SubscriptionsController {
status: 200, status: 200,
description: 'List of subscriptions retrieved successfully', description: 'List of subscriptions retrieved successfully',
}) })
async getSubscriptions(@Res() res: Response) { @HttpCode(200)
async getSubscriptions() {
const subscriptions = await this.subscriptionApp.getSubscriptions(); const subscriptions = await this.subscriptionApp.getSubscriptions();
return res.status(200).send({ subscriptions }); return { subscriptions };
} }
@Post('lemon/checkout_url') @Post('lemon/checkout_url')
@HttpCode(200)
@ApiOperation({ summary: 'Get LemonSqueezy checkout URL' }) @ApiOperation({ summary: 'Get LemonSqueezy checkout URL' })
@ApiBody({ @ApiBody({
schema: { schema: {
@@ -46,14 +49,11 @@ export class SubscriptionsController {
status: 200, status: 200,
description: 'Checkout URL retrieved successfully', description: 'Checkout URL retrieved successfully',
}) })
async getCheckoutUrl( async getCheckoutUrl(@Body('variantId') variantId: number) {
@Body('variantId') variantId: number,
@Res() res: Response,
) {
const checkout = const checkout =
await this.subscriptionApp.getLemonSqueezyCheckoutUri(variantId); await this.subscriptionApp.getLemonSqueezyCheckoutUri(variantId);
return res.status(200).send(checkout); return checkout;
} }
@Post('cancel') @Post('cancel')
@@ -62,38 +62,31 @@ export class SubscriptionsController {
status: 200, status: 200,
description: 'Subscription canceled successfully', description: 'Subscription canceled successfully',
}) })
async cancelSubscription( async cancelSubscription(@Req() req: Request, @Next() next: NextFunction) {
@Req() req: Request,
@Res() res: Response,
@Next() next: NextFunction,
) {
const tenantId = req.headers['organization-id'] as string; const tenantId = req.headers['organization-id'] as string;
await this.subscriptionApp.cancelSubscription(tenantId); await this.subscriptionApp.cancelSubscription(tenantId);
return res.status(200).send({ return {
status: 200, status: 200,
message: 'The organization subscription has been canceled.', message: 'The organization subscription has been canceled.',
}); };
} }
@Post('resume') @Post('resume')
@HttpCode(200)
@ApiOperation({ summary: 'Resume the current organization subscription' }) @ApiOperation({ summary: 'Resume the current organization subscription' })
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Subscription resumed successfully', description: 'Subscription resumed successfully',
}) })
async resumeSubscription( async resumeSubscription(@Req() req: Request, @Next() next: NextFunction) {
@Req() req: Request,
@Res() res: Response,
@Next() next: NextFunction,
) {
const tenantId = req.headers['organization-id'] as string; const tenantId = req.headers['organization-id'] as string;
await this.subscriptionApp.resumeSubscription(tenantId); await this.subscriptionApp.resumeSubscription(tenantId);
return res.status(200).send({ return {
status: 200, status: 200,
message: 'The organization subscription has been resumed.', message: 'The organization subscription has been resumed.',
}); };
} }
@Post('change') @Post('change')
@@ -116,14 +109,11 @@ export class SubscriptionsController {
status: 200, status: 200,
description: 'Subscription plan changed successfully', description: 'Subscription plan changed successfully',
}) })
async changeSubscriptionPlan( async changeSubscriptionPlan(@Body('variant_id') variantId: number) {
@Body('variant_id') variantId: number,
@Res() res: Response,
) {
await this.subscriptionApp.changeSubscriptionPlan(variantId); await this.subscriptionApp.changeSubscriptionPlan(variantId);
return res.status(200).send({ return {
message: 'The subscription plan has been changed.', message: 'The subscription plan has been changed.',
}); };
} }
} }