function success(e, msg, data, code) {
    return e.json(code || 200, {
        code: code || 200,
        msg: msg || '操作成功',
        data: data || {},
    })
}

function successWithToken(e, msg, data, token, code) {
    const statusCode = code || 200
    const payload = {
        code: statusCode,
        msg: msg || '操作成功',
        data: data || {},
    }

    if (token) {
        payload.token = token
    }

    return e.json(statusCode, payload)
}

module.exports = {
    success,
    successWithToken,
}
