summaryrefslogtreecommitdiff
path: root/src/lib/product/api/productSimilarApi.js
blob: 2470937d13305139f08ac02161aa532ba32342ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import odooApi from '@/core/api/odooApi'
import axios from 'axios'
import productSearchApi from './productSearchApi'

const productSimilarApi = async ({ query }) => {
  let dataFlashSale = null
  const flashSale = await odooApi('GET', '/api/v1/flashsale/header')
  if(flashSale){
    const dataProducts = await productSearchApi({
      query: `fq=flashsale_id_i:${flashSale[0].pricelistId}&fq=flashsale_price_f:[1 TO *]&limit=2`,
      operation: 'AND'
    })
    dataFlashSale = dataProducts.response.products
  }
  const dataProductSimilar = await axios(
    `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=${query}&page=1&orderBy=popular-weekly&operation=OR`
  )
  dataProductSimilar.data.response.products = [
    ...dataFlashSale,
    ...dataProductSimilar.data.response.products,
  ];
  return dataProductSimilar.data.response
}

export default productSimilarApi