四好公路
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.

50 lines
1.3 KiB

3 years ago
'use strict';
async function statistic (ctx) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api;
const { projectType } = ctx.query;
let findOption = {
where: {
reportType: 'conserve',
},
attributes: ['id', 'road', 'time', 'projectType', 'projectType'],
include: [{
model: models.User,
attributes: ['name']
}],
}
if (projectType) {
findOption.where.projectType = projectType;
}
const reportRes = await await models.Report.findAll(findOption)
3 years ago
const reportCount = await models.Report.count({
attributes: ['projectType'],
group: ['projectType'],
where: {
reportType: 'conserve',
},
})
3 years ago
ctx.status = 200
ctx.body = {
processed: reportRes.length,
3 years ago
reportCount: reportCount,
3 years ago
reportList: reportRes,
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
statistic,
};