mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: reponse readable text and linting some pages.
This commit is contained in:
@@ -213,7 +213,10 @@ export default class CustomersController extends ContactsController {
|
||||
|
||||
try {
|
||||
await this.customersService.deleteCustomer(tenantId, contactId)
|
||||
return res.status(200).send({ id: contactId });
|
||||
return res.status(200).send({
|
||||
id: contactId,
|
||||
message: 'The customer has been deleted successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -252,7 +255,11 @@ export default class CustomersController extends ContactsController {
|
||||
|
||||
try {
|
||||
await this.customersService.deleteBulkCustomers(tenantId, contactsIds)
|
||||
return res.status(200).send({ ids: contactsIds });
|
||||
|
||||
return res.status(200).send({
|
||||
ids: contactsIds,
|
||||
message: 'The customers have been deleted successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -194,7 +194,10 @@ export default class ExpensesController extends BaseController {
|
||||
expenseDTO,
|
||||
user
|
||||
);
|
||||
return res.status(200).send({ id: expenseId });
|
||||
return res.status(200).send({
|
||||
id: expenseId,
|
||||
message: 'The expense has been created successfully.'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -215,7 +218,7 @@ export default class ExpensesController extends BaseController {
|
||||
|
||||
return res.status(200).send({
|
||||
id: expenseId,
|
||||
message: 'The expense has been deleted.',
|
||||
message: 'The expense has been deleted successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -237,7 +240,7 @@ export default class ExpensesController extends BaseController {
|
||||
|
||||
return res.status(200).send({
|
||||
id: expenseId,
|
||||
message: 'The expense has been published',
|
||||
message: 'The expense has been published successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -260,7 +263,10 @@ export default class ExpensesController extends BaseController {
|
||||
expensesIds,
|
||||
user
|
||||
);
|
||||
return res.status(200).send({ ids: expensesIds });
|
||||
return res.status(200).send({
|
||||
ids: expensesIds,
|
||||
message: 'The expenses have been deleted successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -282,7 +288,10 @@ export default class ExpensesController extends BaseController {
|
||||
expensesIds,
|
||||
user
|
||||
);
|
||||
return res.status(200).send({});
|
||||
return res.status(200).send({
|
||||
ids: expensesIds,
|
||||
message: 'The expenses have been published successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ export default class ItemsController extends BaseController {
|
||||
|
||||
return res.status(200).send({
|
||||
id: storedItem.id,
|
||||
message: 'Item has been created successfully.',
|
||||
message: 'The item has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -258,7 +258,11 @@ export default class ItemsController extends BaseController {
|
||||
|
||||
try {
|
||||
await this.itemsService.editItem(tenantId, itemId, item);
|
||||
return res.status(200).send({ id: itemId });
|
||||
|
||||
return res.status(200).send({
|
||||
id: itemId,
|
||||
message: 'The item has been edited successfully.'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -319,7 +323,11 @@ export default class ItemsController extends BaseController {
|
||||
|
||||
try {
|
||||
await this.itemsService.deleteItem(tenantId, itemId);
|
||||
return res.status(200).send({ id: itemId });
|
||||
|
||||
return res.status(200).send({
|
||||
id: itemId,
|
||||
message: 'The item has been deleted successfully.'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -340,8 +348,6 @@ export default class ItemsController extends BaseController {
|
||||
|
||||
return res.status(200).send({ item: storedItem });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,10 @@ export default class ManualJournalsController extends BaseController {
|
||||
try {
|
||||
await this.manualJournalsService.publishManualJournal(tenantId, manualJournalId);
|
||||
|
||||
return res.status(200).send();
|
||||
return res.status(200).send({
|
||||
id: manualJournalId,
|
||||
message: 'The manual journal has been published successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -224,7 +227,10 @@ export default class ManualJournalsController extends BaseController {
|
||||
try {
|
||||
await this.manualJournalsService.publishManualJournals(tenantId, manualJournalsIds);
|
||||
|
||||
return res.status(200).send();
|
||||
return res.status(200).send({
|
||||
ids: manualJournalsIds,
|
||||
message: 'The manual journals have been published successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -288,7 +294,10 @@ export default class ManualJournalsController extends BaseController {
|
||||
const { manualJournal } = await this.manualJournalsService
|
||||
.makeJournalEntries(tenantId, manualJournalDTO, user);
|
||||
|
||||
return res.status(200).send({ id: manualJournal.id });
|
||||
return res.status(200).send({
|
||||
id: manualJournal.id,
|
||||
message: 'The manual journal has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -312,7 +321,10 @@ export default class ManualJournalsController extends BaseController {
|
||||
manualJournalDTO,
|
||||
user,
|
||||
);
|
||||
return res.status(200).send({ id: manualJournal.id });
|
||||
return res.status(200).send({
|
||||
id: manualJournal.id,
|
||||
message: 'The manual journal has been edited successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { check, param, query, ValidationChain } from 'express-validator';
|
||||
@@ -31,46 +30,51 @@ export default class BillsPayments extends BaseController {
|
||||
router() {
|
||||
const router = Router();
|
||||
|
||||
router.post('/', [
|
||||
...this.billPaymentSchemaValidation,
|
||||
],
|
||||
router.post(
|
||||
'/',
|
||||
[...this.billPaymentSchemaValidation],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.createBillPayment.bind(this)),
|
||||
this.handleServiceError,
|
||||
this.handleServiceError
|
||||
);
|
||||
router.post('/:id', [
|
||||
...this.billPaymentSchemaValidation,
|
||||
...this.specificBillPaymentValidateSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.editBillPayment.bind(this)),
|
||||
this.handleServiceError,
|
||||
)
|
||||
router.delete('/:id', [
|
||||
router.post(
|
||||
'/:id',
|
||||
[
|
||||
...this.billPaymentSchemaValidation,
|
||||
...this.specificBillPaymentValidateSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.deleteBillPayment.bind(this)),
|
||||
this.handleServiceError,
|
||||
asyncMiddleware(this.editBillPayment.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get('/:id/bills',
|
||||
router.delete(
|
||||
'/:id',
|
||||
[...this.specificBillPaymentValidateSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.deleteBillPayment.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get(
|
||||
'/:id/bills',
|
||||
this.specificBillPaymentValidateSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getPaymentBills.bind(this)),
|
||||
this.handleServiceError,
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get('/:id',
|
||||
router.get(
|
||||
'/:id',
|
||||
this.specificBillPaymentValidateSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillPayment.bind(this)),
|
||||
this.handleServiceError,
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get('/',
|
||||
router.get(
|
||||
'/',
|
||||
this.listingValidationSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillsPayments.bind(this)),
|
||||
this.handleServiceError,
|
||||
this.dynamicListService.handlerErrorsToResponse,
|
||||
this.dynamicListService.handlerErrorsToResponse
|
||||
);
|
||||
return router;
|
||||
}
|
||||
@@ -97,9 +101,7 @@ export default class BillsPayments extends BaseController {
|
||||
* Specific bill payment schema validation.
|
||||
*/
|
||||
get specificBillPaymentValidateSchema(): ValidationChain[] {
|
||||
return [
|
||||
param('id').exists().isNumeric().toInt(),
|
||||
];
|
||||
return [param('id').exists().isNumeric().toInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,16 +121,19 @@ export default class BillsPayments extends BaseController {
|
||||
/**
|
||||
* Creates a bill payment.
|
||||
* @async
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {Response} res
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {Response} res
|
||||
*/
|
||||
async createBillPayment(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const billPaymentDTO = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
const billPayment = await this.billPaymentService.createBillPayment(tenantId, billPaymentDTO);
|
||||
const billPayment = await this.billPaymentService.createBillPayment(
|
||||
tenantId,
|
||||
billPaymentDTO
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
id: billPayment.id,
|
||||
@@ -142,8 +147,8 @@ export default class BillsPayments extends BaseController {
|
||||
|
||||
/**
|
||||
* Edits the given bill payment details.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async editBillPayment(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
@@ -190,8 +195,8 @@ export default class BillsPayments extends BaseController {
|
||||
|
||||
/**
|
||||
* Retrieve the bill payment.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async getBillPayment(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
@@ -206,8 +211,8 @@ export default class BillsPayments extends BaseController {
|
||||
|
||||
return res.status(200).send({
|
||||
bill_payment: this.transfromToResponse({ ...billPayment }),
|
||||
payable_bills: this.transfromToResponse([ ...payableBills ]),
|
||||
payment_bills: this.transfromToResponse([ ...paymentMadeBills ]),
|
||||
payable_bills: this.transfromToResponse([...payableBills]),
|
||||
payment_bills: this.transfromToResponse([...paymentMadeBills]),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -216,16 +221,19 @@ export default class BillsPayments extends BaseController {
|
||||
|
||||
/**
|
||||
* Retrieve associated bills for the given payment made.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async getPaymentBills(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { id: billPaymentId } = req.params;
|
||||
|
||||
try {
|
||||
const bills = await this.billPaymentService.getPaymentBills(tenantId, billPaymentId);
|
||||
const bills = await this.billPaymentService.getPaymentBills(
|
||||
tenantId,
|
||||
billPaymentId
|
||||
);
|
||||
return res.status(200).send({ bills });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -233,7 +241,7 @@ export default class BillsPayments extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve bills payments listing with pagination metadata.
|
||||
* Retrieve bills payments listing with pagination metadata.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @return {Response}
|
||||
@@ -250,12 +258,19 @@ export default class BillsPayments extends BaseController {
|
||||
};
|
||||
|
||||
try {
|
||||
const { billPayments, pagination, filterMeta } = await this.billPaymentService.listBillPayments(tenantId, billPaymentsFilter);
|
||||
const {
|
||||
billPayments,
|
||||
pagination,
|
||||
filterMeta,
|
||||
} = await this.billPaymentService.listBillPayments(
|
||||
tenantId,
|
||||
billPaymentsFilter
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
bill_payments: billPayments,
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta)
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -264,46 +279,54 @@ export default class BillsPayments extends BaseController {
|
||||
|
||||
/**
|
||||
* Handle service errors.
|
||||
* @param {Error} error
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Error} error
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
handleServiceError(error: Error, req: Request, res: Response, next: NextFunction) {
|
||||
handleServiceError(
|
||||
error: Error,
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
if (error instanceof ServiceError) {
|
||||
if (error.errorType === 'PAYMENT_MADE_NOT_FOUND') {
|
||||
return res.status(404).send({
|
||||
message: 'Payment made not found.',
|
||||
errors: [{ type: 'BILL_NOT_FOUND', code: 100 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'VENDOR_NOT_FOUND') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'BILL.PAYMENT.VENDOR.NOT.FOUND', code: 500 }],
|
||||
errors: [{ type: 'BILL.PAYMENT.VENDOR.NOT.FOUND', code: 200 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'PAYMENT_ACCOUNT_NOT_CURRENT_ASSET_TYPE') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'PAYMENT_ACCOUNT.NOT.CURRENT_ASSET.TYPE', code: 100 }],
|
||||
errors: [
|
||||
{ type: 'PAYMENT_ACCOUNT.NOT.CURRENT_ASSET.TYPE', code: 300 },
|
||||
],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'BILL_PAYMENT_NUMBER_NOT_UNQIUE') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'PAYMENT.NUMBER.NOT.UNIQUE', code: 300 }],
|
||||
errors: [{ type: 'PAYMENT.NUMBER.NOT.UNIQUE', code: 400 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'PAYMENT_ACCOUNT_NOT_FOUND') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'PAYMENT.ACCOUNT.NOT.FOUND', code: 200 }],
|
||||
errors: [{ type: 'PAYMENT.ACCOUNT.NOT.FOUND', code: 500 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'PAYMENT_ACCOUNT_NOT_FOUND') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'PAYMENT.ACCOUNT.NOT.FOUND', code: 200 }],
|
||||
errors: [{ type: 'PAYMENT.ACCOUNT.NOT.FOUND', code: 600 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === '') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'BILLS.IDS.NOT.EXISTS', code: 600 }],
|
||||
errors: [{ type: 'BILLS.IDS.NOT.EXISTS', code: 700 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'BILL_PAYMENT_ENTRIES_NOT_FOUND') {
|
||||
@@ -313,15 +336,15 @@ export default class BillsPayments extends BaseController {
|
||||
}
|
||||
if (error.errorType === 'INVALID_BILL_PAYMENT_AMOUNT') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'INVALID_BILL_PAYMENT_AMOUNT', code: 100 }],
|
||||
errors: [{ type: 'INVALID_BILL_PAYMENT_AMOUNT', code: 900 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'BILL_ENTRIES_IDS_NOT_FOUND') {
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'BILLS_NOT_FOUND', code: 100 }],
|
||||
})
|
||||
errors: [{ type: 'BILLS_NOT_FOUND', code: 1000 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,10 @@ export default class SalesEstimatesController extends BaseController {
|
||||
try {
|
||||
const storedEstimate = await this.saleEstimateService.createEstimate(tenantId, estimateDTO);
|
||||
|
||||
return res.status(200).send({ id: storedEstimate.id });
|
||||
return res.status(200).send({
|
||||
id: storedEstimate.id,
|
||||
message: 'The sale estimate has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -175,7 +178,10 @@ export default class SalesEstimatesController extends BaseController {
|
||||
// Update estimate with associated estimate entries.
|
||||
await this.saleEstimateService.editEstimate(tenantId, estimateId, estimateDTO);
|
||||
|
||||
return res.status(200).send({ id: estimateId });
|
||||
return res.status(200).send({
|
||||
id: estimateId,
|
||||
message: 'The sale estimate has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -193,7 +199,10 @@ export default class SalesEstimatesController extends BaseController {
|
||||
try {
|
||||
await this.saleEstimateService.deleteEstimate(tenantId, estimateId);
|
||||
|
||||
return res.status(200).send({ id: estimateId });
|
||||
return res.status(200).send({
|
||||
id: estimateId,
|
||||
message: 'The sale estimate has been deleted successfully.'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -276,6 +285,7 @@ export default class SalesEstimatesController extends BaseController {
|
||||
|
||||
try {
|
||||
const estimate = await this.saleEstimateService.getEstimate(tenantId, estimateId);
|
||||
|
||||
return res.status(200).send({ estimate });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -104,7 +104,11 @@ export default class UsersController extends BaseController{
|
||||
|
||||
try {
|
||||
await this.usersService.editUser(tenantId, userId, userDTO);
|
||||
return res.status(200).send({ id: userId });
|
||||
|
||||
return res.status(200).send({
|
||||
id: userId,
|
||||
message: 'The user has been edited successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -122,7 +126,10 @@ export default class UsersController extends BaseController{
|
||||
|
||||
try {
|
||||
await this.usersService.deleteUser(tenantId, id);
|
||||
return res.status(200).send({ id });
|
||||
return res.status(200).send({
|
||||
id,
|
||||
message: 'The user has been deleted successfully.'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -175,7 +182,11 @@ export default class UsersController extends BaseController{
|
||||
|
||||
try {
|
||||
await this.usersService.activateUser(tenantId, userId, user);
|
||||
return res.status(200).send({ id: userId });
|
||||
|
||||
return res.status(200).send({
|
||||
id: userId,
|
||||
message: 'The user has been activated successfully.',
|
||||
});
|
||||
} catch(error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -193,7 +204,11 @@ export default class UsersController extends BaseController{
|
||||
|
||||
try {
|
||||
await this.usersService.inactivateUser(tenantId, userId, user);
|
||||
return res.status(200).send({ id: userId });
|
||||
|
||||
return res.status(200).send({
|
||||
id: userId,
|
||||
message: 'The user has been inactivated successfully.',
|
||||
});
|
||||
} catch(error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user