1 |
|
2 | const Base = require("./Base")
|
3 | const Pager = require("./pager")
|
4 |
|
5 | class 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 | search(q) {
|
42 | return this.getClient().post(this.route("APP_SEARCH"), q)
|
43 | .then((res) => Promise.resolve(Pager.create(res)))
|
44 | }
|
45 |
|
46 | deleteUser(appId, userId) {
|
47 | if(!appId) throw new Error("App id is missing")
|
48 | if(!userId) throw new Error("user id is missing")
|
49 | const url = this.route("APP_DELETE_USER", appId, userId)
|
50 | return this.getClient().get(url)
|
51 | }
|
52 |
|
53 | }
|
54 |
|
55 |
|
56 | module.exports = App
|