Commit 39cc6d1c authored by wuhao's avatar wuhao 🎯

asdl

parent 6346bb2c
......@@ -40,7 +40,29 @@ class ItemController extends Controller {
this.fail('请完善必填项!');
return;
}
const item = await ctx.model.Item.create(ctx.request.body);
const tags = ctx.request.body.tags
?.filter(it => isNaN(it))
.map(it => {
return {
tag_name: it,
project_id: ctx.request.body.project_id,
color: '#cccccc',
};
});
const idtags = await ctx.model.Tag.findAll({
where: {
id: ctx.request.body.tags?.filter(it => !isNaN(it)),
},
});
const mutiadder = await ctx.service.tag.muticreate(tags);
const tages = [
mutiadder?.map(it => it?.dataValues),
idtags.map(it => it?.dataValues),
].flat();
const item = await ctx.model.Item.create({
...ctx.request.body,
tags: tages,
});
// const tags = await ctx.model.service.tags
this.success(item);
}
......
......@@ -21,6 +21,17 @@ class TagService extends Service {
return tag;
}
async muticreate(tagarr) {
const { ctx } = this;
let tag;
try {
tag = await ctx.model.Tag.bulkCreate(tagarr);
} catch (error) {
tag = error;
}
return tag;
}
async getbyproject_id(project_id, status) {
const { ctx } = this;
const where =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment