-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscenes.ts
63 lines (56 loc) · 1.3 KB
/
scenes.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
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { Got } from 'got' with { 'resolution-mode': 'require' }
import type { Scene } from '../types/Scene'
export default (got: Got) => {
return {
async list() {
return await got.get(`scenes`).json<Scene[]>()
},
async get({ id }: { id: string }) {
return await got.get(`scenes/${id}`).json<Scene>()
},
async trigger({ id }: { id: string }) {
await got.post(`scenes/${id}/trigger`).json()
},
async undo({ id }: { id: string }) {
await got.post(`scenes/${id}/undo`).json()
},
async create({
info,
type,
actions,
triggers,
}: Pick<Scene, 'info' | 'type' | 'actions' | 'triggers'>) {
return await got
.post(`scenes`, {
json: {
info,
type,
actions,
triggers,
},
})
.json<{ id: string }>()
},
async delete({ id }: { id: string }) {
await got.delete(`scenes/${id}`)
},
async update({
id,
info,
type,
actions,
triggers,
}: Pick<Scene, 'id' | 'info' | 'type' | 'actions' | 'triggers'>) {
await got
.put(`scenes/${id}`, {
json: {
info,
type,
actions,
triggers,
},
})
.json()
},
}
}