#6274 workerTimeControl #1858
|
@ -26,12 +26,19 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.sync = async function(userName, password, force, options) {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const models = Self.app.models;
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
};
|
||||
|
||||
try {
|
||||
const user = await models.VnUser.findOne({
|
||||
fields: ['id', 'password'],
|
||||
where: {name: userName}
|
||||
|
@ -42,8 +49,23 @@ module.exports = Self => {
|
|||
|
||||
const isSync = !await models.UserSync.exists(userName, myOptions);
|
||||
|
||||
if (!force && isSync && user) return;
|
||||
if (!force && isSync && user) {
|
||||
if (tx) await tx.rollback();
|
||||
return;
|
||||
}
|
||||
|
||||
await Self.rawSql(`
|
||||
SELECT id
|
||||
FROM account.user
|
||||
WHERE id = ?
|
||||
FOR UPDATE`, [user.id], myOptions);
|
||||
|
||||
await models.AccountConfig.syncUser(userName, password);
|
||||
await models.UserSync.destroyById(userName, myOptions);
|
||||
if (tx) await tx.commit();
|
||||
} catch (err) {
|
||||
if (tx) await tx.rollback();
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue