refactor: currencies service.

refactor: exchange rates service.
This commit is contained in:
Ahmed Bouhuolia
2020-09-26 16:23:57 +02:00
parent 986cd6b7a0
commit 933afb37bf
25 changed files with 878 additions and 401 deletions

View File

@@ -1,12 +1,11 @@
import { check, param, query } from 'express-validator';
import { check, param, query, ValidationChain } from 'express-validator';
import BaseController from "api/controllers/BaseController";
export default class ContactsController extends BaseController {
/**
* Contact DTO schema.
* @returns {ValidationChain[]}
*/
get contactDTOSchema() {
get contactDTOSchema(): ValidationChain[] {
return [
check('first_name').optional().trim().escape(),
check('last_name').optional().trim().escape(),
@@ -39,8 +38,9 @@ export default class ContactsController extends BaseController {
/**
* Contact new DTO schema.
* @returns {ValidationChain[]}
*/
get contactNewDTOSchema() {
get contactNewDTOSchema(): ValidationChain[] {
return [
check('balance').optional().isNumeric().toInt(),
];
@@ -48,20 +48,27 @@ export default class ContactsController extends BaseController {
/**
* Contact edit DTO schema.
* @returns {ValidationChain[]}
*/
get contactEditDTOSchema() {
get contactEditDTOSchema(): ValidationChain[] {
return [
]
}
get specificContactSchema() {
/**
* @returns {ValidationChain[]}
*/
get specificContactSchema(): ValidationChain[] {
return [
param('id').exists().isNumeric().toInt(),
];
}
get bulkContactsSchema() {
/**
* @returns {ValidationChain[]}
*/
get bulkContactsSchema(): ValidationChain[] {
return [
query('ids').isArray({ min: 2 }),
query('ids.*').isNumeric().toInt(),

View File

@@ -19,36 +19,36 @@ export default class CustomersController extends ContactsController {
const router = Router();
router.post('/', [
...this.contactDTOSchema,
...this.contactNewDTOSchema,
...this.customerDTOSchema,
],
...this.contactDTOSchema,
...this.contactNewDTOSchema,
...this.customerDTOSchema,
],
this.validationResult,
asyncMiddleware(this.newCustomer.bind(this))
);
router.post('/:id', [
...this.contactDTOSchema,
...this.contactEditDTOSchema,
...this.customerDTOSchema,
],
...this.contactDTOSchema,
...this.contactEditDTOSchema,
...this.customerDTOSchema,
],
this.validationResult,
asyncMiddleware(this.editCustomer.bind(this))
);
router.delete('/:id', [
...this.specificContactSchema,
],
...this.specificContactSchema,
],
this.validationResult,
asyncMiddleware(this.deleteCustomer.bind(this))
);
router.delete('/', [
...this.bulkContactsSchema,
],
...this.bulkContactsSchema,
],
this.validationResult,
asyncMiddleware(this.deleteBulkCustomers.bind(this))
);
router.get('/:id', [
...this.specificContactSchema,
],
...this.specificContactSchema,
],
this.validationResult,
asyncMiddleware(this.getCustomer.bind(this))
);

View File

@@ -1,6 +1,6 @@
import { Request, Response, Router, NextFunction } from 'express';
import { Service, Inject } from 'typedi';
import { check, query } from 'express-validator';
import { check, query, ValidationChain } from 'express-validator';
import ContactsController from 'api/controllers/Contacts/Contacts';
import VendorsService from 'services/Contacts/VendorsService';
import { ServiceError } from 'exceptions';
@@ -19,42 +19,42 @@ export default class VendorsController extends ContactsController {
const router = Router();
router.post('/', [
...this.contactDTOSchema,
...this.contactNewDTOSchema,
...this.vendorDTOSchema,
],
...this.contactDTOSchema,
...this.contactNewDTOSchema,
...this.vendorDTOSchema,
],
this.validationResult,
asyncMiddleware(this.newVendor.bind(this))
);
router.post('/:id', [
...this.contactDTOSchema,
...this.contactEditDTOSchema,
...this.vendorDTOSchema,
],
...this.contactDTOSchema,
...this.contactEditDTOSchema,
...this.vendorDTOSchema,
],
this.validationResult,
asyncMiddleware(this.editVendor.bind(this))
);
router.delete('/:id', [
...this.specificContactSchema,
],
...this.specificContactSchema,
],
this.validationResult,
asyncMiddleware(this.deleteVendor.bind(this))
);
router.delete('/', [
...this.bulkContactsSchema,
],
...this.bulkContactsSchema,
],
this.validationResult,
asyncMiddleware(this.deleteBulkVendors.bind(this))
);
router.get('/:id', [
...this.specificContactSchema,
],
...this.specificContactSchema,
],
this.validationResult,
asyncMiddleware(this.getVendor.bind(this))
);
router.get('/', [
...this.vendorsListSchema,
],
...this.vendorsListSchema,
],
this.validationResult,
asyncMiddleware(this.getVendorsList.bind(this)),
);
@@ -63,8 +63,9 @@ export default class VendorsController extends ContactsController {
/**
* Vendor DTO schema.
* @returns {ValidationChain[]}
*/
get vendorDTOSchema() {
get vendorDTOSchema(): ValidationChain[] {
return [
check('opening_balance').optional().isNumeric().toInt(),
];
@@ -72,6 +73,7 @@ export default class VendorsController extends ContactsController {
/**
* Vendors datatable list validation schema.
* @returns {ValidationChain[]}
*/
get vendorsListSchema() {
return [
@@ -231,7 +233,7 @@ export default class VendorsController extends ContactsController {
const vendors = await this.vendorsService.getVendorsList(tenantId, vendorsFilter);
return res.status(200).send({ vendors });
} catch (error) {
next(error);
}
}
}