| 16 | import { PackItemAttr } from "types/item"; |
| 17 | |
| 18 | export default class Pack implements PackService { |
| 19 | private api: Api; |
| 20 | private baseUrl = '/pack'; |
| 21 | |
| 22 | constructor(baseApi: Api) { |
| 23 | this.api = baseApi; |
| 24 | } |
| 25 | |
| 26 | get: Get = (packId: number) => { |
| 27 | return this.api.get(`${this.baseUrl}/${packId}`) |
| 28 | .then((resp: AxiosResponse<PackPayload>) => resp.data) |
| 29 | }; |
| 30 | |
| 31 | getUserPacks: GetUserPacks = (userId: number) => { |
| 32 | return this.api.get(`${this.baseUrl}/user/${userId}`) |
| 33 | .then((resp: AxiosResponse<PackOverview[]>) => resp.data) |
| 34 | }; |
| 35 | |
| 36 | create: Create = pack => { |
| 37 | return this.api.post(`${this.baseUrl}`, pack) |
| 38 | .then((resp: AxiosResponse<PackPayload>) => resp.data) |
| 39 | }; |
| 40 | |
| 41 | update: Update = pack => { |
| 42 | return this.api.put(`${this.baseUrl}`, pack) |
| 43 | .then((resp: AxiosResponse<PackPayload>) => resp.data) |
| 44 | }; |
| 45 | |
| 46 | delete: Delete = (packId: number) => { |
| 47 | return this.api.post(`${this.baseUrl}/delete`, { packId }) |
| 48 | .then((resp: AxiosResponse<number>) => resp.data) |
| 49 | }; |
| 50 | |
| 51 | addItem: AddItem = packItem => { |
| 52 | return this.api.post(`${this.baseUrl}/add-item`, packItem) |
| 53 | .then((resp: AxiosResponse<PackItemAttr>) => resp.data); |
| 54 | }; |
| 55 | |
| 56 | removeItem: RemoveItem = (packId: number, itemId: number) => { |
| 57 | return this.api.post(`${this.baseUrl}/remove-item`, { packId, itemId }) |
| 58 | .then((resp: AxiosResponse<number>) => resp.data) |
| 59 | }; |
| 60 | |
| 61 | exportItems: ExportItems = packId => { |
| 62 | return this.api.get(`${this.baseUrl}/export/${packId}`) |
| 63 | .then((resp: AxiosResponse<File>) => resp.data); |
| 64 | } |
| 65 | } |