/** @module controllers */ import { ConfigParams, IReferences } from 'pip-services4-components-node'; import { RestController } from 'pip-services4-http-node'; import { ProductsOperationsV1 } from '../../operations/version1/ProductsOperationsV1'; import { OrdersOperationsV1 } from '../../operations/version1/OrdersOperationsV1'; import { PaymentsOperationsV1 } from '../../operations/version1/PaymentsOperationsV1'; import { AuthorizerV1 } from './AuthorizerV1'; export class FacadeControllerV1 extends RestController { private _productsOperations = new ProductsOperationsV1(); private _ordersOperations = new OrdersOperationsV1(); private _paymentsOperations = new PaymentsOperationsV1(); public constructor() { super(); this._baseRoute = "api/v1"; } public configure(config: ConfigParams): void { super.configure(config); this._productsOperations.configure(config); this._ordersOperations.configure(config); this._paymentsOperations.configure(config); } public setReferences(references: IReferences): void { super.setReferences(references); this._productsOperations.setReferences(references); this._ordersOperations.setReferences(references); this._paymentsOperations.setReferences(references); } public register(): void { const auth = new AuthorizerV1(); // register charset middleware this.registerInterceptor('', (req, res, next) => { res.charSet('utf-8'); next(); }); this.registerRoutes(auth); } private registerRoutes(auth: AuthorizerV1): void { // Products routes this.registerRouteWithAuth('get', '/products', null, auth.anybody(), (req, res) => { this._productsOperations.getProducts(req, res); }); this.registerRouteWithAuth('get', '/products/:id', null, auth.anybody(), (req, res) => { this._productsOperations.getProductById(req, res); }); this.registerRouteWithAuth('get', '/products/categories', null, auth.anybody(), (req, res) => { this._productsOperations.getCategories(req, res); }); this.registerRouteWithAuth('get', '/products/brands', null, auth.anybody(), (req, res) => { this._productsOperations.getBrands(req, res); }); this.registerRouteWithAuth('post', '/products', null, auth.anybody(), (req, res) => { this._productsOperations.createProduct(req, res); }); // Orders routes this.registerRouteWithAuth('get', '/orders', null, auth.anybody(), (req, res) => { this._ordersOperations.getOrders(req, res); }); this.registerRouteWithAuth('get', '/orders/:id/:customer_id', null, auth.anybody(), (req, res) => { this._ordersOperations.getOrderById(req, res); }); this.registerRouteWithAuth('post', '/orders/checkout', null, auth.anybody(), (req, res) => { this._ordersOperations.createOrder(req, res); }); this.registerRouteWithAuth('post', '/orders/checkout_and_pay', null, auth.anybody(), (req, res) => { this._ordersOperations.checkoutAndPay(req, res); }); this.registerRouteWithAuth('put', '/orders', null, auth.anybody(), (req, res) => { this._ordersOperations.updateOrder(req, res); }); // Payment Methods routes this.registerRouteWithAuth('get', '/payment_methods/:customer_id', null, auth.anybody(), (req, res) => { this._paymentsOperations.getPaymentMethods(req, res); }); } }