aboutsummaryrefslogtreecommitdiff
path: root/174bg/discord-bot/source/controllers/uex.js
blob: 615b5179f31aab08c181929c917732df1763bdbf (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 { get } from "./http.js";

export async function categories() {
    return await get("https://api.uexcorp.uk/2.0/categories");
}

export async function items(id_category) {
    let items = [];

    if (!id_category) {
        const { data: categories } = await get("https://api.uexcorp.uk/2.0/categories");

        for (const category of categories) {
            const { data: categoryItems } = await get(`https://api.uexcorp.uk/2.0/items?id_category=${category.id}`);

            if (!categoryItems) continue;

            items = items.concat(categoryItems);
        }
    } else {
        const { data } = await get(`https://api.uexcorp.uk/2.0/items?category=${id_category}`);

        items = data;
    }

    return items;
}

export default { categories, items };