diff --git a/modules/account/back/methods/account/handle-user.js b/modules/account/back/methods/account/handle-user.js index 136ce4800..02b505e39 100644 --- a/modules/account/back/methods/account/handle-user.js +++ b/modules/account/back/methods/account/handle-user.js @@ -9,7 +9,13 @@ module.exports = Self => { arg: 'androidId', type: 'String', description: 'Android id' - }, { + }, + { + arg: 'deviceId', + type: 'String', + description: 'Device id' + }, + { arg: 'versionApp', type: 'String', description: 'Version app' @@ -30,9 +36,10 @@ module.exports = Self => { } }); - Self.handleUser = async(ctx, android_id, versionApp, nameApp, options) => { + Self.handleUser = async(ctx, androidId, deviceId, versionApp, nameApp, options) => { const models = Self.app.models; const myOptions = {}; + if (typeof options == 'object') Object.assign(myOptions, options); @@ -41,7 +48,7 @@ module.exports = Self => { const [[{vIsAuthorized, vMessage}]] = await Self.rawSql('CALL vn.device_checkLogin(?, ?);', - [user.id, android_id], myOptions); + [user.id, androidId], myOptions); if (!vIsAuthorized) throw new UserError('Not authorized'); @@ -55,18 +62,17 @@ module.exports = Self => { if (!isUserInOperator) await models.Operator.create({'workerFk': user.id}); - const serialNumber = (await models.DeviceProduction.findOne({ - where: {android_id: android_id} - }, myOptions))?.serialNumber ?? ''; + const whereCondition = deviceId ? {id: deviceId} : {android_id: androidId}; + const serialNumber = + (await models.DeviceProduction.findOne({where: whereCondition}, myOptions))?.serialNumber ?? ''; await models.DeviceLog.create({ - 'android_id': android_id, + 'android_id': androidId, 'userFk': user.id, 'nameApp': nameApp, 'versionApp': versionApp, 'serialNumber': serialNumber }, myOptions); - // ctx.req.accessToken = {userId}; const getDataUser = await models.VnUser.getCurrentUserData(ctx); const getDataOperator = await models.Operator.findOne({