summaryrefslogtreecommitdiff
path: root/src-migrate/services/cart.ts
blob: 11f87125c477d757be2d676006a93846bcc66319 (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
30
31
32
33
34
35
36
37
38
39
40
41
import odooApi from '~/libs/odooApi';

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

interface UpsertUserCartProps {
  userId: number;
  type: 'product' | 'promotion';
  id: number;
  qty: number;
  selected: boolean;
  source?: 'buy' | 'add_to_cart';
  qtyAppend?: boolean;
}

export const upsertUserCart = async ({
  userId,
  type,
  id,
  qty,
  selected,
  source = 'add_to_cart',
  qtyAppend = false,
}: UpsertUserCartProps) => {
  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,
    qty_append: qtyAppend,
  });
};

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