From 9ebd967fe72c67721acb74760b02353ff036ba46 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 11 May 2025 00:40:43 +0200 Subject: [PATCH] fix: return wrong response --- .../Attachments/Attachments.controller.ts | 41 ++++++-------- .../src/modules/Export/Export.controller.ts | 4 +- .../APAgingSummary.controller.ts | 10 ++-- .../ARAgingSummary.controller.ts | 10 ++-- .../BalanceSheet/BalanceSheet.controller.ts | 8 +-- .../CashFlowStatement/Cashflow.controller.ts | 10 ++-- .../CustomerBalanceSummary.controller.ts | 10 ++-- .../GeneralLedger/GeneralLedger.controller.ts | 10 ++-- .../InventoryItemDetails.controller.ts | 10 ++-- .../InventoryValuation.controller.ts | 10 ++-- .../JournalSheet/JournalSheet.controller.ts | 8 +-- .../ProfitLossSheet.controller.ts | 10 ++-- .../PurchasesByItems.controller.ts | 10 ++-- .../SalesByItems/SalesByItems.controller.ts | 10 ++-- .../SalesTaxLiabilitySummary.controller.ts | 10 ++-- .../TransactionsByCustomer.controller.ts | 10 ++-- .../TransactionsByVendor.controller.ts | 10 ++-- .../TrialBalanceSheet.controller.ts | 8 +-- .../VendorBalanceSummary.controller.ts | 10 ++-- .../src/modules/Import/Import.controller.ts | 53 +++++-------------- .../PaymentServices.controller.ts | 39 +++++--------- .../src/modules/Roles/Roles.controller.ts | 23 +++----- .../Subscription/Subscriptions.controller.ts | 44 ++++++--------- 23 files changed, 153 insertions(+), 215 deletions(-) diff --git a/packages/server/src/modules/Attachments/Attachments.controller.ts b/packages/server/src/modules/Attachments/Attachments.controller.ts index 9bfe5cc3a..4ceddf6ad 100644 --- a/packages/server/src/modules/Attachments/Attachments.controller.ts +++ b/packages/server/src/modules/Attachments/Attachments.controller.ts @@ -13,6 +13,7 @@ import { Controller, Delete, Get, + HttpCode, Param, Post, Res, @@ -47,6 +48,7 @@ export class AttachmentsController { * Uploads the attachments to S3 and store the file metadata to DB. */ @Post() + @HttpCode(200) @UseInterceptors(FileInterceptor('file')) @ApiConsumes('multipart/form-data') @ApiOperation({ summary: 'Upload attachment to S3' }) @@ -59,11 +61,7 @@ export class AttachmentsController { status: 401, description: 'Unauthorized - File upload failed', }) - async uploadAttachment( - @UploadedFile() file: Express.Multer.File, - res: Response, - next: NextFunction, - ): Promise { + async uploadAttachment(@UploadedFile() file: Express.Multer.File) { if (!file) { throw new UnauthorizedException({ errorType: 'FILE_UPLOAD_FAILED', @@ -72,11 +70,11 @@ export class AttachmentsController { } const data = await this.attachmentsApplication.upload(file); - return res.status(200).send({ + return { status: 200, message: 'The document has uploaded successfully.', data, - }); + }; } /** @@ -112,15 +110,14 @@ export class AttachmentsController { description: 'The document has been deleted successfully', }) async deleteAttachment( - @Res() res: Response, @Param('id') documentId: string, - ): Promise { + ) { await this.attachmentsApplication.delete(documentId); - return res.status(200).send({ + return { status: 200, message: 'The document has been delete successfully.', - }); + }; } /** @@ -137,18 +134,17 @@ export class AttachmentsController { async linkDocument( @Body() linkDocumentDto: LinkAttachmentDto, @Param('id') documentId: string, - @Res() res: Response, - ): Promise { + ) { await this.attachmentsApplication.link( documentId, linkDocumentDto.modelRef, linkDocumentDto.modelId, ); - return res.status(200).send({ + return { status: 200, message: 'The document has been linked successfully.', - }); + }; } /** @@ -165,18 +161,17 @@ export class AttachmentsController { async unlinkDocument( @Body() unlinkDto: UnlinkAttachmentDto, @Param('id') documentId: string, - @Res() res: Response, - ): Promise { + ) { await this.attachmentsApplication.link( documentId, unlinkDto.modelRef, unlinkDto.modelId, ); - return res.status(200).send({ + return { status: 200, message: 'The document has been linked successfully.', - }); + }; } /** @@ -189,14 +184,10 @@ export class AttachmentsController { status: 200, description: 'Returns the presigned URL for the attachment', }) - async getAttachmentPresignedUrl( - @Param('id') documentKey: string, - res: Response, - next: NextFunction, - ): Promise { + async getAttachmentPresignedUrl(@Param('id') documentKey: string) { const presignedUrl = await this.attachmentsApplication.getPresignedUrl(documentKey); - return res.status(200).send({ presignedUrl }); + return { presignedUrl }; } } diff --git a/packages/server/src/modules/Export/Export.controller.ts b/packages/server/src/modules/Export/Export.controller.ts index 4eff9b663..5cd14a4e9 100644 --- a/packages/server/src/modules/Export/Export.controller.ts +++ b/packages/server/src/modules/Export/Export.controller.ts @@ -29,7 +29,7 @@ export class ExportController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(data); + res.send(data); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx'); @@ -37,7 +37,7 @@ export class ExportController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(data); + res.send(data); // Retrieve the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { res.set({ diff --git a/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts index 572eeb981..200d911e8 100644 --- a/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts @@ -21,7 +21,7 @@ export class APAgingSummaryController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.APAgingSummaryApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(csv); + res.send(csv); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.APAgingSummaryApp.xlsx(filter); @@ -39,7 +39,7 @@ export class APAgingSummaryController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.APAgingSummaryApp.pdf(filter); @@ -48,12 +48,12 @@ export class APAgingSummaryController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Retrieves the json format. } else { const sheet = await this.APAgingSummaryApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts index 15a85c656..e356831fb 100644 --- a/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts @@ -27,12 +27,12 @@ export class ARAgingSummaryController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.ARAgingSummaryApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.ARAgingSummaryApp.pdf(filter); @@ -49,12 +49,12 @@ export class ARAgingSummaryController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Retrieves the json format. } else { const sheet = await this.ARAgingSummaryApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts index 1962b5f0a..2d266a611 100644 --- a/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts @@ -28,7 +28,7 @@ export class BalanceSheetStatementController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.balanceSheetApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.balanceSheetApp.xlsx(query); @@ -46,7 +46,7 @@ export class BalanceSheetStatementController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.balanceSheetApp.pdf(query); @@ -59,7 +59,7 @@ export class BalanceSheetStatementController { } else { const sheet = await this.balanceSheetApp.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts b/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts index 7be695523..bc7a3814b 100644 --- a/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts @@ -22,7 +22,7 @@ export class CashflowController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.cashflowSheetApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.status(200).send(buffer); + res.status(200).send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.cashflowSheetApp.xlsx(query); @@ -40,7 +40,7 @@ export class CashflowController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.cashflowSheetApp.pdf(query); @@ -49,12 +49,12 @@ export class CashflowController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Retrieves the json format. } else { const cashflow = await this.cashflowSheetApp.sheet(query); - return res.status(200).send(cashflow); + res.status(200).send(cashflow); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts index dd29559ce..8c355a4a3 100644 --- a/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts @@ -28,18 +28,18 @@ export class CustomerBalanceSummaryController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.customerBalanceSummaryApp.csv(filter); res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.customerBalanceSummaryApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const buffer = await this.customerBalanceSummaryApp.pdf(filter); @@ -48,11 +48,11 @@ export class CustomerBalanceSummaryController { 'Content-Type': 'application/pdf', 'Content-Length': buffer.length, }); - return res.send(buffer); + res.send(buffer); // Retrieves the json format. } else { const sheet = await this.customerBalanceSummaryApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts b/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts index ff954e1d7..9458dfe9c 100644 --- a/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts @@ -24,7 +24,7 @@ export class GeneralLedgerController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.generalLedgerApplication.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.generalLedgerApplication.xlsx(query); @@ -42,7 +42,7 @@ export class GeneralLedgerController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.generalLedgerApplication.pdf(query); @@ -50,12 +50,12 @@ export class GeneralLedgerController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Retrieves the json format. } else { const sheet = await this.generalLedgerApplication.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts b/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts index 9689ae747..3552a6b92 100644 --- a/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts @@ -25,7 +25,7 @@ export class InventoryItemDetailsController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.inventoryItemDetailsApp.xlsx(query); @@ -35,11 +35,11 @@ export class InventoryItemDetailsController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.inventoryItemDetailsApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const buffer = await this.inventoryItemDetailsApp.pdf(query); @@ -48,11 +48,11 @@ export class InventoryItemDetailsController { 'Content-Type': 'application/pdf', 'Content-Length': buffer.length, }); - return res.send(buffer); + res.send(buffer); } else { const sheet = await this.inventoryItemDetailsApp.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts index 2dbb9eff7..d286af74b 100644 --- a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts @@ -27,7 +27,7 @@ export class InventoryValuationController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.inventoryValuationApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the xslx buffer format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.inventoryValuationApp.xlsx(query); @@ -45,7 +45,7 @@ export class InventoryValuationController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.inventoryValuationApp.pdf(query); @@ -54,12 +54,12 @@ export class InventoryValuationController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.status(200).send(pdfContent); + res.status(200).send(pdfContent); // Retrieves the json format. } else { const sheet = await this.inventoryValuationApp.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts index e62e1ae40..5eca0ee7d 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts @@ -21,7 +21,7 @@ export class JournalSheetController { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.journalSheetApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { @@ -30,7 +30,7 @@ export class JournalSheetController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.journalSheetApp.xlsx(query); @@ -40,7 +40,7 @@ export class JournalSheetController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the json format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.journalSheetApp.pdf(query); @@ -53,7 +53,7 @@ export class JournalSheetController { } else { const sheet = await this.journalSheetApp.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts index 0865ccd40..03cc0bf8a 100644 --- a/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts @@ -33,12 +33,12 @@ export class ProfitLossSheetController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(sheet); + res.send(sheet); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.profitLossSheetApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const sheet = await this.profitLossSheetApp.xlsx(query); @@ -48,7 +48,7 @@ export class ProfitLossSheetController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(sheet); + res.send(sheet); // Retrieves the json format. } else if (acceptHeader.includes(AcceptType.ApplicationJson)) { const pdfContent = await this.profitLossSheetApp.pdf(query); @@ -57,11 +57,11 @@ export class ProfitLossSheetController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); } else { const sheet = await this.profitLossSheetApp.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts b/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts index f19d4f534..5e8b1a52a 100644 --- a/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts @@ -24,7 +24,7 @@ export class PurchasesByItemReportController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.purchasesByItemsApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // CSV response format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Xlsx response format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.purchasesByItemsApp.xlsx(filter); @@ -42,7 +42,7 @@ export class PurchasesByItemReportController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // PDF response format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.purchasesByItemsApp.pdf(filter); @@ -51,12 +51,12 @@ export class PurchasesByItemReportController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Json response format. } else { const sheet = await this.purchasesByItemsApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts b/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts index f94d8796b..2b4029f29 100644 --- a/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts @@ -33,12 +33,12 @@ export class SalesByItemsController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.salesByItemsApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = this.salesByItemsApp.xlsx(filter); @@ -48,7 +48,7 @@ export class SalesByItemsController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the json format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.salesByItemsApp.pdf(filter); @@ -57,10 +57,10 @@ export class SalesByItemsController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); } else { const sheet = await this.salesByItemsApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts index 0788a32bb..970d8cf89 100644 --- a/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts @@ -26,7 +26,7 @@ export class SalesTaxLiabilitySummaryController { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.salesTaxLiabilitySummaryApp.table(query); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.salesTaxLiabilitySummaryApp.xlsx(query); @@ -35,14 +35,14 @@ export class SalesTaxLiabilitySummaryController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.salesTaxLiabilitySummaryApp.csv(query); res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the json format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.salesTaxLiabilitySummaryApp.pdf(query); @@ -50,10 +50,10 @@ export class SalesTaxLiabilitySummaryController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.status(200).send(pdfContent); + res.status(200).send(pdfContent); } else { const sheet = await this.salesTaxLiabilitySummaryApp.sheet(query); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts b/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts index 14852bd05..a50deb7af 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts @@ -23,7 +23,7 @@ export class TransactionsByCustomerController { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.transactionsByCustomersApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieve the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { @@ -32,7 +32,7 @@ export class TransactionsByCustomerController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(csv); + res.send(csv); // Retrieve the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { @@ -42,7 +42,7 @@ export class TransactionsByCustomerController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieve the json format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { @@ -51,10 +51,10 @@ export class TransactionsByCustomerController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); } else { const sheet = await this.transactionsByCustomersApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts b/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts index 8fbb782fc..8086db30e 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts @@ -27,7 +27,7 @@ export class TransactionsByVendorController { res.setHeader('Content-Type', 'application/vnd.openxmlformats'); res.setHeader('Content-Disposition', 'attachment; filename=report.xlsx'); - return res.send(buffer); + res.send(buffer); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.transactionsByVendorsApp.csv(filter); @@ -35,12 +35,12 @@ export class TransactionsByVendorController { res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Disposition', 'attachment; filename=report.csv'); - return res.send(buffer); + res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.transactionsByVendorsApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.transactionsByVendorsApp.pdf(filter); @@ -48,11 +48,11 @@ export class TransactionsByVendorController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Retrieves the json format. } else { const sheet = await this.transactionsByVendorsApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts index af83cf9b4..a89d30f39 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts @@ -29,7 +29,7 @@ export class TrialBalanceSheetController { if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const { table, meta, query } = await this.trialBalanceSheetApp.table(filter); - return res.status(200).send({ table, meta, query }); + res.status(200).send({ table, meta, query }); // Retrieves in xlsx format } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.trialBalanceSheetApp.xlsx(filter); @@ -38,7 +38,7 @@ export class TrialBalanceSheetController { 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); - return res.send(buffer); + res.send(buffer); // Retrieves in csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { 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-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); // Retrieves in pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.trialBalanceSheetApp.pdf(filter); @@ -59,7 +59,7 @@ export class TrialBalanceSheetController { } else { const { data, query, meta } = await this.trialBalanceSheetApp.sheet(filter); - return res.status(200).send({ data, query, meta }); + res.status(200).send({ data, query, meta }); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts index 34a4c2431..b0efa4741 100644 --- a/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts @@ -27,20 +27,20 @@ export class VendorBalanceSummaryController { res.setHeader('Content-Disposition', 'attachment; filename=output.csv'); res.setHeader('Content-Type', 'text/csv'); - return res.send(buffer); + res.send(buffer); } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.vendorBalanceSummaryApp.xlsx(filter); res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx'); res.setHeader('Content-Type', 'application/vnd.openxmlformats'); - return res.send(buffer); + res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.vendorBalanceSummaryApp.table(filter); - return res.status(200).send(table); + res.status(200).send(table); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.vendorBalanceSummaryApp.pdf(filter); @@ -49,11 +49,11 @@ export class VendorBalanceSummaryController { 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, }); - return res.send(pdfContent); + res.send(pdfContent); // Retrieves the json format. } else { const sheet = await this.vendorBalanceSummaryApp.sheet(filter); - return res.status(200).send(sheet); + res.status(200).send(sheet); } } } diff --git a/packages/server/src/modules/Import/Import.controller.ts b/packages/server/src/modules/Import/Import.controller.ts index dcc1e29e4..9b26bc78f 100644 --- a/packages/server/src/modules/Import/Import.controller.ts +++ b/packages/server/src/modules/Import/Import.controller.ts @@ -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); } } diff --git a/packages/server/src/modules/PaymentServices/PaymentServices.controller.ts b/packages/server/src/modules/PaymentServices/PaymentServices.controller.ts index c760681ef..bb250b7ee 100644 --- a/packages/server/src/modules/PaymentServices/PaymentServices.controller.ts +++ b/packages/server/src/modules/PaymentServices/PaymentServices.controller.ts @@ -5,12 +5,8 @@ import { Delete, Param, Body, - Req, - Res, - Next, - HttpStatus, + HttpCode, } from '@nestjs/common'; -import { Request, Response, NextFunction } from 'express'; import { ApiTags } from '@nestjs/swagger'; import { PaymentServicesApplication } from './PaymentServicesApplication'; import { EditPaymentMethodDTO } from './types'; @@ -23,60 +19,53 @@ export class PaymentServicesController { ) {} @Get('/') - async getPaymentServicesSpecificInvoice(@Res() res: Response) { + async getPaymentServicesSpecificInvoice() { const paymentServices = await this.paymentServicesApp.getPaymentServicesForInvoice(); - return res.status(HttpStatus.OK).send({ paymentServices }); + return { paymentServices }; } @Get('/state') - async getPaymentMethodsState(@Res() res: Response) { + async getPaymentMethodsState() { const paymentMethodsState = await this.paymentServicesApp.getPaymentMethodsState(); - return res.status(HttpStatus.OK).send({ data: paymentMethodsState }); + return { data: paymentMethodsState }; } @Get('/:paymentServiceId') - async getPaymentService( - @Param('paymentServiceId') paymentServiceId: number, - @Req() req: Request, - @Res() res: Response, - @Next() next: NextFunction, - ) { + async getPaymentService(@Param('paymentServiceId') paymentServiceId: number) { const paymentService = await this.paymentServicesApp.getPaymentService(paymentServiceId); - return res.status(HttpStatus.OK).send({ data: paymentService }); + return { data: paymentService }; } @Post('/:paymentMethodId') + @HttpCode(200) async updatePaymentMethod( @Param('paymentMethodId') paymentMethodId: number, @Body() updatePaymentMethodDTO: EditPaymentMethodDTO, - @Res() res: Response, ) { await this.paymentServicesApp.editPaymentMethod( paymentMethodId, updatePaymentMethodDTO, ); - return res.status(HttpStatus.OK).send({ + return { id: paymentMethodId, message: 'The given payment method has been updated.', - }); + }; } @Delete('/:paymentMethodId') - async deletePaymentMethod( - @Param('paymentMethodId') paymentMethodId: number, - @Res() res: Response, - ) { + @HttpCode(200) + async deletePaymentMethod(@Param('paymentMethodId') paymentMethodId: number) { await this.paymentServicesApp.deletePaymentMethod(paymentMethodId); - return res.status(HttpStatus.NO_CONTENT).send({ + return { id: paymentMethodId, message: 'The payment method has been deleted.', - }); + }; } } diff --git a/packages/server/src/modules/Roles/Roles.controller.ts b/packages/server/src/modules/Roles/Roles.controller.ts index 6a61bf358..ab79ab228 100644 --- a/packages/server/src/modules/Roles/Roles.controller.ts +++ b/packages/server/src/modules/Roles/Roles.controller.ts @@ -5,7 +5,6 @@ import { Delete, Param, Body, - Req, Res, Next, HttpStatus, @@ -35,16 +34,15 @@ export class RolesController { description: 'Role created successfully', }) async createRole( - @Res() res: Response, @Next() next: NextFunction, @Body() createRoleDto: CreateRoleDto, ) { const role = await this.rolesApp.createRole(createRoleDto); - return res.status(HttpStatus.OK).send({ + return { data: { roleId: role.id }, message: 'The role has been created successfully.', - }); + }; } @Post(':id') @@ -56,17 +54,15 @@ export class RolesController { description: 'Role updated successfully', }) async editRole( - @Res() res: Response, - @Next() next: NextFunction, @Param('id', ParseIntPipe) roleId: number, @Body() editRoleDto: EditRoleDto, ) { const role = await this.rolesApp.editRole(roleId, editRoleDto); - return res.status(HttpStatus.OK).send({ + return { data: { roleId }, message: 'The given role has been updated successfully.', - }); + }; } @Delete(':id') @@ -77,16 +73,14 @@ export class RolesController { description: 'Role deleted successfully', }) async deleteRole( - @Res() res: Response, - @Next() next: NextFunction, @Param('id', ParseIntPipe) roleId: number, ) { await this.rolesApp.deleteRole(roleId); - return res.status(HttpStatus.OK).send({ + return { data: { roleId }, message: 'The given role has been deleted successfully.', - }); + }; } @Get() @@ -95,7 +89,7 @@ export class RolesController { async getRoles(@Res() res: Response) { const roles = await this.rolesApp.getRoles(); - return res.status(HttpStatus.OK).send({ roles }); + return { roles }; } @Get(':id') @@ -103,11 +97,10 @@ export class RolesController { @ApiParam({ name: 'id', description: 'Role ID' }) @ApiResponse({ status: HttpStatus.OK, description: 'Role details' }) async getRole( - @Res() res: Response, @Param('id', ParseIntPipe) roleId: number, ) { const role = await this.rolesApp.getRole(roleId); - return res.status(HttpStatus.OK).send({ role }); + return { role }; } } diff --git a/packages/server/src/modules/Subscription/Subscriptions.controller.ts b/packages/server/src/modules/Subscription/Subscriptions.controller.ts index c42dd18e8..a70bebf5a 100644 --- a/packages/server/src/modules/Subscription/Subscriptions.controller.ts +++ b/packages/server/src/modules/Subscription/Subscriptions.controller.ts @@ -6,6 +6,7 @@ import { Req, Res, Next, + HttpCode, } from '@nestjs/common'; import { Request, Response, NextFunction } from 'express'; import { ApiOperation, ApiTags, ApiResponse, ApiBody } from '@nestjs/swagger'; @@ -22,13 +23,15 @@ export class SubscriptionsController { status: 200, description: 'List of subscriptions retrieved successfully', }) - async getSubscriptions(@Res() res: Response) { + @HttpCode(200) + async getSubscriptions() { const subscriptions = await this.subscriptionApp.getSubscriptions(); - return res.status(200).send({ subscriptions }); + return { subscriptions }; } @Post('lemon/checkout_url') + @HttpCode(200) @ApiOperation({ summary: 'Get LemonSqueezy checkout URL' }) @ApiBody({ schema: { @@ -46,14 +49,11 @@ export class SubscriptionsController { status: 200, description: 'Checkout URL retrieved successfully', }) - async getCheckoutUrl( - @Body('variantId') variantId: number, - @Res() res: Response, - ) { + async getCheckoutUrl(@Body('variantId') variantId: number) { const checkout = await this.subscriptionApp.getLemonSqueezyCheckoutUri(variantId); - return res.status(200).send(checkout); + return checkout; } @Post('cancel') @@ -62,38 +62,31 @@ export class SubscriptionsController { status: 200, description: 'Subscription canceled successfully', }) - async cancelSubscription( - @Req() req: Request, - @Res() res: Response, - @Next() next: NextFunction, - ) { + async cancelSubscription(@Req() req: Request, @Next() next: NextFunction) { const tenantId = req.headers['organization-id'] as string; await this.subscriptionApp.cancelSubscription(tenantId); - return res.status(200).send({ + return { status: 200, message: 'The organization subscription has been canceled.', - }); + }; } @Post('resume') + @HttpCode(200) @ApiOperation({ summary: 'Resume the current organization subscription' }) @ApiResponse({ status: 200, description: 'Subscription resumed successfully', }) - async resumeSubscription( - @Req() req: Request, - @Res() res: Response, - @Next() next: NextFunction, - ) { + async resumeSubscription(@Req() req: Request, @Next() next: NextFunction) { const tenantId = req.headers['organization-id'] as string; await this.subscriptionApp.resumeSubscription(tenantId); - return res.status(200).send({ + return { status: 200, message: 'The organization subscription has been resumed.', - }); + }; } @Post('change') @@ -116,14 +109,11 @@ export class SubscriptionsController { status: 200, description: 'Subscription plan changed successfully', }) - async changeSubscriptionPlan( - @Body('variant_id') variantId: number, - @Res() res: Response, - ) { + async changeSubscriptionPlan(@Body('variant_id') variantId: number) { await this.subscriptionApp.changeSubscriptionPlan(variantId); - return res.status(200).send({ + return { message: 'The subscription plan has been changed.', - }); + }; } }