All files / src/api/v1 Users.js

38.55% Statements 32/83
80% Branches 4/5
22.22% Functions 4/18
38.55% Lines 32/83

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 841x 1x 1x 1x 30x 30x 1x 1x 1x 1x 1x 1x                   1x 1x 1x 1x 1x 1x 1x 1x 1x                       1x 1x                 1x 1x               1x 1x 1x 1x                 1x 1x                 1x  
export default class Users {
    #client;
 
    constructor(client) {
        this.#client = client;
    }
 
    get(id = null)      { return id ? this.#client.get(`/users/${id}`) : this.#client.get('/users'); }
    cashReceivers()     { return this.#client.get('/users/cash-receivers'); }
    edit(id, data)  { return this.#client.patch(`/users/${id}`, data); }
 
    #nested(userId, path) {
        const base = `/users/${userId}/${path}`;
        const client = this.#client;
        return {
            get:    (id = null) => id ? client.get(`${base}/${id}`) : client.get(base),
            create: (data)      => client.put(base, data),
            edit:   (id, data)  => client.patch(`${base}/${id}`, data),
            delete: (id)        => client.del(`${base}/${id}`),
        };
    }
 
    courses(userId)        { return this.#nested(userId, 'courses'); }
    courseNotes(userId)    { return this.#nested(userId, 'course-notes'); }
    quizzes(userId)        { return this.#nested(userId, 'quizzes'); }
    sessions(userId)       { return this.#nested(userId, 'sessions'); }
    surveys(userId)        { return this.#nested(userId, 'surveys'); }
    cart(userId)           { return this.#nested(userId, 'cart'); }
 
    payments(userId) {
        const base = `/users/${userId}/payments`;
        const client = this.#client;
        return {
            get:    (id = null) => id ? client.get(`${base}/${id}`) : client.get(base),
            create: (data)      => client.put(base, data),
            edit:   (id, data)  => client.patch(`${base}/${id}`, data),
            delete: (id)        => client.del(`${base}/${id}`),
            verify: (id)        => client.post(`${base}/${id}/verify`),
            reject: (id, data)  => client.post(`${base}/${id}/reject`, data),
        };
    }
 
    points(userId) {
        const base = `/users/${userId}/points`;
        const client = this.#client;
        return {
            get:    (id = null) => id ? client.get(`${base}/${id}`) : client.get(base),
            create: (data)      => client.put(base, data),
            delete: (id)        => client.del(`${base}/${id}`),
        };
    }
 
    moneyMoves(userId) {
        const base = `/users/${userId}/money-moves`;
        const client = this.#client;
        return {
            get:    (id = null) => id ? client.get(`${base}/${id}`) : client.get(base),
            create: (data)      => client.put(base, data),
        };
    }
 
    statistics(userId)     { return { get: () => this.#client.get(`/users/${userId}/statistics`) }; }
 
    organizations(userId) {
        const base = `/users/${userId}/organizations`;
        const client = this.#client;
        return {
            get:    (id = null) => id ? client.get(`${base}/${id}`) : client.get(base),
            create: (data)      => client.put(base, data),
            delete: (id)        => client.del(`${base}/${id}`),
        };
    }
 
    pushEndpoints(userId) {
        const base = `/users/${userId}/push-endpoints`;
        const client = this.#client;
        return {
            get:    (id = null) => id ? client.get(`${base}/${id}`) : client.get(base),
            create: (data)      => client.put(base, data),
            delete: (id)        => client.del(`${base}/${id}`),
        };
    }
}