summaryrefslogtreecommitdiff
path: root/src/api/productApi.js
blob: 4a29b59d8fd863057f1e53d692341929ba80283b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
import axios from 'axios'

export const popularProductApi = () => {
  return async () => {
    const today = new Date();
    const dayOfYear = Math.floor((today - new Date(today.getFullYear(), 0, 0)) / 86400000);
    const page = (dayOfYear % 24) + 1;
    const dataPopularProducts = await axios(
      `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=${page}&orderBy=stock&priceFrom=1`
    )
    return dataPopularProducts.data.response
  }
}