# Code coverage report for api/savings.js

# All files / api savings.js

73.52% Statements 25/34
100% Branches 4/4
70% Functions 21/30
69.56% Lines 16/23

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

    1x

    1x
    1x
    1x

    1x
    1x

    2x
    2x
    2x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

     import api from "./client"

    export const savingsApi = {
      // Categories
      listCategories: () => api.get("/savings/categories").then((r) => r.data),
      getCategory: (id) => api.get(`/savings/categories/${id}`).then((r) => r.data),
      createCategory: (data) => api.post("/savings/categories", data).then((r) => r.data),
      updateCategory: (id, data) =>
        api.put(`/savings/categories/${id}`, data).then((r) => r.data),
      deleteCategory: (id) => api.delete(`/savings/categories/${id}`),

      // Transactions
      listTransactions: (categoryId, limit = 100, offset = 0) => {
        let url = `/savings/transactions?limit=${limit}&offset=${offset}`
        if (categoryId) url += `&category_id=${categoryId}`
        return api.get(url).then((r) => r.data)
      },
      createTransaction: (data) =>
        api.post("/savings/transactions", data).then((r) => r.data),
      updateTransaction: (id, data) =>
        api.put(`/savings/transactions/${id}`, data).then((r) => r.data),
      deleteTransaction: (id) => api.delete(`/savings/transactions/${id}`),

      // Stats
      getStats: () => api.get("/savings/stats").then((r) => r.data),

      // Members
      getMembers: (categoryId) =>
        api.get(`/savings/categories/${categoryId}/members`).then((r) => r.data),
      addMember: (categoryId, userId) =>
        api
          .post(`/savings/categories/${categoryId}/members`, { user_id: userId })
          .then((r) => r.data),
      removeMember: (categoryId, userId) =>
        api.delete(`/savings/categories/${categoryId}/members/${userId}`),

      // Recurring Plans
      getRecurringPlans: (categoryId) =>
        api
          .get(`/savings/categories/${categoryId}/recurring-plans`)
          .then((r) => r.data),
      createRecurringPlan: (categoryId, data) =>
        api
          .post(`/savings/categories/${categoryId}/recurring-plans`, data)
          .then((r) => r.data),
      updateRecurringPlan: (planId, data) =>
        api.put(`/savings/recurring-plans/${planId}`, data).then((r) => r.data),
      deleteRecurringPlan: (planId) =>
        api.delete(`/savings/recurring-plans/${planId}`),
    }