-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypescript.json
73 lines (73 loc) · 2.51 KB
/
typescript.json
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
"store": {
"prefix": "freenitstore",
"body": [
"import { methods } from '@freenit-framework/core'",
"import store from '.'",
"",
"export default class ${1/(.*)/${1:/capitalize}/}Store {",
" list = \\$state({ page: 0, perpage: 0, pages: 0, data: [], total: 0 })",
" detail = \\$state({ id: 0 })",
"",
" constructor(prefix) {",
" this.prefix = prefix",
" }",
"",
" fetchAll = async (page: Number = 1, perpage: Number = 10) => {",
" await store.auth.refresh_token()",
" const response = await methods.get(`\\${this.prefix}/${1}s`, { page, perpage })",
" if (response.ok) {",
" const data = await response.json()",
" this.list = data",
" return { ...data, ok: true }",
" }",
" return response",
" }",
"",
" create = async (fields: Record<string, any>) => {",
" await store.auth.refresh_token()",
" const response = await methods.post(`\\${this.prefix}/${1}s`, fields)",
" if (response.ok) {",
" const data = await response.json()",
" this.list.data.push(data)",
" return { ...data, ok: true }",
" }",
" return response",
" }",
"",
" fetch = async (id: Number) => {",
" await store.auth.refresh_token()",
" const response = await methods.get(`\\${this.prefix}/${1}s/\\${id}`)",
" if (response.ok) {",
" const data = await response.json()",
" this.detail = data",
" return { ...data, ok: true }",
" }",
" return response",
" }",
"",
" edit = async (id: Number, fields: Record<string, any>) => {",
" await store.auth.refresh_token()",
" const response = await methods.patch(`\\${this.prefix}/${1}s/\\${id}`, fields)",
" if (response.ok) {",
" const data = await response.json()",
" this.detail = data",
" return { ...data, ok: true }",
" }",
" return response",
" }",
"",
" destroy = async (id: Number) => {",
" await store.auth.refresh_token()",
" const response = await methods.delete(`\\${this.prefix}/${1}s/\\${id}`)",
" if (response.ok) {",
" const data = await response.json()",
" return { ...data, ok: true }",
" }",
" return response",
" }",
"}"
],
"description": "Freenit Svelte store"
}
}