Passed
Push — master ( 1adf40...f067da )
by lv
01:05
created

app/services/catering/seller.js   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 35
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 5
eloc 24
c 2
b 0
f 0
nc 2
mnd 1
bc 3
fnc 2
dl 0
loc 35
rs 10
bpm 1.5
cpm 2.5
noi 4

1 Function

Rating   Name   Duplication   Size   Complexity  
A module.exports.storeList 0 25 2
1
const ModelStore = require('../../model/catering/store')
2
const ServiceCustomer = require('../../services/catering/customer')
3
const ApiError = require('../../util/api_error')
0 ignored issues
show
Unused Code introduced by
The constant ApiError seems to be never used. Consider removing it.
Loading history...
4
const Validate = require('request-validate')
0 ignored issues
show
Unused Code introduced by
The constant Validate seems to be never used. Consider removing it.
Loading history...
5
const _ = require('underscore')
0 ignored issues
show
Unused Code introduced by
The constant _ seems to be never used. Consider removing it.
Loading history...
6
const ConfigOss = require('../../../config/oss')
7
8
module.exports = {
9
    storeList: async function (sellerId) {
10
        let result = await ModelStore.getSellerStores(sellerId)
11
        
12
        // 默认开店
13
        if (result.length <= 0) {
14
            let customerInfo = await ServiceCustomer.getCustomerInfo(sellerId)
15
            let storeInfo = {
16
                seller_id: customerInfo.id,
17
                name: customerInfo.nickname,
18
                thumb: customerInfo.avatar,
19
                store_type_id: 0, theme: '', tel: '', wechat: '', license: '', address: '', 
20
                approve_status: 0, status: 1, audit_id: 0
21
            }
22
            let storeRes = await ModelStore.add(storeInfo)
23
            storeInfo.id = storeRes.insertId
24
            result = [storeInfo]
25
        }
26
27
        result.forEach(element => {
28
            element.preview_thumb = ''
29
            if (element.thumb && element.thumb.indexOf('http') < 0) element.preview_thumb = ConfigOss.catering.view_server + element.thumb + '?x-oss-process=style/preview'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
        })
31
32
        return result
33
    },
34
35
}
36