This commit is contained in:
parent
9f6d034f9c
commit
0dbb77fc64
|
@ -25,7 +25,9 @@ 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);
|
||||
|
@ -35,16 +37,23 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
};
|
||||
|
||||
const models = Self.app.models;
|
||||
try {
|
||||
const user = await models.VnUser.findOne({
|
||||
fields: ['id'],
|
||||
where: {name: userName}
|
||||
}, myOptions);
|
||||
const isSync = !await models.UserSync.exists(userName, myOptions);
|
||||
|
||||
if (!force && isSync && user) return;
|
||||
if (!force && isSync && user) {
|
||||
if (tx) await tx.rollback();
|
||||
return;
|
||||
}
|
||||
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