8062-testToMaster_2 #3059
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue