All files / src/services item.ts

100% Statements 17/17
100% Branches 0/0
100% Functions 16/16
100% Lines 9/9

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      1x   1x       1x       1x       1x       1x       1x       1x       1x      
import api from './api'
import type { Item, CreateItemRequest, UpdateItemRequest } from '../types'
 
export const itemService = {
  getAll(listId: string): Promise<Item[]> {
    return api.get<Item[]>(`/lists/${listId}/items`).then(r => r.data)
  },
 
  getTrash(listId: string): Promise<Item[]> {
    return api.get<Item[]>(`/lists/${listId}/items/trash`).then(r => r.data)
  },
 
  create(listId: string, req: CreateItemRequest): Promise<Item> {
    return api.post<Item>(`/lists/${listId}/items`, req).then(r => r.data)
  },
 
  update(listId: string, itemId: string, req: UpdateItemRequest): Promise<Item> {
    return api.put<Item>(`/lists/${listId}/items/${itemId}`, req).then(r => r.data)
  },
 
  toggleCheck(listId: string, itemId: string): Promise<Item> {
    return api.patch<Item>(`/lists/${listId}/items/${itemId}/check`).then(r => r.data)
  },
 
  delete(listId: string, itemId: string): Promise<void> {
    return api.delete(`/lists/${listId}/items/${itemId}`).then(() => undefined)
  },
 
  restore(listId: string, itemId: string): Promise<Item> {
    return api.patch<Item>(`/lists/${listId}/items/${itemId}/restore`).then(r => r.data)
  },
 
  permanentDelete(listId: string, itemId: string): Promise<void> {
    return api.delete(`/lists/${listId}/items/${itemId}/permanent`).then(() => undefined)
  },
}