'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, };