UNPKG

yekonga-server

Version:
65 lines (47 loc) 1.97 kB
// @ts-nocheck /*global Yekonga, serverLibrary */ const moment = serverLibrary.moment; class DataSync { static async setSync(collection, key, id, tag, auth) { let current_time = moment().format('YYYY-MM-DD HH:mm:ss'); var license = await Yekonga.DB.table('account_licenses') .where('account_id', auth.account_id) .findOne(); var body = { reference_id: id, reference_key: key, reference_collection: collection, device_id: (license) ? license.device_id : null, user_id: auth.user_id, is_synchronizing: 0, last_synchronize: null, tag: tag, timestamp: current_time }; Yekonga.DB.table('synchronizations').create(body); return { 'status': 'done' }; } static async setAllData(data) { if (Array.isArray(data.account_group_users_list) && data.account_group_users_list.length) { await Yekonga.DB.table('account_group_users').create(data.account_group_users_list); } if (Array.isArray(data.account_groups_list) && data.account_groups_list.length) { await Yekonga.DB.table('account_groups').create(data.account_groups_list); } return { 'status': 'done' }; } static async getAllData(req, res) { var data = {} var license = (req.body) ? req.body : {}; var license_key = (license && license.license_key) ? license.license_key : null; var account_id = await Yekonga.DB.table('license_key').where('license_key', license_key).pluck('account_id'); data['account_group_users_list'] = await Yekonga.DB.table('account_group_users').find(); data['account_groups_list'] = await Yekonga.DB.table('account_groups').where('account_id', account_id).find(); return res.json(data); } } module.exports = DataSync;