app/services/catering/desk.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 2.25

Size

Lines of Code 60
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 9
eloc 35
c 0
b 0
f 0
nc 4
mnd 1
bc 7
fnc 4
dl 0
loc 60
rs 10
bpm 1.75
cpm 2.25
noi 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A module.exports.add 0 13 1
A module.exports.list 0 4 1
A module.exports.edit 0 16 3
A module.exports.detail 0 16 4
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)
0 ignored issues
show
Unused Code introduced by
The variable editResult seems to be never used. Consider removing it.
Loading history...
56
57
        return updateData
58
    },
59
60
}
61