8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +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(?, ?);',
await models.Operator.create({'workerFk': userId}); [userId, android_id], myOptions);
const device = await models.DeviceProduction.findById(deviceId); const [{vIsAuthorized, vMessage}] = resultCheckLogin[0];
// const [serialNumber] = await models.DeviceProductionUser.findOne({ if (!vIsAuthorized)
// where: {id: '100'} throw new UserError('Not authorized');
// });
const isUserInOperator = await models.Operator.findOne({
where: {
workerFk: userId
}
});
if (!isUserInOperator){
await models.Operator.create({ 'workerFk': userId });
const getDataUser = await models.Operator.findOne({
where: {
workerFk: userId
}
});
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( // const insertDeviceLog = await models.DeviceLog.create(
// { // {
// 'android_id': android_id, // 'android_id': android_id,