feat: add flow edit
This commit is contained in:
@@ -31,7 +31,9 @@ app
|
||||
key: 'list',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = await PageModel.findAll();
|
||||
ctx.body = await PageModel.findAll({
|
||||
order: [['updatedAt', 'DESC']],
|
||||
});
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
@@ -42,25 +44,65 @@ app
|
||||
key: 'update',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { data, id, ...rest } = ctx.query.data;
|
||||
const { data, id, title, type, description } = ctx.query.data;
|
||||
if (id) {
|
||||
const page = await PageModel.findByPk(id);
|
||||
if (page) {
|
||||
const newPage = await page.update({ data: data, ...rest });
|
||||
const newPage = await page.update({ data: data, title, type, description });
|
||||
ctx.body = newPage;
|
||||
} else {
|
||||
throw new CustomError('page not found');
|
||||
}
|
||||
} else if (data) {
|
||||
const page = await PageModel.create({ data, ...rest });
|
||||
const page = await PageModel.create({ data, title, type, description });
|
||||
ctx.body = page;
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
.route('page', 'updateNode')
|
||||
.define(async (ctx) => {
|
||||
const { id, nodeData } = ctx.query.data;
|
||||
if (!id) {
|
||||
throw new CustomError('id is required');
|
||||
}
|
||||
const page = await PageModel.findByPk(id);
|
||||
if (!page) {
|
||||
throw new CustomError('page not found');
|
||||
}
|
||||
const { data } = page;
|
||||
const { nodes = [] } = data;
|
||||
let flag = false;
|
||||
const newNodes = nodes.map((item) => {
|
||||
if (item.id === nodeData.id) {
|
||||
flag = true;
|
||||
return nodeData;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
if (!flag) {
|
||||
newNodes.push(nodeData);
|
||||
}
|
||||
const newData = { ...data, nodes: newNodes };
|
||||
const newPage = await page.update({ data: newData });
|
||||
ctx.body = newPage;
|
||||
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
.route({
|
||||
path: 'page',
|
||||
key: 'delete',
|
||||
})
|
||||
.define({
|
||||
validator: {
|
||||
id: {
|
||||
required: true,
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const id = ctx.query.id;
|
||||
const page = await PageModel.findByPk(id);
|
||||
|
||||
Reference in New Issue
Block a user