我有 hapi.js,用 mysql 续集,脚本如下:
method: 'GET',
path: `/${GROUP_NAME}`,
options: {
tags: ['api', GROUP_NAME],
description: 'Mendapatkan jumlah tempat tidur berdasarkan kelas',
notes: 'Mendapatkan jumlah tempat tidur',
handler: async (request, h) => {
return jlhttidurbyjenis.findAll({ attributes: ['VIP','KELAS 1','KELAS 2','KELAS 3','ICU','NICU','PICU','HCU','ICCU','ISOLASI']})
},
validate: {
},
response: {
}
}
当我用邮递员测试时,它的响应如下:
[
{
"VIP": {
"type": "Buffer",
"data": [
50,
47,
50,
50
]
},
"KELAS 1": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"KELAS 2": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"KELAS 3": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"ICU": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"NICU": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"PICU": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"HCU": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"ICCU": {
"type": "Buffer",
"data": [
48,
47,
48
]
},
"ISOLASI": {
"type": "Buffer",
"data": [
48,
47,
48
]
}
}
]
如何修复脚本以使响应与数据库内容相同,它将是这样的:
[
{
"VIP": "12/22",
"KELAS 1": "0/0",
"KELAS 2": "0/0",
"KELAS 3": "0/0",
"ICU": "0/0",
"NICU": "0/0",
"PICU": "0/0",
"HCU": "0/0",
"ICCU": "0/0",
"ISOLASI": "0/0"
}
]