Total Complexity | 9 |
Complexity/F | 2.25 |
Lines of Code | 60 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | const ModelDesk = require('../../model/catering/desk') |
||
2 | const ApiError = require('../../util/api_error') |
||
3 | const Validate = require('request-validate') |
||
4 | const _ = require('underscore') |
||
5 | |||
6 | module.exports = { |
||
7 | list: async function (storeId) { |
||
8 | let result = await ModelDesk.list(storeId) |
||
9 | return result |
||
10 | }, |
||
11 | |||
12 | detail: async function (storeId, id) { |
||
13 | let result = await ModelDesk.first(id) |
||
14 | if (_.isEmpty(result)) { |
||
15 | throw new ApiError('common.notExist', 'desk') |
||
16 | } |
||
17 | |||
18 | if (result.store_id != storeId) { |
||
19 | throw new ApiError('common.notExist', 'desk') |
||
20 | } |
||
21 | |||
22 | if (result.status == -1) { |
||
23 | throw new ApiError('common.notExist', 'desk') |
||
24 | } |
||
25 | |||
26 | return result |
||
27 | }, |
||
28 | |||
29 | add: async function (storeId, data) { |
||
30 | Validate(data, { |
||
31 | name: 'required', |
||
32 | }) |
||
33 | let insertData = { |
||
34 | store_id: storeId, |
||
35 | name: data.name |
||
36 | } |
||
37 | let insertResult = await ModelDesk.add(insertData) |
||
38 | insertData.id = insertResult.insertId |
||
39 | |||
40 | return insertData |
||
41 | }, |
||
42 | |||
43 | edit: async function (storeId, id, data) { |
||
44 | let detail = await this.detail(storeId, id) |
||
45 | |||
46 | let where = { |
||
47 | id: id |
||
48 | } |
||
49 | |||
50 | let updateData = { |
||
51 | name: _.has(data, 'name') ? data.name : detail.name, |
||
52 | status: _.has(data, 'status') ? data.status : detail.status |
||
53 | } |
||
54 | |||
55 | let editResult = await ModelDesk.edit(updateData, where) |
||
|
|||
56 | |||
57 | return updateData |
||
58 | }, |
||
59 | |||
60 | } |
||
61 |