|
|
@ -7,31 +7,27 @@ async function getTask(ctx) { |
|
|
|
const whereopt = { |
|
|
|
isdanger: query.isdanger |
|
|
|
} |
|
|
|
console.log('whereopt', whereopt) |
|
|
|
const whereRoadOpt = { |
|
|
|
id: query.id |
|
|
|
} |
|
|
|
console.log('wherwhereRoadOpteopt', whereRoadOpt) |
|
|
|
|
|
|
|
const taskRes = await models.TaskManage.findAndCountAll({ |
|
|
|
order: [['id', 'DESC']], |
|
|
|
attributes: ['id', 'dangerDescription', 'isdanger', 'issuanceTime', 'reportTime'], |
|
|
|
include: [ |
|
|
|
{ |
|
|
|
attributes: ['routeName', 'routeCode'], |
|
|
|
attributes: ['id', 'routeName', 'routeCode'], |
|
|
|
model: models.Road, |
|
|
|
where: query.id == undefined ? {} : whereRoadOpt |
|
|
|
|
|
|
|
}, |
|
|
|
{ |
|
|
|
attributes: ['name'], |
|
|
|
attributes: ['id', 'name'], |
|
|
|
model: models.User |
|
|
|
} |
|
|
|
], |
|
|
|
where: query.isdanger == undefined ? {} : whereopt |
|
|
|
}) |
|
|
|
ctx.body = taskRes |
|
|
|
console.log('tas', taskRes) |
|
|
|
ctx.status = 200 |
|
|
|
} |
|
|
|
catch (error) { |
|
|
@ -48,7 +44,6 @@ async function delTask(ctx) { |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models |
|
|
|
const { id } = ctx.params |
|
|
|
console.log('params', id) |
|
|
|
await models.TaskManage.destroy({ where: { id: id } }) |
|
|
|
ctx.status = 204 |
|
|
|
} catch (error) { |
|
|
@ -66,23 +61,18 @@ async function editTask(ctx) { |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models |
|
|
|
const params = ctx.request.body |
|
|
|
const road = await models.Road.findOne({ where: { id: params.routeId } }) |
|
|
|
const user = await models.User.findOne({ where: { id: params.userId } }) |
|
|
|
if (!params.id) { |
|
|
|
|
|
|
|
const road = await models.Road.findOne({ where: { routeCode: params.routeCode } }) |
|
|
|
const user = await models.User.findOne({ where: { name: params.name } }) |
|
|
|
console.log('params', road.id, user.id) |
|
|
|
await models.TaskManage.create({ |
|
|
|
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim() |
|
|
|
}) |
|
|
|
} else { |
|
|
|
const road = await models.Road.findOne({ where: { routeCode: params.routeCode } }) |
|
|
|
const user = await models.User.findOne({ where: { name: params.name } }) |
|
|
|
await models.TaskManage.update({ |
|
|
|
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim() |
|
|
|
}, { where: { id: params.id } }) |
|
|
|
} |
|
|
|
ctx.status = 204 |
|
|
|
//await transaction.commit();
|
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|