UNPKG

1.63 kBJavaScriptView Raw
1
2const Base = require("./Base")
3const Pager = require("./pager")
4
5class App extends Base {
6
7 create(app) {
8 return this.getClient().post(this.route("APP_CREATE"), app)
9 }
10
11 update(app) {
12 if(!app.id) throw new Error("App id is missing")
13 return this.getClient().put(this.route("APP_UPDATE", app.id), app)
14 }
15
16 save(app) {
17 if(app.id) {
18 return this.update(app)
19 }
20 return this.create(app)
21 }
22
23 delete(app) {
24 app = app.id ? app : { id: app.id }
25 if(!app.id) throw new Error("App id is missing")
26 return this.getClient().delete(this.route("APP_DELETE", app.id))
27 }
28
29 read(app) {
30 const id = app.id ? app.id : app
31 const path = this.route("APP_READ", id)
32 return this.getClient().get(path)
33 }
34
35 list(paging) {
36 const url = this.route("APP_LIST") + Pager.buildQuery(paging)
37 return this.getClient().get(url)
38 .then((res) => Promise.resolve(Pager.create(res)))
39 }
40
41 supportCodec() {
42 const url = this.route("APP_SUPPORTED_CODEC")
43 return this.getClient().get(url)
44 .then((res) => Promise.resolve(res))
45 }
46
47 search(q) {
48 return this.getClient().post(this.route("APP_SEARCH"), q)
49 .then((res) => Promise.resolve(Pager.create(res)))
50 }
51
52 deleteUser(appId, userId) {
53 if(!appId) throw new Error("App id is missing")
54 if(!userId) throw new Error("user id is missing")
55 const url = this.route("APP_DELETE_USER", appId, userId)
56 return this.getClient().get(url)
57 }
58
59}
60
61
62module.exports = App