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

109 lines
2.8 KiB

'use strict';
async function overspeedGet (ctx) {
try {
const models = ctx.fs.dc.models;
const { limit, page, nameOfInspectionPoint, licensePlate, numberOfAxles, overrunRateUpper, overrunRateFloor, testTime } = ctx.query
let findOption = {
where: {
},
order: [['id', 'DESC']]
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
if (nameOfInspectionPoint) {
findOption.where.nameOfInspectionPoint = {
'$like': `%${nameOfInspectionPoint}%`
}
}
if (licensePlate) {
findOption.where.licensePlate = {
'$like': `%${licensePlate}%`
}
}
if (numberOfAxles) {
findOption.where.numberOfAxles = numberOfAxles
}
if (overrunRateUpper) {
findOption.where.overrunRate = {
$lte: overrunRateUpper
}
}
if (overrunRateFloor) {
findOption.where.overrunRate = {
$gte: overrunRateFloor
}
}
if (testTime) {
findOption.where.testTime = testTime
}
const overspeedRes = await models.Overspeed.findAll(findOption)
ctx.status = 200;
ctx.body = overspeedRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function overspeedEdit (ctx) {
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
if (!data.overspeedId) {
await models.Overspeed.create(data)
} else {
await models.Overspeed.update(
data,
{
where: {
id: data.overspeedId
}
})
}
ctx.status = 204
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function overspeedDel (ctx) {
try {
const models = ctx.fs.dc.models;
const { overspeedId } = ctx.params;
await models.Overspeed.destroy({
where: {
id: overspeedId
}
})
ctx.status = 204
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
overspeedGet, overspeedEdit, overspeedDel,
};