-
Notifications
You must be signed in to change notification settings - Fork 18
/
stamps.ts
50 lines (43 loc) · 1.05 KB
/
stamps.ts
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
import { Module, VuexModule, Action, Mutation } from 'vuex-module-decorators';
import { Stamp } from '@/messages';
import { $axios } from '~/utils/api';
@Module({
name: 'stamps',
stateFactory: true,
namespaced: true,
})
export default class Stamps extends VuexModule {
stamps: Stamp[] = [];
@Mutation
setStamps(stamps: Stamp[]) {
this.stamps = stamps;
}
@Action
async fetchStamps() {
const stamps: Stamp[] = await $axios.$get(`/stamps`);
this.context.commit('setStamps', stamps);
}
@Action
async addStamp(form: FormData) {
await $axios.post('/stamps', form);
await this.context.dispatch('fetchStamps');
}
@Action
async deleteStamp(id: number) {
await $axios.$delete(`/stamps/${id}`);
await this.context.dispatch('fetchStamps');
}
@Action
async updateOrder(stamps: Stamp[]) {
await $axios.post(
'/stamps/order',
stamps.map((stamp, index) => {
return {
id: stamp.id,
order: index,
};
})
);
this.context.commit('setStamps', stamps);
}
}