From 8a52eeb310ebafd6a124a8891c36bf066a5dac16 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sun, 6 Mar 2022 10:56:29 +0530 Subject: [PATCH] feat: implement getOrder on legacy --- src/LegacySocket/business.ts | 40 +++++++++++++++++++++++++++++++++++- src/Types/Product.ts | 20 ++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/LegacySocket/business.ts b/src/LegacySocket/business.ts index 9a06aba..3faba02 100644 --- a/src/LegacySocket/business.ts +++ b/src/LegacySocket/business.ts @@ -1,4 +1,4 @@ -import { LegacySocketConfig } from '../Types' +import { LegacySocketConfig, OrderDetails } from '../Types' import { CatalogResult, Product, ProductCreate, ProductCreateResult, ProductUpdate } from '../Types' import makeGroupsSocket from './groups' @@ -90,6 +90,43 @@ const makeBusinessSocket = (config: LegacySocketConfig) => { return mapProduct(result.data.product) } + const getOrderDetails = async(orderId: string, tokenBase64: string) => { + const result = await query({ + expect200: true, + json: [ + 'query', + 'order', + { + id: generateMessageTag(true), + orderId, + imageWidth: '80', + imageHeight: '80', + token: tokenBase64 + } + ] + }) + + const data = result.data + const order: OrderDetails = { + price: { + currency: data.price.currency, + total: data.price.total, + }, + products: data.products.map( + p => ({ + id: p.id, + imageUrl: p.image?.url, + name: p.name, + quantity: +p.quantity, + currency: p.currency, + price: +p.price + }) + ) + } + + return order + } + // maps product create to send to WA const mapProductCreate = (product: ProductCreate, mapCompliance = true) => { const result: any = { @@ -121,6 +158,7 @@ const makeBusinessSocket = (config: LegacySocketConfig) => { return { ...sock, + getOrderDetails, getCatalog, productCreate, productDelete, diff --git a/src/Types/Product.ts b/src/Types/Product.ts index c6d25ec..653fe3c 100644 --- a/src/Types/Product.ts +++ b/src/Types/Product.ts @@ -36,4 +36,24 @@ export type Product = ProductBase & { imageUrls: { [_: string]: string } reviewStatus: { [_: string]: string } availability: ProductAvailability +} + +export type OrderPrice = { + currency: string + total: number +} + +export type OrderProduct = { + id: string + imageUrl: string + name: string + quantity: number + + currency: string + price: number +} + +export type OrderDetails = { + price: OrderPrice + products: OrderProduct[] } \ No newline at end of file