Add endpoint to retrieve similar products and implement corresponding service method
This commit is contained in:
parent
6dba6fb1a9
commit
b1aae3304b
|
|
@ -176,6 +176,20 @@ export class SalesController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Get('product/simil/:id')
|
||||||
|
@ApiOperation({ summary: 'Get products similar' })
|
||||||
|
@ApiParam({ name: 'id', description: 'Product ID' })
|
||||||
|
async getProductSimil(@Headers() headers, @Param('id') id: number) {
|
||||||
|
try {
|
||||||
|
const { store } = this.extractPaginationParams(headers);
|
||||||
|
return await this.salesService.GetProductsSimil(store, id);
|
||||||
|
} catch (e) {
|
||||||
|
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Get('stock/:storeid/:id')
|
@Get('stock/:storeid/:id')
|
||||||
@ApiOperation({ summary: 'Get product stock information' })
|
@ApiOperation({ summary: 'Get product stock information' })
|
||||||
@ApiParam({ name: 'storeid', description: 'Store ID' })
|
@ApiParam({ name: 'storeid', description: 'Store ID' })
|
||||||
|
|
|
||||||
|
|
@ -851,6 +851,66 @@ export class SalesService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async GetProductsSimil(store: string, id: number) {
|
||||||
|
const connectionDb = new Connection(connectionOptions);
|
||||||
|
await connectionDb.connect();
|
||||||
|
const queryRunner = connectionDb.createQueryRunner();
|
||||||
|
await queryRunner.connect();
|
||||||
|
try {
|
||||||
|
const sql = `SELECT esvlistaprodutos.CODPROD as "idProduct"
|
||||||
|
,esvlistaprodutos.SEQ as "seq"
|
||||||
|
,esvlistaprodutos.DESCRICAO as "smallDescription"
|
||||||
|
,esvlistaprodutos.NOMEECOMMERCE as "title"
|
||||||
|
,esvlistaprodutos.CODFAB as "idProvider"
|
||||||
|
,esvlistaprodutos.CODAUXILIAR as "ean"
|
||||||
|
,esvlistaprodutos.TIPOPRODUTO as "productType"
|
||||||
|
,esvlistaprodutos.DADOSTECNICOS as "technicalData"
|
||||||
|
,esvlistaprodutos.INFORMACOESTECNICAS as "description"
|
||||||
|
,esvlistaprodutos.URLIMAGEM as "urlImage"
|
||||||
|
,esvlistaprodutos.NOMEMARCA as "brand"
|
||||||
|
,esvlistaprodutos.NOMEDEPARTAMENTO as "department"
|
||||||
|
,esvlistaprodutos.NOMESECAO as "section"
|
||||||
|
,esvlistaprodutos.NOMECATEGORIA as "category"
|
||||||
|
,esvlistaprodutos.NOMEFORNECEDOR as "supplier"
|
||||||
|
,esvlistaprodutos.CODIGOFILIAL as "store"
|
||||||
|
,esvlistaprodutos.CLASSEVENDA as "saleAbc"
|
||||||
|
,esvlistaprodutos.CLASSEESTOQUE as "stockAbc"
|
||||||
|
,esvlistaprodutos.FORALINHA as "outLine"
|
||||||
|
,esvlistaprodutos.PRECOVENDA as "listPrice"
|
||||||
|
,esvlistaprodutos.PRECOPROMOCIONAL as "salePrice"
|
||||||
|
,esvlistaprodutos.PRECOPROMOCIONAL as "salePromotion"
|
||||||
|
,esvlistaprodutos.PERCENTUALDESCONTO as"offPercent"
|
||||||
|
,esvlistaprodutos.QTESTOQUE_DISPONIVEL as "stock"
|
||||||
|
,esvlistaprodutos.QTCAIXAS as "boxStock"
|
||||||
|
,esvlistaprodutos.ESTOQUE_DISP_LOJA as "store_stock"
|
||||||
|
,esvlistaprodutos.ESTOQUE_DISP_CAIXA_LOJA as "store_boxStock"
|
||||||
|
,esvlistaprodutos.ESTOQUE_DISP_LOJA as "store_stock"
|
||||||
|
,esvlistaprodutos.ESTOQUE_DISP_CAIXA_LOJA as "store_boxStock"
|
||||||
|
,esvlistaprodutos.MULTIPLO as "mutiple"
|
||||||
|
,esvlistaprodutos.UNIDADE as "unity"
|
||||||
|
,esvlistaprodutos.URLDEPARTAMENTO as "urlDepartment"
|
||||||
|
,esvlistaprodutos.URLSECAO as "urlSection"
|
||||||
|
,esvlistaprodutos.PRODUTO_COM_REDUCAO_PRECO as "downPrice"
|
||||||
|
,esvlistaprodutos.PRODUTO_EM_CAMPANHA as "compaing"
|
||||||
|
,esvlistaprodutos.BASETINTOMETRICO as "base"
|
||||||
|
,esvlistaprodutos.QUANTIDADE_ESTOQUE_GERAL as "full_stock"
|
||||||
|
FROM ESVLISTAPRODUTOS, PCPRODSIMIL
|
||||||
|
WHERE ESVLISTAPRODUTOS.CODPROD = PCPRODSIMIL.CODSIMIL
|
||||||
|
AND PCPRODSIMIL.CODPROD = ${id}
|
||||||
|
AND ESVLISTAPRODUTOS.CODFILIAL = '${store}'
|
||||||
|
ORDER BY REPLACE(esvlistaprodutos.DESCRICAO,'#', '')`;
|
||||||
|
let products: SalesProduct[] = await queryRunner.query(sql);
|
||||||
|
|
||||||
|
products = this.createListImages(products);
|
||||||
|
return products;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release();
|
||||||
|
await connectionDb.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async GetStocks(storeId: string, id: number) {
|
async GetStocks(storeId: string, id: number) {
|
||||||
const connectionDb = new Connection(connectionOptions);
|
const connectionDb = new Connection(connectionOptions);
|
||||||
await connectionDb.connect();
|
await connectionDb.connect();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue