chore: add transaction in set field action (#1647)
This commit is contained in:
parent
b7abdfb9e6
commit
83daf55741
@ -4,28 +4,40 @@ export default {
|
|||||||
async ['collections:setFields'](ctx, next) {
|
async ['collections:setFields'](ctx, next) {
|
||||||
const { filterByTk, values } = ctx.action.params;
|
const { filterByTk, values } = ctx.action.params;
|
||||||
|
|
||||||
// WARN: 删掉 key 才能保存
|
const transaction = await ctx.app.db.sequelize.transaction();
|
||||||
const fields = values.fields?.map(f => {
|
|
||||||
delete f.key;
|
|
||||||
return f;
|
|
||||||
});
|
|
||||||
|
|
||||||
const db = ctx.app.db as Database;
|
try {
|
||||||
|
const fields = values.fields?.map((f) => {
|
||||||
|
delete f.key;
|
||||||
|
return f;
|
||||||
|
});
|
||||||
|
|
||||||
const collection = await db.getRepository('collections').findOne({
|
const db = ctx.app.db as Database;
|
||||||
filter: {
|
|
||||||
name: filterByTk,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await db.getRepository('collections').update({
|
const collection = await db.getRepository('collections').findOne({
|
||||||
filterByTk,
|
filter: {
|
||||||
values: {
|
name: filterByTk,
|
||||||
fields,
|
},
|
||||||
},
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
await collection.loadFields();
|
await db.getRepository('collections').update({
|
||||||
|
filterByTk,
|
||||||
|
values: {
|
||||||
|
fields,
|
||||||
|
},
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await collection.loadFields({
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (e) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user