/* eslint-disable @typescript-eslint/no-explicit-any */ /** @module operations */ import { IProductsClientV1 } from "bm-vslice-ecommerce-layered-client-products-pipservices-node"; import { Context, Descriptor, IReferences, } from "pip-services4-components-node"; import { IdGenerator } from "pip-services4-data-node"; import { RestOperations } from "pip-services4-http-node"; export class ProductsOperationsV1 extends RestOperations { private _productsClient: IProductsClientV1; private _traceId = "products-operations"; public constructor() { super(); this._dependencyResolver.put( "products", new Descriptor("service-products", "client", "*", "*", "1.0") ); } public setReferences(references: IReferences): void { super.setReferences(references); this._productsClient = this._dependencyResolver.getOneRequired("products"); } public async getProducts(req: any, res: any): Promise { const filter = this.getFilterParams(req); const paging = this.getPagingParams(req); const sorting = this.getSortParams(req); try { const page = await this._productsClient.getProducts( Context.fromTraceId(this._traceId + IdGenerator.nextShort()), filter, paging, sorting ); this.sendResult(req, res, page); } catch (err) { this.sendError(req, res, err); } } public async getProductById(req: any, res: any): Promise { const id = req.route.params.id; try { const product = await this._productsClient.getProductById( Context.fromTraceId(this._traceId + IdGenerator.nextShort()), id ); this.sendResult(req, res, product); } catch (err) { this.sendError(req, res, err); } } public async getCategories(req: any, res: any): Promise { try { const page = await this._productsClient.getCategories( Context.fromTraceId(this._traceId + IdGenerator.nextShort()), null, null ); this.sendResult(req, res, page); } catch (err) { this.sendError(req, res, err); } } public async getBrands(req: any, res: any): Promise { const filter = this.getFilterParams(req); try { const page = await this._productsClient.getBrands( Context.fromTraceId(this._traceId + IdGenerator.nextShort()), filter, null ); this.sendResult(req, res, page); } catch (err) { this.sendError(req, res, err); } } public async createProduct(req: any, res: any): Promise { const data = req.body; try { const product = await this._productsClient.createProduct(null, data); this.sendResult(req, res, product); } catch (err) { this.sendError(req, res, err); } } }