CHECKAPPVERISON : AADHAVAN
This commit is contained in:
parent
a0879a8e32
commit
7fd60ed4aa
@ -1,48 +1,64 @@
|
||||
const { MacModel } = require('../models')
|
||||
const {logMsg} = require('../services/logger')
|
||||
const secretKeyJwt = process.env.SECRETKEY;
|
||||
const { info } = require('winston');
|
||||
const { info, log } = require('winston');
|
||||
const moment = require('moment');
|
||||
|
||||
|
||||
|
||||
module.exports.addMacValue= async(req, res, next)=>{
|
||||
try {
|
||||
const today = moment().format('YYYY/MM/DD');
|
||||
const today = new Date();
|
||||
const one_year = moment().add(1, 'year');
|
||||
const nextFiscalYearEndDate = one_year.format('YYYY/MM/DD');
|
||||
|
||||
const mac =await MacModel.findOne({where:{licency_key:req.body.key}});
|
||||
console.log(mac);
|
||||
if (mac.dataValues.licency_key == req.body.key) {
|
||||
if (mac.dataValues.isActive == false) {
|
||||
const {key, mac_id, mail, company_name, app_version} = req.body
|
||||
|
||||
const mac =await MacModel.findOne({where:{licency_key: key},raw:true});
|
||||
|
||||
//Check License Key IN DB
|
||||
if (mac.licency_key == key) {
|
||||
//Check isActive and App Version are Same
|
||||
if (mac.isActive == false && mac.app_version == app_version) {
|
||||
|
||||
const info={
|
||||
licency_key:req.body.key,
|
||||
mac_id: JSON.stringify(req.body.mac_id),
|
||||
mail: req.body.mail,
|
||||
company_name:req.body.company_name,
|
||||
licency_key:key,
|
||||
mac_id: JSON.stringify(mac_id),
|
||||
mail: mail,
|
||||
company_name: company_name,
|
||||
isActive:true,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
}
|
||||
const macUpdate = await MacModel.update(info, {where:{id: mac.dataValues.id}});
|
||||
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
|
||||
console.log("Update ");
|
||||
console.log(macUpdate);
|
||||
if (macUpdate) {
|
||||
logMsg.info({status:200,message:"Update Success!", data: info});
|
||||
res.send({status:200,message:" Update Success!", data: info})
|
||||
}
|
||||
} else {
|
||||
|
||||
var expiryDate = new Date(mac.expiry_date);
|
||||
|
||||
const info={
|
||||
licency_key:req.body.key,
|
||||
mail: req.body.mail,
|
||||
company_name:req.body.company_name,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
//Check expired or not!
|
||||
if (expiryDate > new Date()) {
|
||||
const info={
|
||||
licency_key: key,
|
||||
mail: mail,
|
||||
company_name: company_name,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
}
|
||||
logMsg.info({status:404,message:" Your Mac is Already Activated!", data: info});
|
||||
res.send({status:404,message:" Your Mac is Already Activated!", data: info});
|
||||
|
||||
} else {
|
||||
logMsg.info({status:404,message:" Product Expired!", data: "No Data!"});
|
||||
res.send({status:404,message:" Product Expired!", data: "No Data!"});
|
||||
}
|
||||
logMsg.info({status:200,message:" Your Mac is Already Activated!", data: info});
|
||||
res.send({status:200,message:" Your Mac is Already Activated!", data: info});
|
||||
|
||||
|
||||
// const macId = JSON.parse(mac.mac_id);
|
||||
// var DBData= [];
|
||||
// macId.forEach(function(macid) {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize');
|
||||
const { columns } = require('mssql');
|
||||
const { Model, TEXT } = require('sequelize');
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
|
||||
class MacModel extends Model {
|
||||
}
|
||||
|
||||
MacModel.init(
|
||||
{
|
||||
licency_key: {type: DataTypes.STRING},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user