mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: rewrite repositories with base entity repository class.
feat: sales and purchases status. feat: sales and purchases auto-increment number. fix: settings find query with extra columns.
This commit is contained in:
@@ -38,6 +38,14 @@ export default class BillsController extends BaseController {
|
||||
asyncMiddleware(this.newBill.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.post(
|
||||
'/:id/open', [
|
||||
...this.specificBillValidationSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.openBill.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.post(
|
||||
'/:id', [
|
||||
...this.billValidationSchema,
|
||||
@@ -94,6 +102,8 @@ export default class BillsController extends BaseController {
|
||||
check('due_date').optional().isISO8601(),
|
||||
check('vendor_id').exists().isNumeric().toInt(),
|
||||
check('note').optional().trim().escape(),
|
||||
check('open').default(false).isBoolean().toBoolean(),
|
||||
|
||||
check('entries').isArray({ min: 1 }),
|
||||
|
||||
check('entries.*.id').optional().isNumeric().toInt(),
|
||||
@@ -117,6 +127,8 @@ export default class BillsController extends BaseController {
|
||||
check('due_date').optional().isISO8601(),
|
||||
check('vendor_id').exists().isNumeric().toInt(),
|
||||
check('note').optional().trim().escape(),
|
||||
check('open').default(false).isBoolean().toBoolean(),
|
||||
|
||||
check('entries').isArray({ min: 1 }),
|
||||
|
||||
check('entries.*.id').optional().isNumeric().toInt(),
|
||||
@@ -185,12 +197,13 @@ export default class BillsController extends BaseController {
|
||||
* @param {Response} res
|
||||
*/
|
||||
async editBill(req: Request, res: Response, next: NextFunction) {
|
||||
const { id: billId } = req.params;
|
||||
const { id: billId, user } = req.params;
|
||||
const { tenantId } = req;
|
||||
const billDTO: IBillEditDTO = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
const editedBill = await this.billsService.editBill(tenantId, billId, billDTO);
|
||||
await this.billsService.editBill(tenantId, billId, billDTO, user);
|
||||
|
||||
return res.status(200).send({
|
||||
id: billId,
|
||||
message: 'The bill has been edited successfully.',
|
||||
@@ -200,6 +213,27 @@ export default class BillsController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the given bill.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async openBill(req: Request, res: Response, next: NextFunction) {
|
||||
const { id: billId } = req.params;
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
await this.billsService.openBill(tenantId, billId);
|
||||
|
||||
return res.status(200).send({
|
||||
id: billId,
|
||||
message: 'The bill has been opened successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given bill details with associated item entries.
|
||||
* @param {Request} req
|
||||
@@ -339,6 +373,11 @@ export default class BillsController extends BaseController {
|
||||
errors: [{ type: 'ITEMS_NOT_FOUND', code: 1000 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'BILL_ALREADY_OPEN') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [{ type: 'BILL_ALREADY_OPEN', code: 1100 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user