8062-testToMaster_2 #3059

Merged
alexm merged 293 commits from 8062-testToMaster_2 into master 2024-10-03 05:43:41 +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 UserError = require('vn-loopback/util/user-error');
const {setLocale} = require('i18n');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('loginApp', { Self.remoteMethodCtx('loginApp', {
@ -53,20 +52,55 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); 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 userId = ctx.req.accessToken.userId;
const isUserInOperator = await models.Operator.findById(userId); const resultCheckLogin =
if (!isUserInOperator) 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 }); 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({ const resultDevice = await models.DeviceProduction.findOne({
// where: {id: '100'} 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( // const insertDeviceLog = await models.DeviceLog.create(
// { // {
// 'android_id': android_id, // 'android_id': android_id,