UNPKG

1.18 kBJavaScriptView Raw
1
2const Base = require("../Base")
3
4class Client extends Base {
5
6 create(client) {
7 if (typeof client === "string") {
8 client = {
9 name: client
10 }
11 }
12 return this.getClient().post(this.route("CLIENT_CREATE"), client)
13 }
14
15 update(client) {
16 if(!client.id) throw new Error("Client id is missing")
17 return this.getClient().put(this.route("CLIENT_UPDATE", client.id), client)
18 }
19
20 save(client) {
21 if(client.id) {
22 return this.update(client)
23 }
24 return this.create(client)
25 }
26
27 delete(client) {
28 if (typeof client === "string") {
29 client = { id: client }
30 }
31 if(!client.id) throw new Error("Client id is missing")
32 return this.getClient().delete(this.route("CLIENT_DELETE", client.id))
33 }
34
35 read(client) {
36 const id = client.id ? client.id : client
37 return this.getClient().get(this.route("CLIENT_GET", id))
38 }
39
40 list() {
41 return this.getClient().get(this.route("CLIENT_LIST"))
42 .then((list) => Promise.resolve(require("../pager").create(list)))
43 }
44
45}
46
47module.exports = Client