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 44 additions and 10 deletions
Showing only changes of commit 52b82603d2 - Show all commits

View File

@ -1,5 +1,4 @@
const {setDefaultHighWaterMark} = require('form-data');
const {setLocale} = require('i18n');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('loginApp', {
@ -53,20 +52,55 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
await models.Account.login(ctx, user, password, myOptions);
const login = await models.Account.login(ctx, user, password, myOptions);
const userId = ctx.req.accessToken.userId;
const isUserInOperator = await models.Operator.findById(userId);
if (!isUserInOperator)
const resultCheckLogin =
await Self.rawSql('CALL vn.device_checkLogin(?, ?);',
[userId, android_id], myOptions);
const [{vIsAuthorized, vMessage}] = resultCheckLogin[0];
if (!vIsAuthorized)
throw new UserError('Not authorized');
const isUserInOperator = await models.Operator.findOne({
where: {
workerFk: userId
}
});
if (!isUserInOperator){
await models.Operator.create({ 'workerFk': userId });
const device = await models.DeviceProduction.findById(deviceId);
const getDataUser = await models.Operator.findOne({
where: {
workerFk: userId
}
});
// const [serialNumber] = await models.DeviceProductionUser.findOne({
// where: {id: '100'}
// });
const resultDevice = await models.DeviceProduction.findOne({
where: {
android_id: android_id
}
});
if (resultDevice)
serialNumber = resultDevice.serialNumber ?? '';
await models.DeviceLog.create({
'android_id': android_id,
'userFk': userId,
'nameApp': nameApp,
'versionApp': versionApp,
'serialNumber': serialNumber
});
console.log(vIsAuthorized);
console.log(vMessage);
// const insertDeviceLog = await models.DeviceLog.create(
// {
// 'android_id': android_id,