All files Surveys.js

100% Statements 32/32
100% Branches 22/22
100% Functions 16/16
100% Lines 32/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 15x 15x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 5x 5x 5x 5x 5x 5x 5x 5x 10x 10x 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}`),
                };
            },
        };
    }
}