6868_createLogin #2598

Merged
sergiodt merged 20 commits from 6868_createLogin into dev 2024-09-13 09:43:32 +00:00
1 changed files with 29 additions and 25 deletions
Showing only changes of commit 5c3ce40bbd - Show all commits

View File

@ -49,40 +49,44 @@ module.exports = Self => {
Self.loginApp = async(ctx, user, password, deviceId, android_id, versionApp, nameApp, options) => { Self.loginApp = async(ctx, user, password, deviceId, android_id, versionApp, nameApp, options) => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const login = await Self.app.models.VnUser.signIn(ctx, user, password, options); await models.Account.login(ctx, user, password, myOptions);
const userId = login.user; const userId = ctx.req.accessToken.userId;
const query = const isUserInOperator = await models.Operator.findById(userId);
`INSERT IGNORE INTO operator (workerFk) if (!isUserInOperator)
VALUES (?);`; await models.Operator.create({'workerFk': userId});
const insertOperator = await Self.rawSql(query, [userId], options); const device = await models.DeviceProduction.findById(deviceId);
const [serialNumber] = await models.DeviceProductionUser.findOne({ // const [serialNumber] = await models.DeviceProductionUser.findOne({
where: {id: '100'} // where: {id: '100'}
}); // });
const insertDeviceLog = await models.DeviceLog.create( // const insertDeviceLog = await models.DeviceLog.create(
{ // {
'android_id': android_id, // 'android_id': android_id,
'userFk': userId, // 'userFk': userId,
'versionApp': versionApp, // 'versionApp': versionApp,
'nameApp': nameApp, // 'nameApp': nameApp,
'serialNumber': [serialNumber] // 'serialNumber': [serialNumber]
}, // },
options // options
); // );
const queryDeviceCheck = // const queryDeviceCheck =
`CALL device_checkLogin(?, ?)`; // `CALL device_checkLogin(?, ?)`;
const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options); // const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options);
if (!queryDeviceCheckLogin.vIsAuthorized) // if (!queryDeviceCheckLogin.vIsAuthorized)
throw new UserError('User not authorized'); // throw new UserError('User not authorized');
return insertDeviceLog; // return insertDeviceLog;
return [];
}; };
}; };