summaryrefslogtreecommitdiff
path: root/src/api/productApi.js
blob: dc96a77e4be3998c71c4811b5763467cebc02c6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;
  };
};