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:
Ahmed Bouhuolia
2020-12-13 19:50:59 +02:00
parent e9e4ddaee0
commit 188e411f02
78 changed files with 1634 additions and 869 deletions

View File

@@ -7,6 +7,7 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
import SaleEstimateService from 'services/Sales/SalesEstimate';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import { ServiceError } from "exceptions";
import { Request } from 'express-validator/src/base';
@Service()
export default class SalesEstimatesController extends BaseController {
@@ -30,6 +31,15 @@ export default class SalesEstimatesController extends BaseController {
asyncMiddleware(this.newEstimate.bind(this)),
this.handleServiceErrors,
);
router.post(
'/:id/deliver',
[
...this.validateSpecificEstimateSchema,
],
this.validationResult,
asyncMiddleware(this.deliverSaleEstimate.bind(this)),
this.handleServiceErrors,
);
router.post(
'/:id', [
...this.validateSpecificEstimateSchema,
@@ -75,6 +85,7 @@ export default class SalesEstimatesController extends BaseController {
check('expiration_date').optional().isISO8601(),
check('reference').optional(),
check('estimate_number').exists().trim().escape(),
check('delivered').default(false).isBoolean().toBoolean(),
check('entries').exists().isArray({ min: 1 }),
check('entries.*.index').exists().isNumeric().toInt(),
@@ -170,6 +181,27 @@ export default class SalesEstimatesController extends BaseController {
}
}
/**
* Deliver the given sale estimate.
* @param {Request} req
* @param {Response} res
*/
async deliverSaleEstimate(req: Request, res: Response, next: NextFunction) {
const { id: estimateId } = req.params;
const { tenantId } = req;
try {
await this.saleEstimateService.deliverSaleEstimate(tenantId, estimateId);
return res.status(200).send({
id: estimateId,
message: 'The sale estimate has been delivered successfully.',
});
} catch (error) {
next(error);
}
}
/**
* Retrieve the given estimate with associated entries.
*/

View File

@@ -28,11 +28,23 @@ export default class SaleInvoicesController extends BaseController{
router.post(
'/',
this.saleInvoiceValidationSchema,
[
...this.saleInvoiceValidationSchema,
check('from_estimate_id').optional().isNumeric().toInt(),
],
this.validationResult,
asyncMiddleware(this.newSaleInvoice.bind(this)),
this.handleServiceErrors,
);
router.post(
'/:id/deliver',
[
...this.specificSaleInvoiceValidation,
],
this.validationResult,
asyncMiddleware(this.deliverSaleInvoice.bind(this)),
this.handleServiceErrors,
)
router.post(
'/:id',
[
@@ -86,7 +98,7 @@ export default class SaleInvoicesController extends BaseController{
check('due_date').exists().isISO8601(),
check('invoice_no').optional().trim().escape(),
check('reference_no').optional().trim().escape(),
check('status').exists().trim().escape(),
check('delivered').default(false).isBoolean().toBoolean(),
check('invoice_message').optional().trim().escape(),
check('terms_conditions').optional().trim().escape(),
@@ -172,6 +184,28 @@ export default class SaleInvoicesController extends BaseController{
next(error);
}
}
/**
* Deliver the given sale invoice.
* @param {Request} req -
* @param {Response} res -
* @param {NextFunction} next -
*/
async deliverSaleInvoice(req: Request, res: Response, next: NextFunction) {
const { tenantId } = req;
const { id: saleInvoiceId } = req.params;
try {
await this.saleInvoiceService.deliverSaleInvoice(tenantId, saleInvoiceId);
return res.status(200).send({
id: saleInvoiceId,
message: 'The given sale invoice has been published successfully',
});
} catch (error) {
next(error);
}
}
/**
* Deletes the sale invoice with associated entries and journal transactions.
@@ -319,6 +353,11 @@ export default class SaleInvoicesController extends BaseController{
errors: [{ type: 'CUSTOMER_NOT_FOUND', code: 200 }],
});
}
if (error.errorType === 'SALE_INVOICE_ALREADY_DELIVERED') {
return res.boom.badRequest(null, {
errors: [{ type: 'SALE_INVOICE_ALREADY_DELIVERED', code: 200 }],
});
}
}
next(error);
}