aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-frontend/src/api/templates.ts
blob: 0c8dffd9587da99a80ab1b943fa22f4da6247f8c (plain) (blame)
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
import { get, APIMissingTokenError } from "./client";
import store from "../store";

export interface Variant {
    variant_id: number;
    name: string;
    size: string;
    colour?: string;
    colour_code?: string;
    colour_code2?: string;
    price: string;
    last_synced: string;
}

export interface Template {
    template_id: number;
    title: string;
    product_id: number;
    mockup_file_url: string;
    last_synced: string;
    variants?: Variant[];
}

export const getTemplates = async (withVariants: boolean): Promise<Template[]> => {
    /* TODO: Handle lacking authorization */

    const token = store.getState().authorization.voucherToken;

    if (!token) {
        throw new APIMissingTokenError();
    };

    return await get(`/templates/?with_variants=${withVariants.toString()}`, {
        headers: {
            Authorization: `Bearer ${token}`,
        },
    }) as unknown as Template[];
};