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

112 lines
3.0 KiB

3 years ago
'use strict';
async function overspeedGet (ctx) {
try {
const models = ctx.fs.dc.models;
const { limit, page, nameOfInspectionPoint, licensePlate, numberOfAxles, overrunRateUpper, overrunRateFloor, testTime } = ctx.query
2 years ago
const sequelize = ctx.fs.dc.ORM;
3 years ago
let findOption = {
where: {
},
2 years ago
order: [['id', 'DESC']],
3 years ago
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
2 years ago
if (nameOfInspectionPoint || licensePlate) {
findOption.where['$or'] = {}
if (nameOfInspectionPoint) {
findOption.where['$or'].
nameOfInspectionPoint = { $like: `%${nameOfInspectionPoint}%` }
3 years ago
}
2 years ago
if (licensePlate) {
findOption.where['$or'].
licensePlate = { $like: `%${licensePlate}%` }
3 years ago
}
}
2 years ago
3 years ago
if (numberOfAxles) {
findOption.where.numberOfAxles = numberOfAxles
}
if (overrunRateUpper) {
findOption.where.overrunRate = {
$lte: overrunRateUpper
}
}
if (overrunRateFloor) {
findOption.where.overrunRate = {
$gte: overrunRateFloor
2 years ago
}
3 years ago
}
if (testTime) {
findOption.where.testTime = testTime
}
2 years ago
const overspeedRes = await models.Overspeed.findAndCountAll(findOption)
3 years ago
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,
};