У меня есть таблица с именем user_feedbacks,
Для типа у нас есть 4 значения по умолчанию - 1-Предложение, 2 -Запрос, отчет о 3-х повреждениях, 4-инцидент
Для статуса у нас есть 3 значения по умолчанию - 0-открытый, 1-в процессе, 2-закрытый
I хотите показать под каждым типом для каждого статуса, количество записей, как показано ниже [Обязательный вывод] ,
{
"status": "success",
"code": 200,
"data": {
"1"(Type): {
"0" (status): 20, (total)
"1": 19,
"2": 28
},
"2": {
"0": 20,
"1": 19,
"2": 28
},
"3": {
"0": 20,
"1": 19,
"2": 28
},
"4": {
"0": 20,
"1": 19,
"2": 28
}
}
}
Ниже мой код,
В обратная связь. js
static async getFeedbackStats(opts) {
assert.object(opts, 'opts')
assert.func(opts.mysql_db, 'opts.mysql_db')
const { mysql_db } = opts
const result = mysql_db.select('type', 'status', mysql_db.raw('count(status)'))
.from('user_feedbacks')
.groupBy('status', 'type')
return result
}
В обработчике. js
const assert = require('assert-plus')
const Utils = require('../common/repos/feedbacks')
const Auth = require('../common/auth')
const Logger = require('../common/debug_logger')
async function handler(event, ctx, opts) {
Logger.info('Feedback stats handler has been invoked: %j', event)
const auth = await Auth.authenticate(event)
if (!auth.success){
return { status : 'failed', code : 401}
}
assert('params' in auth, 'auth.params')
assert('auth_ctx' in auth, 'auth.auth_ctx')
assert('user_id' in auth.auth_ctx, 'auth.auth_ctx.user_id')
Logger.info('Feedback stats handler Auth.Params: %j', auth.params)
const result = await Utils.getFeedbackStats(opts)
return { status: 'success', code: 200, data: result }
}
module.exports = { handler }
Выше кода возврата ниже выхода [Output i return ] ,
{
"status":"success",
"code":200,
"data":[
{
"type":1,
"status":0,
"count(status)":2
},
{
"type":2,
"status":0,
"count(status)":1
},
{
"type":1,
"status":1,
"count(status)":1
},
{
"type":1,
"status":2,
"count(status)":1
}
]
}
Кто-нибудь может помочь мне получить этот вывод, как я упоминал выше?