summaryrefslogtreecommitdiff
path: root/src/api/productApi.js
blob: 6d0431722bc157dd056d639530924477f141abd6 (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
26
import odooApi from '@/core/api/odooApi'
import productSearchApi from '@/lib/product/api/productSearchApi'
import axios from 'axios'
import { useState } from 'react'

export const popularProductApi = () => {
  let dataFlashSale = null
  return async () => {
    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 dataPopularProducts = await axios(
      `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=1&orderBy=popular-weekly`
    )
    dataPopularProducts.data.response.products = [
      ...dataFlashSale,
      ...dataPopularProducts.data.response.products,
    ];
    return dataPopularProducts.data.response
  }
}