module.exports = Self => { Self.remoteMethod('sync', { description: 'Synchronizes the user with the other user databases', accepts: [ { arg: 'userName', type: 'string', description: 'The user name', required: true }, { arg: 'password', type: 'string', description: 'The password' }, { arg: 'force', type: 'boolean', description: 'Whether to force synchronization' } ], http: { path: `/:userName/sync`, verb: 'PATCH' } }); Self.sync = async function(userName, password, force) { const models = Self.app.models; const user = await models.VnUser.findOne({ fields: ['id'], where: {name: userName} }); const isSync = !await models.UserSync.exists(userName); if (!force && isSync && user) return; await models.AccountConfig.syncUser(userName, password); await models.UserSync.destroyById(userName); }; };