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,
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<Response | void> {
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<Response | void> {
) {
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<Response | void> {
) {
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<Response | void> {
) {
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<Response | void> {
async getAttachmentPresignedUrl(@Param('id') documentKey: string) {
const presignedUrl =
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-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({

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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 });
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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.',
});
};
}
}

View File

@@ -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 };
}
}

View File

@@ -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.',
});
};
}
}