summaryrefslogtreecommitdiff
path: root/src-migrate/services/cart.ts
blob: 73967073617c588c1652628b96d6fbde308b977e (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
27
28
29
import odooApi from '~/libs/odooApi';

export const getUserCart = async (userId: number) => {
  return await odooApi('GET', `/api/v1/user/${userId}/cart`);
};

export const upsertUserCart = async (
  userId: number,
  type: 'product' | 'promotion',
  id: number,
  qty: number,
  selected: boolean,
  source: 'buy' | 'add_to_cart' = 'add_to_cart'
) => {
  return await odooApi('POST', `/api/v1/user/${userId}/cart/create-or-update`, {
    product_id: type === 'product' ? id : null,
    qty,
    selected,
    program_line_id: type === 'promotion' ? id : null,
    source,
  });
};

export const deleteUserCart = async (userId: number, ids: number[]) => {
  return await odooApi(
    'DELETE',
    `/api/v1/user/${userId}/cart?ids=${ids.join(',')}`
  );
};