This commit is contained in:
parent
9668468f94
commit
9f92bc4b4c
|
@ -40,17 +40,10 @@ module.exports = Self => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const user = await Self.findById(userId, {fields: ['hasGrant']}, myOptions);
|
const user = await Self.findById(userId, {fields: ['hasGrant']}, myOptions);
|
||||||
|
|
||||||
const userToUpdate = await Self.findById(id, {
|
const userToUpdate = await Self.findById(id, {
|
||||||
|
@ -84,12 +77,7 @@ module.exports = Self => {
|
||||||
userToUpdate.roleFk = roleFk;
|
userToUpdate.roleFk = roleFk;
|
||||||
}
|
}
|
||||||
|
|
||||||
await userToUpdate.save(myOptions);
|
await userToUpdate.save(userToUpdate);
|
||||||
await models.Account.sync(userToUpdate.name, null, null, myOptions);
|
await models.Account.sync(userToUpdate.name);
|
||||||
if (tx) await tx.commit();
|
|
||||||
} catch (err) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw err;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue