feat handleUser refs #6868
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Sergio De la torre 2024-07-16 17:08:38 +02:00
parent 144cf20e71
commit 7870416860
1 changed files with 14 additions and 8 deletions

View File

@ -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({