All files / src/api/v1 Surveys.js

43.75% Statements 14/32
75% Branches 3/4
42.85% Functions 3/7
43.75% Lines 14/32

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 331x 1x 1x 1x 30x 30x 1x 1x 1x 1x 1x 1x 1x                                     1x  
export default class Surveys {
    #client;
 
    constructor(client) {
        this.#client = client;
    }
 
    get(id = null)  { return id ? this.#client.get(`/surveys/${id}`) : this.#client.get('/surveys'); }
    create(data)    { return this.#client.put('/surveys', data); }
    edit(id, data)  { return this.#client.patch(`/surveys/${id}`, data); }
    delete(id)      { return this.#client.del(`/surveys/${id}`); }
 
    questions(surveyId) {
        const client = this.#client;
        const base = `/surveys/${surveyId}/questions`;
        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}`),
            answers: (questionId) => {
                const aBase = `${base}/${questionId}/answers`;
                return {
                    get:    (id = null) => id ? client.get(`${aBase}/${id}`) : client.get(aBase),
                    create: (data)      => client.put(aBase, data),
                    edit:   (id, data)  => client.patch(`${aBase}/${id}`, data),
                    delete: (id)        => client.del(`${aBase}/${id}`),
                };
            },
        };
    }
}