四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
1.4 KiB

'use strict';
async function busCarLevelList (ctx) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api;
let data = []
const busCarRes = await models.BusCar.findAll({
attributes: ['id', 'company', 'fleet', 'vehicleLicensePlateNumber'],
})
for (let c of busCarRes) {
const { company, fleet } = c
const corCompany = data.find(d => d.name === company)
if (!corCompany) {
data.push({
name: company,
child: [{
name: fleet,
child: [{ ...c.dataValues }]
}]
})
} else {
const corFleet = corCompany.child.find(d => d.name === fleet)
if (!corFleet) {
corCompany.child.push({
name: fleet,
child: [{ ...c.dataValues }]
})
} else {
corFleet.child.push({ ...c.dataValues })
}
}
}
ctx.status = 200
ctx.body = data
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
busCarLevelList
};