const SyncEngine = require('../../util/sync-engine'); module.exports = Self => { Self.remoteMethod('syncAll', { description: 'Synchronizes user database with LDAP and Samba', http: { path: `/syncAll`, verb: 'PATCH' } }); Self.syncAll = async function() { let $ = Self.app.models; let engine = new SyncEngine(); await engine.init($); let usersToSync = await engine.getUsers(); usersToSync = Array.from(usersToSync.values()) .sort((a, b) => a.localeCompare(b)); for (let user of usersToSync) { try { console.log(`Synchronizing user '${user}'`); await engine.sync(user); console.log(` -> '${user}' sinchronized`); } catch (err) { console.error(` -> '${user}' synchronization error:`, err.message); } } await engine.deinit(); await $.RoleInherit.sync(); }; };