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.
92 lines
2.2 KiB
92 lines
2.2 KiB
'use strict';
|
|
|
|
async function projectGet (ctx) {
|
|
try {
|
|
const models = ctx.fs.dc.models;
|
|
const { type, entryName, doneState } = ctx.query;
|
|
|
|
let findOption = {
|
|
where: {
|
|
|
|
},
|
|
order: [['id', 'DESC']]
|
|
}
|
|
if (type) {
|
|
findOption.where.type = type
|
|
}
|
|
if (entryName) {
|
|
findOption.where.entryName = {
|
|
$like: `%${entryName}%`
|
|
}
|
|
}
|
|
if (doneState) {
|
|
if (doneState == 'true') {
|
|
findOption.where.done = true
|
|
} else if (doneState == 'false') {
|
|
findOption.where.done = false
|
|
}
|
|
}
|
|
|
|
const projectRes = await models.Project.findAll(findOption)
|
|
|
|
ctx.status = 200;
|
|
ctx.body = projectRes
|
|
} catch (error) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error == 'string' ? error : undefined
|
|
}
|
|
}
|
|
}
|
|
|
|
async function projectEdit (ctx) {
|
|
try {
|
|
const models = ctx.fs.dc.models;
|
|
const data = ctx.request.body;
|
|
|
|
if (!data.projectId) {
|
|
await models.Project.create(data)
|
|
} else {
|
|
await models.Project.update(
|
|
data, {
|
|
where: {
|
|
id: data.projectId
|
|
}
|
|
})
|
|
}
|
|
|
|
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 projectDel (ctx) {
|
|
try {
|
|
const models = ctx.fs.dc.models;
|
|
const { projectId } = ctx.params;
|
|
|
|
await models.Project.destroy({
|
|
where: {
|
|
id: projectId
|
|
}
|
|
})
|
|
|
|
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 = {
|
|
projectGet, projectEdit, projectDel,
|
|
};
|