summaryrefslogtreecommitdiff
path: root/src/models/product.ts
blob: b375537e1986765d56206f17bdafb36f8bc49b2b (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
export interface Product {
  id: number;
  name: string;
  picture: string;
  unitary_price: number;
  bulk_price: number;
  available_quantity: number;
  company_name: string;
}

export function mapProduct(data: any) {
  if(!data)
    return null;

  const product: Product = {
    id: data.id,
    name: data.attributes.name,
    picture: data.attributes.picture,
    unitary_price: data.attributes.unitary_price,
    bulk_price: data.attributes.bulk_price,
    available_quantity: data.attributes.available_quantity,
    company_name: data.attributes.company.name
  };

  return product;
}