| 17 | import { HandleError } from "./helpers"; |
| 18 | |
| 19 | class UserStore extends EventEmitter { |
| 20 | client: UserServiceClient; |
| 21 | |
| 22 | constructor() { |
| 23 | super(); |
| 24 | this.client = new UserServiceClient(""); |
| 25 | } |
| 26 | |
| 27 | create = (req: CreateUserRequest, callbackFunc: (resp: CreateUserResponse) => void) => { |
| 28 | this.client.create(req, SessionStore.getMetadata(), (err, resp) => { |
| 29 | if (err !== null) { |
| 30 | HandleError(err); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | notification.success({ |
| 35 | message: "User created", |
| 36 | duration: 3, |
| 37 | }); |
| 38 | |
| 39 | callbackFunc(resp); |
| 40 | }); |
| 41 | }; |
| 42 | |
| 43 | get = (req: GetUserRequest, callbackFunc: (resp: GetUserResponse) => void) => { |
| 44 | this.client.get(req, SessionStore.getMetadata(), (err, resp) => { |
| 45 | if (err !== null) { |
| 46 | HandleError(err); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | callbackFunc(resp); |
| 51 | }); |
| 52 | }; |
| 53 | |
| 54 | update = (req: UpdateUserRequest, callbackFunc: () => void) => { |
| 55 | this.client.update(req, SessionStore.getMetadata(), (err, resp) => { |
| 56 | if (err !== null) { |
| 57 | HandleError(err); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | notification.success({ |
| 62 | message: "User updated", |
| 63 | duration: 3, |
| 64 | }); |
| 65 | |
| 66 | callbackFunc(); |
| 67 | }); |
| 68 | }; |
| 69 | |
| 70 | delete = (req: DeleteUserRequest, callbackFunc: () => void) => { |
| 71 | this.client.delete(req, SessionStore.getMetadata(), (err, resp) => { |
| 72 | if (err !== null) { |
| 73 | HandleError(err); |
| 74 | return; |
| 75 | } |
| 76 | |