4179 lines
111 KiB
JavaScript
4179 lines
111 KiB
JavaScript
const express = require('express');
|
|
var bodyparser = require('body-parser');
|
|
var Razorpay = require('razorpay');
|
|
var async = require('async');
|
|
var models = require('../models');
|
|
var multer = require('multer');
|
|
var sequelize = require('sequelize');
|
|
const {hashGenerate}=require('../helper/hashing');
|
|
const {hashValidator}= require('../helper/hashing');
|
|
const {authVerify}=require('../helper/authverify');
|
|
const {tokenGenerator}=require('../helper/token');
|
|
const http = require("http");
|
|
const { sign } = require('jsonwebtoken');
|
|
const QRCode = require("qrcode");
|
|
const crypto=require('crypto');
|
|
const FCM = require('fcm-node');
|
|
var base64 = require('base-64');
|
|
var assert = require('assert');
|
|
const {validateWebhookSignature} = require('razorpay/dist/utils/razorpay-utils')
|
|
//const admin = require('../config/firebase-config');
|
|
|
|
const { checkToken } = require('../auth/token_validation');
|
|
var app = express();
|
|
app.use(bodyparser.json());
|
|
var cors = require('cors');
|
|
|
|
app.use(express.static('public'));
|
|
app.use('/uploads', express.static('uploads'));
|
|
|
|
app.use(cors()) ;
|
|
|
|
app.get('/',async(req,res)=>
|
|
{
|
|
res.send("Welcome to Medcifys");
|
|
});
|
|
|
|
|
|
///// Start Push Notification
|
|
function notifyme(tokenId,title,body)
|
|
{
|
|
var serverKey = 'AAAAMPRIRf8:APA91bE75N3ncIfHOmypWgtATGIl1tb7GcjPWGt_HB7q-cIDPCUR5l3_m5bA5O5OHb5prJleFCRn6-7UEUAttGfc0HRCbXrOg3dbZtxsKoGZYIPaEB39H93FYrcbzOMr3F1MsMxdXRS5'; //put your server key here
|
|
const tokenId=tokenId
|
|
var fcm = new FCM(serverKey);
|
|
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
|
|
to: tokenId,
|
|
notification: {
|
|
title:title,
|
|
body: body
|
|
},
|
|
data: { //you can send only notification or only data(or include both)
|
|
my_key: 'my value',
|
|
my_another_key: 'my another value'
|
|
}
|
|
}
|
|
|
|
fcm.send(message, function(err, response){
|
|
if (err) {
|
|
console.log(err)
|
|
} else {
|
|
console.log("Successfully sent with response: ", response)
|
|
}
|
|
})
|
|
}
|
|
///// End Push Notification */
|
|
|
|
///Start Webhook
|
|
|
|
|
|
|
|
//POST SUBSCRIPTION ADD
|
|
app.post('/addSubscription',authVerify,async(req,res)=>{
|
|
var enddate=new Date(new Date().getTime()+(req.body.validity*24*60*60*1000));
|
|
|
|
var billStart=Date.now();
|
|
var startNo=req.body.id;
|
|
var Medicify="MED";
|
|
var billNumber=Medicify+billStart+startNo;
|
|
const data=
|
|
{
|
|
storeId:req.body.storeId,
|
|
billNumber:billNumber,
|
|
planId:req.body.planId,
|
|
amount:req.body.amount,
|
|
validity:req.body.validity,
|
|
paymentType:1,//online
|
|
startDate:new Date(),
|
|
endDate:enddate,
|
|
razorpayOrderId:req.body.razorpayOrderId,
|
|
razorpayPaymentId:req.body.razorpayPaymentId,
|
|
razorpaySignature:req.body.razorpaySignature,
|
|
createdBy:req.body.createdBy,
|
|
status:req.body.status,
|
|
createdAt:Date.now()
|
|
}
|
|
|
|
const storeData=
|
|
{
|
|
storeId:req.body.id,
|
|
planId:req.body.planId,
|
|
planType:2,
|
|
planValidity:req.body.validity,
|
|
planStatus:1,//active
|
|
startDate:new Date(),
|
|
endDate:enddate,
|
|
}
|
|
var subscritption=await models.subscription.create(data);
|
|
if(subscritption){
|
|
models.store.update(storeData,{where:{id:req.body.storeId}}).then(ress=>{
|
|
console.log(ress);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: ress
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
//GET SUBSCRIPTION DETAILS
|
|
|
|
//GET RAZORPAY DETAIL
|
|
|
|
app.get('/settings',authVerify,async(req,res)=>{
|
|
|
|
await models.settings.findAll({where:{status:1},
|
|
attributes: [`id`, `razor_key`, `razor_secretkey`]
|
|
})
|
|
.then(result=>{
|
|
var razor_key=result[0]['razor_key'];
|
|
var razor_secretkey=result[0]['razor_secretkey'];
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Razorpay List",
|
|
Key: razor_key,
|
|
secretKey: razor_secretkey
|
|
|
|
});
|
|
}).catch(error=>{console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
var deviceAccessCheck="This mobile number is register on another device please check";
|
|
//USER START
|
|
|
|
//1.getotp
|
|
app.post('/getOtp',async(requ,res)=>{
|
|
var mob =requ.body.mobile;
|
|
var ccode =91;
|
|
var mobwithccode = ccode + mob;
|
|
await models.store.findAll({where:{contactNumber:requ.body.mobile},
|
|
attributes: [`id`, `storeName`, `storeUrl`, `ownerName`, `contactNumber`, `whatsAppNumber`, `address1`,
|
|
`address2`, `pincode`, `location`, `storeImage`, `openingTime`, `closingTime`, `features`, `disclaimer`, `status`, `otp`, `verifyOtp`, `createdBy`, `updatedBy`, `createdAt`, `updatedAt`]
|
|
|
|
}).then(result=>{
|
|
|
|
if(result.length > 0)
|
|
{
|
|
|
|
var OTP=Math.floor(100000 + Math.random() * 900000);
|
|
|
|
// Google verification
|
|
if (mob == "9633468236") OTP = "515085";
|
|
|
|
const url = "http://sms.dotwings.net/api/smsapi?key=6ca7240e6b85c4dee6c2fa38e947c220&route=4&sender=DOTWIN&number="+mobwithccode+"&sms="+OTP+" is your One Time Password (OTP) - DOTWINGS.&templateid=1707165087062220072";
|
|
http.get(url, function(response) {
|
|
if(response.statusCode==200)
|
|
{
|
|
console.log("test");
|
|
var data={otp:OTP,status:0,verifyOtp:0}
|
|
models.store.update(data,{where:{contactNumber:requ.body.mobile}}).then(upotp=>{
|
|
console.log("test1");
|
|
var response_code="1";
|
|
var alertinfo="OTP sent successfully";
|
|
res.send(JSON.stringify({ "code":response_code,"message":alertinfo}));
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
else
|
|
{
|
|
let data=
|
|
{
|
|
contactNumber: requ.body.mobile
|
|
}
|
|
models.store.create(data).then(newres=>{
|
|
|
|
var OTP=Math.floor(100000 + Math.random() * 900000)
|
|
const url = "http://sms.dotwings.net/api/smsapi?key=960a0d015c1ab50eb9e57bf09a1027e2&route=4&sender=OPENCL&number="+mob+"&sms="+OTP+" is the OTP for Open Close App.&templateid=1207164448608913709";
|
|
|
|
http.get(url, function(response) {
|
|
|
|
if(response.statusCode==200)
|
|
{
|
|
var datan={otp:OTP,status:0,verifyOtp:0}
|
|
models.store.update(datan,{where:{contactNumber:requ.body.mobile}}).then(upotp=>{
|
|
var response_code="1";
|
|
var alertinfo="OTP sent successfully";
|
|
res.send(JSON.stringify({ "code":response_code,"message":alertinfo}));
|
|
});
|
|
}
|
|
|
|
});
|
|
})
|
|
}
|
|
})
|
|
|
|
});
|
|
|
|
//2.verifyotp
|
|
app.post('/verifyOtp',async(requ,rese)=>
|
|
{
|
|
let bufferObjmob = Buffer.from(requ.body.mobile, "base64");
|
|
let mobile = bufferObjmob.toString("utf8");
|
|
let bufferObjotp = Buffer.from(requ.body.otp, "base64");
|
|
let otp = bufferObjotp.toString("utf8");
|
|
await models.store.findAll({where:{contactNumber:mobile},
|
|
attributes: [`id`, `storeName`, `storeUrl`,`otp`]
|
|
|
|
}).then(results=>{
|
|
|
|
if(results.length>0)
|
|
{
|
|
|
|
var storeId=results[0]["id"];
|
|
// var ccode=results[0]["countryCode"];
|
|
var ex_otp=results[0]["otp"];
|
|
var storeUrl=results[0]["storeUrl"];
|
|
// var mobwithccode = ccode + mobile;
|
|
|
|
if(storeUrl!=null){
|
|
|
|
var already_store=true;
|
|
}
|
|
else
|
|
{
|
|
var already_store=false;
|
|
}
|
|
|
|
if(ex_otp==otp){
|
|
|
|
let data={
|
|
status: 1,
|
|
verifyOtp:1,
|
|
deviceId:requ.body.deviceId
|
|
}
|
|
models.store.update(data,{where:{id:storeId}}).then(
|
|
upresult=>{
|
|
if(upresult.length > 0 )
|
|
{
|
|
var response_code="2";
|
|
var alertinfo="Otp verified";
|
|
const jsonwebtoken= sign({mobile:requ.body.mobile,storeId:storeId,deviceId:requ.body.deviceId},process.env.JWT_KEY);
|
|
if(jsonwebtoken!=""){
|
|
|
|
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"storeId": storeId,"storeStatus":already_store,"token":jsonwebtoken}));
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
var response_code="3";
|
|
var alertinfo="Otp not matched";
|
|
|
|
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"storeId": storeId}));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
});
|
|
//2.verifyotp
|
|
app.post('/checkStoreExist',async(requ,rese)=>{
|
|
await models.store.findAll({where:{contactNumber:requ.body.mobile},
|
|
attributes: [`id`, `storeName`, `storeUrl`, `ownerName`, `contactNumber`, `whatsAppNumber`, `address1`,
|
|
`address2`, `pincode`, `location`, `storeImage`, `openingTime`, `closingTime`, `features`, `disclaimer`, `status`, `otp`, `verifyOtp`, `createdBy`, `updatedBy`, `createdAt`, `updatedAt`]
|
|
|
|
}).then(results=>{
|
|
|
|
if(results.length>0)
|
|
{
|
|
// console.log(">o");
|
|
var storeId=results[0]["id"];
|
|
var storeUrl=results[0]["storeUrl"];
|
|
|
|
if(storeUrl!=null){
|
|
|
|
var already_store=true;
|
|
}
|
|
else
|
|
{
|
|
|
|
var already_store=false;
|
|
}
|
|
var response_code="1";
|
|
var alertinfo="Store Registered..";
|
|
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"storeId": storeId,"storeStatus":already_store}));
|
|
}
|
|
else
|
|
{
|
|
|
|
var response_code="0";
|
|
var alertinfo="Mobile number not matched";
|
|
|
|
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"storeId": storeId}));
|
|
|
|
}
|
|
|
|
|
|
})
|
|
});
|
|
|
|
//=================
|
|
|
|
//LOGIN
|
|
app.post('/login',async(req,res)=>
|
|
{
|
|
//SELECT DATA FROM EMPLOYEE TABLE WITH GIVEN EMAIL
|
|
const existingUser=await models.users.findOne({where:{username:req.body.username,userType:1},
|
|
attributes:[`id`, `userType`, `name`, `image`,`referralDoctor`, `email`, `contactNumber`, `whatsAppNumber`, `address1`, `address2`, `pincode`, `location`, `username`, `password`, `status`, `createdAt`, `updatedAt`]
|
|
});
|
|
if(!existingUser)
|
|
{
|
|
res.send({
|
|
Code:0,
|
|
Message:"Username does not exist...!"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//COMPARE GIVEN PASSWORD AND EISTING PASSWORD (IN DB)
|
|
const checkUser=await hashValidator(req.body.password,existingUser.password);
|
|
if(!checkUser){
|
|
res.send({
|
|
Code:0,
|
|
Message:"Invalid Password"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
const token=await tokenGenerator(existingUser.username);
|
|
//res.cookie("jwt",token);
|
|
res.send({
|
|
JWTToken:token,
|
|
Code:1,
|
|
User:existingUser.name,
|
|
Id:existingUser.id,
|
|
profileImage:existingUser.image,
|
|
Message:"Login Successfully!"
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|
|
//POST USER ADD
|
|
app.post('/addUser',authVerify,async(req,res)=>{
|
|
|
|
//GENERATE HASH PASSWORD FROM {hashGenerate} FUNCTION
|
|
const hashPassword=await hashGenerate(req.body.password);
|
|
const data=
|
|
{
|
|
userType:req.body.userType,
|
|
name:req.body.name,
|
|
referralDoctor:req.body.referralDoctor,
|
|
email:req.body.email,
|
|
contactNumber:req.body.contactNumber,
|
|
whatsAppNumber:req.body.whatsAppNumber,
|
|
address1:req.body.address1,
|
|
address2:req.body.address2,
|
|
pincode:req.body.pincode,
|
|
location:req.body.location,
|
|
username:req.body.username,
|
|
password:hashPassword,
|
|
status:req.body.status,
|
|
createdAt:Date.now()
|
|
}
|
|
|
|
await models.users.create(data).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"User Created Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
});
|
|
//GET USER LIST
|
|
|
|
app.get('/users',authVerify,async(req,res)=>{
|
|
await models.users.findAll({where:{status:1,userType:2},
|
|
attributes: [`id`, `userType`, `name`, `referralDoctor`, `email`, `contactNumber`, `whatsAppNumber`, `address1`, `address2`, `pincode`, `location`, `username`, `password`, `status`, `createdAt`, `updatedAt`]
|
|
})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Users List",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
|
|
//PUT USER VIEW
|
|
app.get('/viewUser/(:userId)',authVerify,async(req,res)=>{
|
|
await models.users.findByPk(req.params.userId,{
|
|
attributes: [`id`, ["concat('"+process.env.IMAGE_URL+"profile/', image)" , 'image'],`userType`, `name`, `referralDoctor`, `email`, `contactNumber`, `whatsAppNumber`, `address1`, `address2`, `pincode`, `location`, `username`, `password`, `status`, `createdAt`, `updatedAt`]
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT USER - UPDATE
|
|
|
|
const files=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/profile");
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
|
|
cb(null,"st-"+Date.now()+ file.originalname);
|
|
}
|
|
});
|
|
const uploadimg=multer({
|
|
storage:files
|
|
});
|
|
|
|
app.put('/updateUser/(:userId)',uploadimg.single('image'),async(req,res)=>{
|
|
const userid=req.params.userId;
|
|
console.log(req.body.passwords);
|
|
if(req.body.passwords!="null")
|
|
{
|
|
console.log("if");
|
|
var curpass=await hashGenerate(req.body.passwords);
|
|
|
|
}
|
|
else
|
|
{
|
|
console.log("else");
|
|
var curpass= req.body.oldpassword;
|
|
}
|
|
console.log(curpass);
|
|
if(req.body.image==undefined)
|
|
{
|
|
var currentimg=req.file.filename;
|
|
}
|
|
else
|
|
{
|
|
var currentimg=req.body.image;
|
|
}
|
|
|
|
const data=
|
|
{
|
|
userType:req.body.userType,
|
|
name:req.body.name,
|
|
referralDoctor:req.body.referralDoctor,
|
|
email:req.body.email,
|
|
contactNumber:req.body.contactNumber,
|
|
whatsAppNumber:req.body.whatsAppNumber,
|
|
address1:req.body.address1,
|
|
address2:req.body.address2,
|
|
pincode:req.body.pincode,
|
|
location:req.body.location,
|
|
username:req.body.username,
|
|
password:curpass,
|
|
image:currentimg,
|
|
status:req.body.status,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.users.update(data,{where:{id:userid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT USER - DELETE
|
|
app.put('/deleteUser/(:userId)',authVerify,async(req,res)=>{
|
|
const userid=req.params.userId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
|
|
await models.users.update(data,{where:{id:userid}}).then(result=>{
|
|
res.status(201).json({
|
|
Message:"Successfully Deleted",
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//MEDICINES START
|
|
//POST MEDICINES ADD
|
|
//MULTER FOR UPLOAD IMAGE
|
|
const medicine=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/medicine");//call backsrc\assets\uploads
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
cb(null,"md-"+Date.now()+file.originalname);
|
|
}
|
|
|
|
});
|
|
const imageFileFilter=(req,file,cbe)=>{
|
|
if(!file.originalname.match(/\.(jpg|jpeg|png|gif)$/)){
|
|
return cbe(new Error('You can upload only images'),false);
|
|
}
|
|
cb(null,true)
|
|
}
|
|
const medicineUploaded=multer({
|
|
storage:medicine
|
|
|
|
});
|
|
|
|
//MULTER FOR UPLOAD IMAGE
|
|
app.post('/addMedicines',medicineUploaded.single('imageps'),authVerify,async(req,res)=>{
|
|
//console.log(req.file.filename)
|
|
//GENERATE HASH PASSWORD FROM {hashGenerate} FUNCTION
|
|
const data=
|
|
{
|
|
name:req.body.name,
|
|
companyId:req.body.companyId,
|
|
storeId:0,
|
|
amount:req.body.amount,
|
|
quantity:req.body.quantity,
|
|
image:req.file.filename,
|
|
discount:req.body.discount,
|
|
howWorks:req.body.howWorks,
|
|
directionOfUse:req.body.directionOfUse,
|
|
prescription:req.body.prescription,
|
|
status:1,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now(),
|
|
medicineuses: req.body.isComingFromPostman?req.body.medicineuses:JSON.parse(req.body.medicineuses),
|
|
medicinesideeffects:req.body.isComingFromPostman?req.body.medicinesideeffects:JSON.parse(req.body.medicinesideeffects)
|
|
}
|
|
console.log("data",data);
|
|
await models.medicines.create(data,{include:[
|
|
//insert into multiple table
|
|
{model: models.medicinesideeffects},
|
|
{model: models.medicineuses}
|
|
]}
|
|
).then(result=>{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Medicine Created Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
});
|
|
//GET MEDICINES LIST
|
|
app.get('/medicines',authVerify,async(req,res)=>{
|
|
await models.medicines.findAll({where:{status:1},order: [ ['name', 'ASC']],
|
|
attributes: [ `id`, `name`,'companyId','storeId', `quantity`, `amount`, `discount`,["concat('"+process.env.IMAGE_URL+"medicine/', image)" , 'image'],'howWorks','directionOfUse','prescription','status'],
|
|
include:[
|
|
{model: models.store,attributes: ['storeName']},
|
|
{model: models.company,attributes:[['name','companyName']]},
|
|
//{model: models.medicineuses,attributes: ['name','medicineId','status']},
|
|
//{model: models.medicinesideeffects,attributes: ['name','medicineId','status']},
|
|
|
|
]
|
|
})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Medicine List",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
})
|
|
});
|
|
|
|
//PUT MEDICINES VIEW
|
|
app.put('/viewMedicine/(:medicineId)',authVerify,async(req,res)=>{
|
|
await models.medicines.findByPk(req.params.medicineId,{
|
|
attributes: [ `id`, `name`,'companyId','storeId', `quantity`, `amount`, `discount`,["concat('"+process.env.IMAGE_URL+"medicine/', image)" , 'image'],'howWorks','directionOfUse','prescription','status'],
|
|
include: [
|
|
{model: models.company,attributes: [['name','companyName']]},
|
|
{model: models.medicineuses,attributes: [['name','uses']]},
|
|
{model: models.medicinesideeffects,attributes: [['name','sideEffects']]}
|
|
]}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT MEDICINES - UPDATE
|
|
app.put('/updateMedicine/(:medicineId)',medicineUploaded.single('imagepa'),authVerify,async(req,res)=>{
|
|
const mid=req.params.medicineId;
|
|
|
|
models.medicineuses.destroy({where:{medicineId:mid}});
|
|
models.medicinesideeffects.destroy({where:{medicineId:mid}});
|
|
models.medicineuses.bulkCreate(req.body.medicineuses);
|
|
models.medicinesideeffects.bulkCreate(req.body.medicinesideeffects);
|
|
|
|
await models.medicines.findAll({where:{id:mid},attributes:['image']}).then(result1=>{
|
|
if(result1.length>0)
|
|
{
|
|
var medicineImage=result1[0]["image"];
|
|
}
|
|
console.log(req.body.imagepa);
|
|
console.log(req.file.filename);
|
|
if(req.body.imagepa==undefined)
|
|
{
|
|
var currentimg=req.file.filename;
|
|
}
|
|
else
|
|
{
|
|
var currentimg=medicineImage;
|
|
}
|
|
data=
|
|
{
|
|
name:req.body.name,
|
|
companyId:req.body.companyId,
|
|
storeId:req.body.storeId,
|
|
storeId:req.body.storeId,
|
|
amount:req.body.amount,
|
|
discount:req.body.discount,
|
|
quantity:req.body.quantity,
|
|
image:currentimg,
|
|
howWorks:req.body.howWorks,
|
|
directionOfUse:req.body.directionOfUse,
|
|
prescription:req.body.prescription,
|
|
status:req.body.status,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
}
|
|
models.medicines.update(data,{where:{id:mid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
})
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT MEDICINES - DELETE
|
|
app.put('/deleteMedicine/(:medicineId)',authVerify,async(req,res)=>{
|
|
const mid=req.params.medicineId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
await models.medicineuses.update({status:0},{where:{medicineId:mid}});
|
|
await models.medicinesideeffects.update({status:0},{where:{medicineId:mid}});
|
|
await models.medicines.update(data,{where:{id:mid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Deleted",
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//COMPANY START
|
|
//POST COMPANY ADD
|
|
app.post('/addCompany',authVerify,async(req,res)=>{
|
|
|
|
const data=
|
|
{
|
|
name:req.body.name,
|
|
status:1,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
}
|
|
|
|
await models.company.create(data).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Company Created Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
});
|
|
//GET COMPANY LIST
|
|
app.get('/companies',authVerify,async(req,res)=>{
|
|
await models.company.findAll({where:{status:1}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Company List",
|
|
Data: result
|
|
}
|
|
);
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
|
|
//PUT COMPANY VIEW
|
|
app.put('/viewComapany/(:comId)',authVerify,async(req,res)=>{
|
|
await models.company.findByPk(req.params.comId).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
///PUT COMPANY - UPDATE
|
|
app.put('/updateCompany/(:comId)',authVerify,async(req,res)=>{
|
|
const cid=req.params.comId;
|
|
const data=
|
|
{
|
|
name:req.body.name,
|
|
status:1,
|
|
createdBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.company.update(data,{where:{id:cid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
///PUT COMPANY - DELETE
|
|
app.put('/deleteCompany/(:comId)',authVerify,async(req,res)=>{
|
|
const cid=req.params.comId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
|
|
await models.company.update(data,{where:{id:cid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Deleted",
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//COMPANY START
|
|
|
|
//{ model: models.store ,attributes: ['storeName','ownerName','contactNumber','address1','pincode','location']}
|
|
app.get('/subscriptionDetails',authVerify,async(req,res)=>{
|
|
await models.subscription.findAll(
|
|
{
|
|
where:{status:1},
|
|
include:
|
|
[
|
|
//model: models.store ,attributes: ['storeName']}
|
|
{model:models.store,attributes:['storeName']},
|
|
// {model:models.users,attributes:[['name','username'],'email']},
|
|
{model:models.plan,attributes:[['name','planName']]}
|
|
]
|
|
|
|
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Subscription Details",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT SUBSCRIPTION VIEW
|
|
app.put('/viewSubscription/(:subId)',authVerify,async(req,res)=>{
|
|
await models.subscription.findByPk(req.params.subId).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT SUBSCRIPTION EDIT
|
|
app.put('/updateSubscription/(:subId)',authVerify,async(req,res)=>{
|
|
const sid=req.params.subId;
|
|
const data=
|
|
{
|
|
storeId:req.body.storeId,
|
|
billNumber:req.body.billNumber,
|
|
planId:req.body.planId,
|
|
amount:req.body.amount,
|
|
validity:req.body.validity,
|
|
paymentType:req.body.paymentType,
|
|
startDate:req.body.startDate,
|
|
endDate:req.body.endDate,
|
|
updatedBy:req.body.createdBy,
|
|
status:req.body.status,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.subscription.update(data,{where:{id:sid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT SUBSCRIPTION DELETE
|
|
app.put('/deleteSubscription/(:subId)',authVerify,async(req,res)=>{
|
|
const sid=req.params.subId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
|
|
await models.subscription.update(data,{where:{id:sid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Successfully Deleted"
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//POST ORDER-PROCESS ADD
|
|
app.post('/addOrderProcess',authVerify,async(req,res)=>{
|
|
const data=
|
|
{
|
|
name:req.body.name,
|
|
status:req.body.status,
|
|
createdBy:req.body.status,
|
|
createdAt:Date.now()
|
|
|
|
}
|
|
await models.orderProcess.create(data).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Successfully Added"
|
|
});
|
|
}).catch(result=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
|
|
});
|
|
//GET ORDER-PROCESS LIST
|
|
app.get('/orderProcess',authVerify,async(req,res)=>{
|
|
await models.orderProcess.findAll({where:{status:1},attributes:[ `id`, `name`]}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Order Process List",
|
|
Data:result
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT ORDER-PROCESS VIEW
|
|
app.put('/viewOrderProcess/(:opid)',authVerify,async(req,res)=>{
|
|
await models.orderProcess.findByPk(req.params.opid).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Data:result
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT ORDER-PROCESS EDIT
|
|
app.put('/editProcessOrder/(:opid)',authVerify,async(req,res)=>{
|
|
const oid=req.params.opid;
|
|
const data=
|
|
{
|
|
name:req.body.name,
|
|
status:req.body.status,
|
|
updatedBy:req.body.status,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.orderProcess.update(data,{where:{id:oid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Data:"Succesfully Updated"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT ORDER-PROCESS DELETE
|
|
app.put('/deleteOrderProcess/(:opid)',authVerify,async(req,res)=>{
|
|
const oid=req.params.opid;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
|
|
await models.orderProcess.update(data,{where:{id:oid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Deleted"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
|
|
//POST ORDER-PROCESS-HISTORY ADD
|
|
app.post('/addOrderProcessHistory',authVerify,async(req,res)=>{
|
|
data=
|
|
{
|
|
orderId:req.body.orderId,
|
|
statusDate:req.body.statusDate,
|
|
processStatus:req.body.processStatus,
|
|
status:req.body.status,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
}
|
|
|
|
await models.orderProcessHistory.create(data).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Added"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
//GET ORDER-PROCESS-HISTORY LIST
|
|
app.get('/orderHistoryProcess',authVerify,async(req,res)=>{
|
|
await models.orderProcessHistory.findAll({where:{status:1}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Order Process History List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong",
|
|
|
|
});
|
|
})
|
|
});
|
|
//PUT ORDER-PROCESS-HISTORY VIEW
|
|
app.put('/orderHistoryProcessView/(:id)',authVerify,async(req,res)=>{
|
|
await models.orderProcessHistory.findByPk(req.params.id).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"View Order Process History",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong",
|
|
|
|
});
|
|
})
|
|
});
|
|
//PUT ORDER-PROCESS-HISTORY EDIT
|
|
app.put('/editOrderProcessHistory/(:id)',authVerify,async(req,res)=>{
|
|
const phid=req.params.id;
|
|
data=
|
|
{
|
|
orderId:req.body.orderId,
|
|
statusDate:req.body.statusDate,
|
|
processStatus:req.body.processStatus,
|
|
status:req.body.status,
|
|
updatedBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
|
|
await models.orderProcessHistory.update(data,{where:{id:phid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Updated"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT ORDER-PROCESS-HISTORY DELETE
|
|
app.put('/deleteOrderProcessHistory/(:id)',authVerify,async(req,res)=>{
|
|
const phid=req.params.id;
|
|
data=
|
|
{
|
|
status:0
|
|
}
|
|
|
|
await models.orderProcessHistory.update(data,{where:{id:phid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Deleted"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//POST CART ADD
|
|
app.post('/addCart',async(req,res)=>{
|
|
data=
|
|
{
|
|
userId:req.body.userId,
|
|
storeId:req.body.storeId,
|
|
medicineId:req.body.medicineId,
|
|
medAmt:req.body.medAmt,
|
|
pres_required:req.body.pres_required,
|
|
quantity:req.body.quantity,
|
|
amount:req.body.amount,
|
|
discount:req.body.discount,
|
|
total:req.body.total,
|
|
status:req.body.status,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
}
|
|
console.log(data)
|
|
await models.cart.create(data).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Added"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//GET CART LIST
|
|
app.get('/cart',authVerify,async(req,res)=>{
|
|
await models.cart.findAll({where:{status:1}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Cart List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong",
|
|
|
|
});
|
|
})
|
|
});
|
|
//PUT CART VIEW
|
|
app.put('/viewCart/(:cid)',authVerify,async(req,res)=>{
|
|
await models.cart.findByPk(req.params.cid).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"View Cart",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong",
|
|
|
|
});
|
|
})
|
|
});
|
|
//PUT CART EDIT
|
|
app.put('/editCart/(:id)',authVerify,async(req,res)=>{
|
|
const cid=req.params.id;
|
|
data=
|
|
{
|
|
userId:req.body.userId,
|
|
medicineId:req.body.medicineId,
|
|
quantity:req.body.quantity,
|
|
amount:req.body.amount,
|
|
status:req.body.status,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
|
|
}
|
|
|
|
await models.cart.update(data,{where:{id:cid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Updated"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PUT CART DELETE
|
|
app.put('/deleteCart/(:id)',async(req,res)=>{
|
|
const cid=req.params.id;
|
|
await models.cart.destroy({where:{id:cid}}).then(result=>{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"Succesfully Deleted"
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//PROTECTED ROUTE
|
|
app.get('/protected', authVerify,(req,res)=>
|
|
{
|
|
res.send("Iam Protected");
|
|
});
|
|
//===========================================================
|
|
//************ROLE***************************************** */
|
|
//=============================================================
|
|
//1. List role
|
|
app.get('/roles',authVerify,async(req,res)=>{
|
|
await models.role.findAll({
|
|
where: {
|
|
status: 1
|
|
}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Role List",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
//2. add role
|
|
app.post('/addRole',authVerify,async(req,res)=>{
|
|
var data={
|
|
name:req.body.name,
|
|
status:'1',
|
|
createdBy:req.body.createdBy,
|
|
}
|
|
await models.role.create(data).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully added",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//3.view role
|
|
app.get('/viewRole/(:roleId)',authVerify,async(req,res)=>{
|
|
|
|
await models.role.findByPk(req.params.roleId).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//4.update role
|
|
app.put('/updateRole/(:roleId)', authVerify, async(req,res)=>{
|
|
var data={
|
|
name:req.body.name,
|
|
updatedBy:req.body.updatedBy,
|
|
}
|
|
await models.role.update(data,{where:{id:req.params.roleId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully updated",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//5.delete role
|
|
app.put('/deleteRole/(:roleId)', authVerify,async(req,res)=>{
|
|
var data={
|
|
status:0,
|
|
updatedBy:req.body.updatedBy
|
|
}
|
|
await models.role.update(data,{where:{id:req.params.roleId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully deleted",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//===========================================================
|
|
//************PLAN***************************************** */
|
|
//=============================================================
|
|
//1. List plan
|
|
app.get('/plan',authVerify,async(req,res)=>{
|
|
await models.plan.findAll({where:{status:1},
|
|
attributes:[ `id`, `name`, 'planFor',`type`, `amount`, `validity`, `status`, `createdBy`, `updatedBy`, `createdAt`, `updatedAt`]
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Plan List",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
//2. add plan
|
|
app.post('/addPlan',authVerify,async(req,res)=>{
|
|
var data={
|
|
name:req.body.name,
|
|
type:req.body.type,
|
|
planFor:req.body.planFor,//1=Pharmacy 2=Hospital
|
|
amount:req.body.amount,
|
|
validity:req.body.validity,
|
|
status:'1',
|
|
createdBy:req.body.createdBy,
|
|
}
|
|
await models.plan.create(data).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully added",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//3.view plan
|
|
app.get('/viewPlan/(:planId)',authVerify,async(req,res)=>{
|
|
|
|
await models.plan.findByPk(req.params.planId,
|
|
{attributes:[ `id`, `name`,'planFor',`type`, `amount`, `validity`, `status`, `createdBy`, `updatedBy`, `createdAt`, `updatedAt`]}
|
|
).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//4.update plan
|
|
app.put('/updatePlan/(:planId)',authVerify,async(req,res)=>{
|
|
var data={
|
|
name:req.body.name,
|
|
type:req.body.type,
|
|
planFor:req.body.planFor,//1=Pharmacy 2=Hospital
|
|
amount:req.body.amount,
|
|
validity:req.body.validity,
|
|
status:'1',
|
|
updatedBy:req.body.updatedBy,
|
|
}
|
|
await models.plan.update(data,{where:{id:req.params.planId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//5.delete plan
|
|
app.put('/deletePlan/(:planId)',authVerify,async(req,res)=>{
|
|
var data={
|
|
status:0,
|
|
updatedBy:req.body.updatedBy
|
|
}
|
|
await models.plan.update(data,{where:{id:req.params.planId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully deleted",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
//===========================================================
|
|
//************STORES***************************************** */
|
|
//=============================================================
|
|
let date_ob = new Date();
|
|
let date = ("0" + date_ob.getDate()).slice(-2);
|
|
let month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
|
|
let year = date_ob.getFullYear();
|
|
let hours = date_ob.getHours();
|
|
let minutes = date_ob.getMinutes();
|
|
let seconds = date_ob.getSeconds();
|
|
var currentdatetime=date + "-" + month + "-" + year + " " + hours + ":" + minutes + ":" + seconds;
|
|
//1. List store
|
|
app.get('/store',authVerify,async(req,res)=>{
|
|
await models.store.findAll({where:{status:1},
|
|
attributes: [`id`, `storeName`, `ownerName`, `contactNumber`, `whatsAppNumber`, `address1`, `address2`, `pincode`, `location`,["concat('"+process.env.IMAGE_URL+"store/', storeImage)" , 'storeImage'], `openingTime`, `closingTime`, `features`, `disclaimer`, `status`, `createdBy`, `updatedBy`, `createdAt`, `updatedAt`,'storeStatus','returnPolicy','pickup','wideDiscount','cashondelivery']
|
|
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Store List",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
//2. add store
|
|
|
|
|
|
const filestorageengines=multer.diskStorage({
|
|
destination:(reqs,file,cb)=>{
|
|
cb(null,"uploads/store");
|
|
},
|
|
filename: (reqs,file,cb)=>
|
|
{
|
|
|
|
cb(null,"st-"+Date.now()+ file.originalname);
|
|
}
|
|
});
|
|
const uploaded=multer({
|
|
storage:filestorageengines
|
|
});
|
|
|
|
const cpUpload = uploaded.fields([{ name: 'storeImage'}, { name: 'storeDoc' }])
|
|
|
|
|
|
app.put('/addStore/(:storeId)',cpUpload,async(req,res)=>{
|
|
|
|
var storeimg=req.files['storeImage'][0].filename;
|
|
const stProof=req.files['storeDoc'][0].filename;
|
|
|
|
var domain=req.body.storeName;
|
|
var newString = domain.replace(/[^A-Z0-9]/ig, "");
|
|
var storename=newString.toLowerCase() //url
|
|
var storeURL=process.env.STORE_URL+"/"+storename;
|
|
|
|
|
|
models.plan.findAll({where:{status:1,type :1},attributes: [`id`, `name`]})
|
|
.then(planResult=>{
|
|
var planId=planResult[0]['id'];
|
|
console.log(planId)
|
|
var data=
|
|
{
|
|
storeName:req.body.storeName,
|
|
ownerName:req.body.ownerName,
|
|
whatsAppNumber:req.body.whatsAppNumber,
|
|
address1:req.body.address1,
|
|
address2:req.body.address2,
|
|
pincode:req.body.pincode,
|
|
location:req.body.location,
|
|
storeImage:storeimg,
|
|
storeDoc:stProof,
|
|
openingTime:req.body.openingTime,
|
|
closingTime:req.body.closingTime,
|
|
features:req.body.features,
|
|
storeType:req.body.storeType,
|
|
disclaimer:req.body.disclaimer,
|
|
storeStatus:1,
|
|
pickup:1,
|
|
enablePrescription:2,
|
|
wideDiscountType:1,
|
|
wideDiscount:0,
|
|
cashondelivery:1,
|
|
planId:planId,
|
|
planType:1,
|
|
planValidity:14,
|
|
planStatus:1,//1=active,2=deactive
|
|
trialStatus:2,//1=not used,2=used
|
|
startDate:Date.now(),
|
|
endDate:new Date( Date.now() + 14 * 24 * 60 * 60 * 1000),
|
|
status:'1',
|
|
createdBy:req.body.createdBy
|
|
}
|
|
|
|
|
|
models.store.findAll({where:{storeName : req.body.storeName},attributes: [`id`, `storeName`, `storeUrl`]})
|
|
|
|
.then(checkexist=>{
|
|
if(checkexist.length>0){
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Store name already exist...! Please choose another name"
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
|
|
var Notifydata={
|
|
moduleName:"Store",
|
|
messageDetail:"New Store "+req.body.storeName+ " Added...! on "+ currentdatetime,
|
|
status:'1',
|
|
createdBy:req.body.createdBy,
|
|
}
|
|
|
|
QRCode.toDataURL(storeURL,(err, src) => {
|
|
|
|
var qrURL=src;
|
|
const codeda={
|
|
qrCode:qrURL
|
|
}
|
|
models.store.update(codeda,{where:{id:req.params.storeId}})
|
|
models.store.update(data,{where:{id:req.params.storeId}})
|
|
.then(
|
|
result=>{
|
|
//Find
|
|
models.store.findAll({where:{id : req.params.storeId},
|
|
attributes: [`openingTime`, `closingTime`]})
|
|
.then(getStoreDet=>{
|
|
//Find
|
|
var opentime=getStoreDet[0]["openingTime"];
|
|
var closetime=getStoreDet[0]["closingTime"];
|
|
var sun="Sunday";var mon="Monday";var tue="Tuesday";var wed="Wednesday";
|
|
var wed="Wednesday";var thu="Thursday";var fri="Friday";var sat="Saturday";
|
|
var dataChangeTime=[
|
|
{
|
|
storeId:req.params.storeId,
|
|
dayName: sun,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
},
|
|
{
|
|
storeId:req.params.storeId,
|
|
dayName: mon,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
},
|
|
{
|
|
storeId:req.params.storeId,
|
|
dayName: tue,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
},
|
|
{
|
|
storeId:req.params.storeId,
|
|
dayName: wed,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
},
|
|
{
|
|
storeId:req.params.storeId,
|
|
dayName: thu,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
},{
|
|
storeId:req.params.storeId,
|
|
dayName: fri,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
},{
|
|
storeId:req.params.storeId,
|
|
dayName: sat,
|
|
startTime: opentime,
|
|
endTime: closetime,
|
|
status: 1
|
|
}
|
|
]
|
|
//Create
|
|
models.storeTime.bulkCreate(dataChangeTime);
|
|
//Create
|
|
})
|
|
|
|
models.store.update({
|
|
storeUrl:storename
|
|
},{where:{id:req.params.storeId}});
|
|
models.notification.create(Notifydata)
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data:result
|
|
});
|
|
})
|
|
.catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
}
|
|
});
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
//3.view store
|
|
app.get('/viewStore/(:storeId)',async(req,res)=>{
|
|
|
|
await models.store.findByPk(req.params.storeId,
|
|
{attributes: [`id`, `storeName`, `ownerName`, `contactNumber`, 'enablePrescription',`whatsAppNumber`, `address1`, `address2`, `pincode`, `location`, ["concat('"+process.env.IMAGE_URL+"store/', storeImage)" , 'storeImage'], ["concat('"+process.env.IMAGE_URL+"store/', storeDoc)" , 'storeDoc'],`openingTime`, `closingTime`, `features`, `disclaimer`,'storeType','storeStatus','returnPolicy','pickup','cashondelivery','wideDiscountType','wideDiscount','upi','planType','planValidity','startDate','endDate']
|
|
|
|
}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
// //4.update store
|
|
// app.put('/updateStore/(:storeId)',uploaded.single('storeImage'),async(req,res)=>{
|
|
// var data={
|
|
// storeName:req.body.storeName,
|
|
// ownerName:req.body.ownerName,
|
|
// contactNumber:req.body.contactNumber,
|
|
// whatsAppNumber:req.body.whatsAppNumber,
|
|
// address1:req.body.address1,
|
|
// address2:req.body.address2,
|
|
// pincode:req.body.pincode,
|
|
// location:req.body.location,
|
|
// storeImage:req.file.filename,
|
|
// openingTime:req.body.openingTime,
|
|
// closingTime:req.body.closingTime,
|
|
// features:req.body.features,
|
|
// disclaimer:req.body.disclaimer,
|
|
// status:'1',
|
|
// updatedBy:req.body.updatedBy,
|
|
// }
|
|
// var Notifydata={
|
|
// moduleName:"Store",
|
|
// messageDetail:"Store "+req.body.storeName+ " Edited...! on "+currentdatetime,
|
|
// status:'1',
|
|
// updatedBy:req.body.updatedBy,
|
|
// }
|
|
// await models.store.update(data,{where:{id:req.params.storeId}}).then(
|
|
// result=>{
|
|
// models.notification.create(Notifydata)
|
|
// res.status(201).json({
|
|
// Code:"1",
|
|
// Message:"Success",
|
|
// Data:result
|
|
// });
|
|
// }).catch(error=>{
|
|
// res.status(500).json({
|
|
// Code:"0",
|
|
// Message:"No Data"
|
|
|
|
// });
|
|
// })
|
|
// });
|
|
|
|
//4.update store
|
|
app.put('/updateStore/(:storeId)',authVerify,async(req,res)=>{
|
|
|
|
var datas={
|
|
storeName:req.body.storeName,
|
|
ownerName:req.body.ownerName,
|
|
whatsAppNumber:req.body.whatsAppNumber,
|
|
address1:req.body.address1,
|
|
address2:req.body.address2,
|
|
pincode:req.body.pincode,
|
|
location:req.body.location,
|
|
openingTime:req.body.openingTime,
|
|
closingTime:req.body.closingTime,
|
|
features:req.body.features,
|
|
storeType:req.body.storeType,
|
|
disclaimer:req.body.disclaimer,
|
|
status:'1',
|
|
updatedBy:req.body.updatedBy,
|
|
}
|
|
console.log(datas);
|
|
var Notifydata={
|
|
moduleName:"Store",
|
|
messageDetail:"Store "+req.body.storeName+ " Edited...! on "+currentdatetime,
|
|
status:'1',
|
|
updatedBy:req.body.updatedBy,
|
|
}
|
|
await models.store.update(datas,{where:{id:req.params.storeId}}).then(
|
|
result=>{
|
|
models.notification.create(Notifydata)
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
|
|
});
|
|
//5.delete store
|
|
|
|
app.put('/deleteStore/(:storeId)',async(req,res)=>{
|
|
var data={
|
|
status:req.body.status,
|
|
updatedBy:req.body.updatedBy
|
|
}
|
|
await models.store.update(data,{where:{id:req.params.storeId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully deleted",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//===========================================================
|
|
//************PRESCRIPTION***************************************** */
|
|
//=============================================================
|
|
//1. List prescription
|
|
app.get('/prescription',authVerify,async(req,res)=>{
|
|
await models.prescription.findAll( {attributes:['storeId','userId',["concat('"+process.env.IMAGE_URL+"prescription/', prescription)", 'prescription']]},{
|
|
include: [
|
|
{
|
|
model: models.users,attributes: [['name','userName']]
|
|
},
|
|
{
|
|
model: models.store,attributes: ['storeName']
|
|
}
|
|
]
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully added",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
// console.log()
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
|
|
//2. add prescription
|
|
|
|
|
|
const prescription=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/prescription/");
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
|
|
cb(null,"st-"+Date.now()+ file.originalname);
|
|
}
|
|
});
|
|
const uploads=multer({
|
|
storage:prescription
|
|
});
|
|
|
|
app.post('/addPrescription',uploads.single('prescription'),async(req,res)=>{
|
|
var data={
|
|
storeId:req.body.storeId,
|
|
prescription:req.file.filename,
|
|
date:req.body.date,
|
|
userId:req.body.userId,
|
|
status:'1',
|
|
createdBy:req.body.createdBy,
|
|
}
|
|
await models.prescription.create(data).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully added",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//3.view prescription
|
|
app.get('/viewPrescription/(:prescId)',async(req,res)=>{
|
|
|
|
await models.prescription.findByPk(req.params.prescId).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//4.update prescription
|
|
app.put('/updateprescription/(:prescId)',uploads.single('prescription'),async(req,res)=>{
|
|
var data={
|
|
date:req.body.date,
|
|
userId:req.body.userId,
|
|
storeId:req.body.storeId,
|
|
prescription:req.file.filename,
|
|
status:'1',
|
|
updatedBy:req.body.updatedBy,
|
|
}
|
|
await models.prescription.update(data,{where:{id:req.params.prescId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//5.delete prescription
|
|
|
|
app.put('/deletePrescription/(:prescId)',async(req,res)=>{
|
|
var data={
|
|
status:req.body.status,
|
|
updatedBy:req.body.updatedBy
|
|
}
|
|
await models.prescription.update(data,{where:{id:req.params.prescId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully deleted",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//===========================================================
|
|
//************ORDER***************************************** */
|
|
//=============================================================
|
|
//1. List order
|
|
app.get('/orders', authVerify,async(req,res)=>{
|
|
await models.order.findAll({include: [{
|
|
model: models.orderDetails},{
|
|
model: models.store ,attributes: ['storeName']},{
|
|
model:models.users ,attributes: [['name', 'userName']]},{
|
|
model:models.orderProcess ,attributes: [['name','orderStatus']]}
|
|
|
|
]}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
//2. add plan
|
|
app.post('/addOrder',async(req,res)=>{
|
|
var data={
|
|
userId:req.body.userId,
|
|
date:req.body.date,
|
|
storeId:req.body.storeId,
|
|
deviceId:req.body.deviceId,
|
|
quantity:req.body.quantity,
|
|
prescriptionId:req.body.prescriptionId,
|
|
amount:req.body.amount,
|
|
discount:req.body.discount,
|
|
deliveryfee:req.body.deliveryfee,
|
|
total:req.body.total,
|
|
orderProcessId:req.body.orderProcessId,
|
|
paymentMethod:req.body.paymentMethod,
|
|
createdBy:req.body.createdBy,
|
|
status:'1',
|
|
orderDetails:req.body.orderDetails
|
|
}
|
|
|
|
|
|
await models.order.create(data, {
|
|
include: [{
|
|
model: models.orderDetails
|
|
|
|
}]
|
|
}).then(result=>{
|
|
var Notifydata={
|
|
storeId:req.body.storeId,
|
|
messageDetail:"You get a new order from on "+ currentdatetime,
|
|
status:'1',
|
|
createdBy:req.body.createdBy
|
|
}
|
|
models.orderNotification.create(Notifydata)
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully added",
|
|
Data:result
|
|
});
|
|
//var fcmToken=models.store.findAll({where: {id:req.body.storeId},attributes:['deviceId']})
|
|
models.store.findAll({where: {id:req.body.storeId},attributes:['deviceId']}).then(fcmres=>{
|
|
var fcmToken=fcmres[0].deviceId;
|
|
|
|
//////////////
|
|
var serverKey = 'AAAAMPRIRf8:APA91bE75N3ncIfHOmypWgtATGIl1tb7GcjPWGt_HB7q-cIDPCUR5l3_m5bA5O5OHb5prJleFCRn6-7UEUAttGfc0HRCbXrOg3dbZtxsKoGZYIPaEB39H93FYrcbzOMr3F1MsMxdXRS5'; //put your server key here
|
|
const tokenId=fcmToken;
|
|
var fcm = new FCM(serverKey);
|
|
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
|
|
to: tokenId,
|
|
notification: {
|
|
title:"New Order :)",
|
|
body: "You got a new order for ₹ "+req.body.total
|
|
},
|
|
data: { //you can send only notification or only data(or include both)
|
|
my_key: 'my value',
|
|
my_another_key: 'my another value'
|
|
}
|
|
}
|
|
fcm.send(message, function(err, response){
|
|
if (err) {
|
|
console.log(err)
|
|
} else {
|
|
console.log("Successfully sent with response: ", response)
|
|
}
|
|
})
|
|
/////////////////
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
//console.log('dsdsdsds',fcmToken);
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//1. List order
|
|
app.get('/viewOrders/(:orderId)', authVerify,async(req,res)=>{
|
|
await models.order.findByPk(req.params.orderId,{ include: [
|
|
{
|
|
model: models.orderDetails,
|
|
attributes:['orderId','medicineId','quantity','amount','discount','total'],
|
|
include: { model: models.medicines, attributes:[['name','medicineName']] }
|
|
},
|
|
{ model: models.store ,attributes: ['storeName','ownerName','contactNumber','address1','pincode','location']},
|
|
{ model:models.users ,attributes: [['name', 'userName'],'referralDoctor','email','contactNumber','address1','pincode','location']},
|
|
{model:models.orderProcess ,attributes: [['name','orderStatus']]}
|
|
|
|
]
|
|
},{attributes:['amount','discount','total']}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//order status
|
|
//1. List order
|
|
app.put('/changeOrderStatus/(:orderId)', authVerify,async(req,res)=>{
|
|
var data={
|
|
orderProcessId:req.body.orderProcessId,
|
|
}
|
|
await models.order.update(data,{where:{id:req.params.orderId}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//count users
|
|
app.get('/userCount', authVerify,async(req,res)=>{
|
|
await models.users.findAll({where: {status:1,userType:2},attributes:['id']}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" User Count",
|
|
Data:result.length
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//count store
|
|
app.get('/storeCount', authVerify,async(req,res)=>{
|
|
await models.store.findAll({where: {status:1},attributes:['id']}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Store Count",
|
|
Data:result.length
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//count company
|
|
app.get('/companyCount', authVerify,async(req,res)=>{
|
|
await models.company.findAll({where: {status:1},attributes:['id']}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Company Count",
|
|
Data:result.length
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//count medicine
|
|
app.get('/medicineCount', authVerify,async(req,res)=>{
|
|
await models.medicines.findAll({where: {status:1},attributes:['id']}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Medicine Count",
|
|
Data:result.length
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//count order
|
|
app.get('/orderCount', authVerify,async(req,res)=>{
|
|
await models.order.findAll({where: {status:1},attributes:['id']}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order Count",
|
|
Data:result.length
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//order details inside graph
|
|
app.get('/orderGraph', authVerify,async(req,res)=>{
|
|
await models.order.findAll({where:{status:1},
|
|
attributes: [
|
|
/* add other attributes you may need from your table */
|
|
[sequelize.fn('DATE_FORMAT', sequelize.col('date'),"%d-%m-%Y"), 'date'],
|
|
[ sequelize.fn('count', '*'), 'count'],
|
|
],
|
|
group: [sequelize.fn('date', sequelize.col('date')), 'date'],
|
|
order:[
|
|
["date","DESC"]
|
|
],
|
|
limit:7
|
|
|
|
}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order Graph",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
//notofications
|
|
app.get('/getNotification', authVerify,async(req,res)=>{
|
|
await models.notification.findAll({where:{status:1}
|
|
}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Notification Info",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
//viewd notifications
|
|
|
|
app.put('/viewednotification', authVerify,async(req,res)=>{
|
|
var data={
|
|
status:0,
|
|
}
|
|
await models.notification.update(data,{where:{status:1}}).then(
|
|
result=>{ res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
})
|
|
});
|
|
app.get('/subscriptionGraph',authVerify,async(req,res)=>{
|
|
await models.subscription.findAll({where:{status:1},
|
|
attributes: [
|
|
/* add other attributes you may need from your table */
|
|
[sequelize.fn('DATE_FORMAT', sequelize.col('startDate'),"%d-%m-%Y"), 'startDate'],
|
|
[ sequelize.fn('count', '*'), 'count'],
|
|
],
|
|
group: [sequelize.fn('date', sequelize.col('startDate')), 'startDate'],
|
|
order:[
|
|
["startDate","DESC"]
|
|
],
|
|
limit:7
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order Graph",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
app.get('/storeGraph',authVerify,async(req,res)=>{
|
|
await models.store.findAll({where:{status:1},
|
|
attributes: [
|
|
/* add other attributes you may need from your table */
|
|
[sequelize.fn('DATE_FORMAT', sequelize.col('createdAt'),"%d-%m-%Y"), 'date'],
|
|
[ sequelize.fn('count', '*'), 'count'],
|
|
],
|
|
group: [sequelize.fn('date', sequelize.col('createdAt')), 'date'],
|
|
order:[
|
|
["createdAt","DESC"]
|
|
],
|
|
limit:7
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order Graph",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
//today order
|
|
app.get('/todayOrders',authVerify,async(req,res)=>{
|
|
let date_obj = new Date();
|
|
let dates = ("0" + date_obj.getDate()).slice(-2);
|
|
let months = ("0" + (date_obj.getMonth() + 1)).slice(-2);
|
|
let years = date_obj.getFullYear();
|
|
todaydate=years + "-" + months + "-" + dates;
|
|
console.log(todaydate+"ert");
|
|
await models.order.findAll({
|
|
//date:2022-07-21,
|
|
where: sequelize.where(sequelize.fn('date', sequelize.col('date')),' = ',todaydate)
|
|
,include: [{
|
|
model: models.orderDetails},{
|
|
model: models.store ,attributes: ['storeName']},{
|
|
model:models.users ,attributes: [['name', 'userName']]},{
|
|
model:models.orderProcess ,attributes: [['name','orderStatus']]}
|
|
]}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
|
|
//medicine search api
|
|
app.post('/searchMedicine/(:storeId)',async(req,res)=>{
|
|
const Op = sequelize. Op;
|
|
|
|
await models.medicines.findAll({where: {
|
|
name: {
|
|
[Op. like]: '%'+req.body.medicine+'%'
|
|
},status:1,storeId:{
|
|
[Op.in]:[0,req.params.storeId]
|
|
}},
|
|
include:[
|
|
{model: models.company,attributes:[['name','companyName']]}
|
|
],
|
|
attributes:[`id`,`name`, `companyId`, 'quantity','prescription',
|
|
`amount`, `discount`, ["concat('"+process.env.IMAGE_URL+"medicine/', image)" , 'image'], `howWorks`, `directionOfUse`, `status` ],limit:50
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Medicines Search List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
|
|
//store view by name
|
|
app.get('/viewStoreDetail/(:Storeurl)',async(req,res)=>{
|
|
|
|
await models.store.findAll({where:{storeUrl:req.params.Storeurl},
|
|
attributes: [`id`, `storeName`, `ownerName`, `contactNumber`, 'storeUrl','qrCode',`whatsAppNumber`, `address1`, `address2`, `pincode`, `location`,'disclaimer','wideDiscount','wideDiscountType','returnPolicy','pickup', 'cashondelivery','upi',["concat('"+process.env.IMAGE_URL+"store/', storeImage)" , 'storeImage'], `openingTime`, `closingTime`, `features`, `disclaimer`,'enablePrescription','pickup','status','upi',["concat('"+process.env.IMAGE_URL+"store/', upiQr)" , 'upiQr'] ]
|
|
|
|
}).then(
|
|
result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//BANNER START
|
|
//POST BANNER ADD
|
|
//MULTER FOR UPLOAD IMAGE
|
|
const banner=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/banner"); //call backsrc\assets\uploads
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
cb(null,"md-"+Date.now()+file.originalname);
|
|
}
|
|
|
|
});
|
|
|
|
const bannerUploaded=multer({
|
|
storage:banner,
|
|
limits: {
|
|
// Setting Image Size Limit to 2MBs
|
|
fileSize: 2000000
|
|
},
|
|
});
|
|
|
|
//MULTER FOR UPLOAD IMAGE
|
|
app.post('/addBanner',bannerUploaded.single('imageps'),authVerify,async(req,res)=>{
|
|
|
|
const data=
|
|
{
|
|
image:req.file.filename,
|
|
status:1,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
}
|
|
//console.log(data);
|
|
//console.log(req.body.medicineuses);
|
|
await models.banner.create(data)
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Banner Created Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
});
|
|
//GET BANNER LIST
|
|
app.get('/banner',authVerify,async(req,res)=>{
|
|
await models.banner.findAll({where:{status:1},
|
|
|
|
attributes:['id',["concat('"+process.env.IMAGE_URL+"banner/', image)" , 'image']]
|
|
})
|
|
.then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Banner List",
|
|
Data:result
|
|
});
|
|
})
|
|
});
|
|
|
|
//PUT BANNER VIEW
|
|
app.put('/viewBanner/(:bannereId)',authVerify,async(req,res)=>{
|
|
await models.banner.findByPk(req.params.bannereId).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT MEDICINES - UPDATE
|
|
app.put('/updateBanner/(:bannereId)',bannerUploaded.single('imagepa1'),authVerify,async(req,res)=>{
|
|
const bid=req.params.bannereId;
|
|
|
|
if(req.body.imagepa1==undefined)
|
|
{
|
|
//console.log("dsdsds");
|
|
var currentimg=req.file.filename;
|
|
}
|
|
else
|
|
{
|
|
|
|
var currentimg=req.body.image;
|
|
}
|
|
|
|
data=
|
|
{
|
|
image:currentimg,
|
|
status:1,
|
|
updatedBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.banner.update(data,{where:{id:bid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT BANNER - DELETE
|
|
app.put('/deleteBanner/(:bannereId)',authVerify,async(req,res)=>{
|
|
const bid=req.params.bannereId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
await models.banner.update(data,{where:{id:bid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Deleted",
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//GET ORDERS COUNT
|
|
app.get('/ordersCount/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
|
|
await models.order.findAndCountAll({where:{storeId:stid,status:1}})
|
|
.then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
|
|
Code:"1",
|
|
Message:"Orders Count",
|
|
Data:result.count
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data Found"
|
|
});
|
|
})
|
|
});
|
|
//GET ORDERS COUNT
|
|
app.get('/notificationCount/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
|
|
await models.orderNotification.findAndCountAll({where:{storeId:stid,status:1}})
|
|
.then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
|
|
Code:"1",
|
|
Message:"Orders Notification Count",
|
|
Data:result.count
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data Found"
|
|
});
|
|
})
|
|
});
|
|
//GET SALES TOTAL
|
|
app.get('/salesTotal/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
|
|
await models.order.findAll({where:{status:1,storeId:stid},attributes: [[sequelize.fn('sum', sequelize.col('amount')), 'total']]})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Total Sales",
|
|
Data:result[0].total
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data Found"
|
|
});
|
|
})
|
|
});
|
|
//GET STORE VISITORS TOTAL
|
|
app.get('/storeVisitorsCount/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
|
|
await models.storevisitors.findAll({where:{status:1,storeid:stid},attributes: ['count']})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Total Visitors",
|
|
Data:result[0].count
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data Found"
|
|
});
|
|
})
|
|
});
|
|
|
|
//DELIVERY PINCODE
|
|
app.post('/addDeliveryPincode',authVerify,async(req,res)=>{
|
|
|
|
const data=
|
|
{
|
|
storeId:req.body.storeId,
|
|
pincode:req.body.pincode,
|
|
deliveryFee:req.body.deliveryFee,
|
|
free_above:req.body.free_above,
|
|
status:1,
|
|
createdBy:req.body.createdBy,
|
|
createdAt:Date.now()
|
|
}
|
|
|
|
await models.deliveryPincode.create(data)
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Created Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
});
|
|
//GET DELIVERY PINCODE
|
|
app.get('/DeliveryPincode/(:storeId)',authVerify,async(req,res)=>{
|
|
await models.deliveryPincode.findAll({where:{storeId:req.params.storeId,status:1}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"deliveryPincode List",
|
|
Data: result
|
|
});
|
|
})
|
|
});
|
|
|
|
//PUT DELIVERY PINCODE
|
|
app.put('/viewDeliveryPincode/(:storeId)',authVerify,async(req,res)=>{
|
|
await models.deliveryPincode.findByPk(req.params.storeId,{attributes: [`storeId`, `pincode`, `deliveryFee`,'free_above', `status`, `createdAt`, `updatedAt`]}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT DELIVERY PINCODE
|
|
app.put('/updateDeliveryPincode/(:primaryId)',authVerify,async(req,res)=>{
|
|
const pid=req.params.primaryId;
|
|
const data=
|
|
{
|
|
pincode:req.body.pincode,
|
|
deliveryFee:req.body.deliveryFee,
|
|
free_above:req.body.free_above,
|
|
status:1,
|
|
updatedBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.deliveryPincode.update(data,{where:{id:pid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result.data
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
///PUT DELIVERY PINCODE
|
|
app.put('/deleteDeliveryPincode/(:primaryId)',authVerify,async(req,res)=>{
|
|
const pid=req.params.primaryId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
await models.deliveryPincode.update(data,{where:{id:pid}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Deleted",
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//GET COMPLETED ORDER LIST
|
|
app.get('/CompletedOrderList/(:storeId)',authVerify,async(req,res)=>{
|
|
const pid=req.params.storeId;
|
|
await models.order.findAll({
|
|
where:{status:1,orderProcessId:2,storeId:pid},
|
|
attributes: [ `id`, `userId`,'amount', `discount`,'deliveryfee',`total`,'paymentMethod','prescriptionId',`createdAt`],
|
|
include: [
|
|
{model: models.users,attributes: [['name','userName'],['contactNumber','contactNumber'],['address1','address'],['address2','address1'],['pincode','pincode']]},
|
|
{model: models.prescription,attributes: [['prescription','prescriptionName']]}
|
|
]
|
|
})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Completed Order List",
|
|
Data: result,
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//GET PENDING ORDER LIST
|
|
app.get('/pendingOrderList/(:storeId)',authVerify,async(req,res)=>{
|
|
const pid=req.params.storeId;
|
|
await models.order.findAll({
|
|
where:{status:1,orderProcessId:1,storeId:pid},
|
|
attributes: [ `id`, `userId`,'amount', `discount`,'deliveryfee', `total`,'paymentMethod',`createdAt`],
|
|
include: [
|
|
{model: models.users,attributes: [['name','userName'],['contactNumber','contactNumber'],['address1','address'],['address2','address1'],['pincode','pincode']]},
|
|
{model: models.prescription,attributes: [['prescription','prescription']]}
|
|
]
|
|
})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Completed Order List",
|
|
Data: result
|
|
});
|
|
})
|
|
});
|
|
//GET CANCELLED ORDER LIST
|
|
app.get('/cencelledOrderList/(:storeId)',authVerify,async(req,res)=>{
|
|
const pid=req.params.storeId;
|
|
await models.order.findAll({
|
|
where:{status:1,orderProcessId:3,storeId:pid},
|
|
attributes: [ `id`, `userId`,'amount', `discount`,'deliveryfee', `total`,'paymentMethod',`createdAt`],
|
|
include: [
|
|
{model: models.users,attributes: [['name','userName'],['contactNumber','contactNumber'],['address1','address'],['address2','address1'],['pincode','pincode']]},
|
|
{model: models.prescription,attributes: [['prescription','prescription']]}
|
|
]
|
|
})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Completed Order List",
|
|
Data: result
|
|
});
|
|
})
|
|
});
|
|
//GET ORDER DETAILS
|
|
app.get('/medicineOrderDetail/(:orderId)',authVerify,async(req,res)=>{
|
|
const oid=req.params.orderId;
|
|
await models.orderDetails.findAll({
|
|
where:{status:1,orderId:oid},
|
|
attributes: [ `id`,'orderId',`medicineId`,'quantity', `amount`, `discount`, `total`],
|
|
include: [
|
|
{model: models.medicines,attributes: [['name','medicineName']]},
|
|
{model: models.order,attributes: [['paymentMethod','methodOfPayment'],['deliveryfee','deliveryfee']],
|
|
//include:[{model:models.prescription,attributes:[["concat('https://abc.s3-us-west-2.amazonaws.com/', prescription)",'image']]}]
|
|
include:
|
|
[
|
|
//{model: models.prescription,attributes: [["concat('https://abc.s3-us-west-2.amazonaws.com/', prescription)" , 'prescription']]},
|
|
//{model: models.prescription,attributes: [["concat('"+process.env.IMAGE_URL+"prescription/', prescription)" , 'prescription']]},
|
|
{model: models.prescription,attributes: [['prescription', 'prescription']]},
|
|
{model: models.users,attributes: [['name','UserName'],['contactNumber','contactNumber'],['address1','address1'],['address2','address2'],['pincode','pincode'],['location','location']
|
|
]}
|
|
],
|
|
// include:[],
|
|
}
|
|
]
|
|
|
|
})
|
|
.then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Order List Details",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
//GET STORE URL
|
|
app.get('/storeUrl/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
//console.log(stid);
|
|
await models.store.findAll({where:{status:1,id:stid},
|
|
attributes: [["concat('"+process.env.STORE_URL+"/',storeUrl)",'storeUrl'],['storeName','storeName']]})
|
|
|
|
.then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Store URL",
|
|
URL:result[0]['storeUrl'],
|
|
StoreName:result[0]['storeName']
|
|
});
|
|
})
|
|
});
|
|
//GET STORE UPI
|
|
app.put('/updateUPI/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
var data={
|
|
upi:req.body.upi
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>
|
|
{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Store UPI Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//GET STORE UPI
|
|
app.put('/updateStoreStatus/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
var data={
|
|
storeStatus:req.body.storeStatus
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"store Status Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//UPDATE RETURN POLICY
|
|
app.put('/updateReturnPolicy/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
var data={
|
|
returnPolicy:req.body.returnPolicy
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Return Policy Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//UPDATE PICKUP
|
|
app.put('/updatePickup/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
var data={
|
|
pickup:req.body.pickup
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Pickup Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//UPDATE Cashondelivery
|
|
app.put('/updateCashondelivery/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
var data={
|
|
cashondelivery:req.body.cashondelivery
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Cashondelivery Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
///STORE BANNER UPDATE
|
|
//MULTER FOR UPLOAD IMAGE
|
|
const storeBanner=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/store"); //call backsrc\assets\uploads
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
cb(null,"md-"+Date.now()+file.originalname);
|
|
}
|
|
|
|
});
|
|
|
|
const storeBannerUploaded=multer({
|
|
storage:storeBanner,
|
|
limits: {
|
|
// Setting Image Size Limit to 2MBs
|
|
fileSize: 2000000
|
|
},
|
|
});
|
|
|
|
app.put('/updateStoreBanner/(:storeId)',storeBannerUploaded.single('storeImagenew'),authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
|
|
if(req.body.storeImagenew==undefined)
|
|
{
|
|
//console.log("dsdsds");
|
|
var currentimg1=req.file.filename;
|
|
}
|
|
else
|
|
{
|
|
|
|
var currentimg1=req.body.storeImage;
|
|
}
|
|
|
|
data=
|
|
{
|
|
storeImage:currentimg1,
|
|
status:1,
|
|
updatedBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.store.update(data,{where:{id:storeId}}).then(result=>{
|
|
//console.log(result);
|
|
//console.log(storeId);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
|
|
//UPDATE Storewide Discount Type
|
|
app.put('/updateWideDiscountStatus/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
var data={
|
|
wideDiscountType:req.body.wideDiscountType
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Discount Type Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//UPDATE Storewide Discount
|
|
app.put('/updateWideDiscount/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
|
|
var data={
|
|
wideDiscount:req.body.wideDiscount
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Dicount Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Button Disabled"
|
|
|
|
});
|
|
})
|
|
});
|
|
app.put('/MedicineInfoo/(:medicineId)',async(req,res)=>{
|
|
await models.medicines.findByPk(req.params.medicineId,{
|
|
attributes: [ `id`, `name`,'companyId', `quantity`, `amount`, `discount`,["concat('"+process.env.IMAGE_URL+"medicine/', image)" , 'image'],'howWorks','directionOfUse','prescription','status'],
|
|
include: [
|
|
{model: models.company,attributes: [['name','companyName']]},
|
|
{model: models.medicineuses,attributes: ['name','medicineId','status']},
|
|
{model: models.medicinesideeffects,attributes: ['name','medicineId','status']}
|
|
]}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Success",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
app.get('/cartCount/:id/:sid',async(req,res)=>{
|
|
await models.cart.findAndCountAll({where: {status:1,userId:req.params.id,storeId:req.params.sid},attributes:['id']}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Order Count",
|
|
Data:result.count
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
app.put('/viewCartItem/(:deviceid)/(:storeId)',async(req,res)=>{
|
|
await models.cart.findAll({where:{userId:req.params.deviceid,storeId:req.params.storeId},
|
|
attributes: [ `id`,'userId','medicineId','medAmt','quantity','amount','discount','total','status','pres_required'],
|
|
include:[
|
|
{model: models.medicines,attributes:[['name','medicineName'],'amount']}
|
|
]
|
|
}).then(result=>
|
|
|
|
{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"View Cart",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{ //console.log(error);
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"No Data",
|
|
});
|
|
})
|
|
});
|
|
app.put('/listCartItemtoOrder/(:deviceid)/(:stid)',async(req,res)=>{
|
|
await models.cart.findAll({where:{userId:req.params.deviceid,storeId:req.params.stid},
|
|
attributes: ['medicineId','quantity','amount','discount','total','status'],
|
|
}).then(result=>
|
|
|
|
{
|
|
res.status(201).json({
|
|
code:"1",
|
|
Message:"View Cart",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{ console.log(error);
|
|
res.status(500).json({
|
|
code:"0",
|
|
Message:"No Data",
|
|
});
|
|
})
|
|
});
|
|
//GET STORE TIME
|
|
app.get('/getStoreTime/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
// console.log(stid);
|
|
await models.storeTime.findAll({where:{status:1,storeId:stid}}).then(result=>
|
|
{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Store URL",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
})
|
|
});
|
|
app.put('/changeTime/:storeId',async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
await models.storeTime.destroy({where:{storeId:stid}});
|
|
await models.storeTime.bulkCreate(req.body.myData,{where:{storeId:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Time Updated Succesfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
})
|
|
});
|
|
app.put('/viewCartItemSum/(:deviceid)/(:sid)',async(req,res)=>{
|
|
|
|
await models.cart.findAll({where:{userId:req.params.deviceid,storeId:req.params.sid},
|
|
attributes: [
|
|
|
|
[sequelize.fn('sum', sequelize.col('amount')), 'total_amount'],
|
|
],
|
|
group: ['userId'],
|
|
raw: true
|
|
}).then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Cart sum",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
|
|
});
|
|
app.post('/insertUser',async(req,res)=>{
|
|
|
|
//GENERATE HASH PASSWORD FROM {hashGenerate} FUNCTION
|
|
|
|
const data1=
|
|
{
|
|
userType:req.body.userType,
|
|
name:req.body.name,
|
|
referralDoctor:req.body.referralDoctor,
|
|
email:req.body.email,
|
|
contactNumber:req.body.contactNumber,
|
|
address1:req.body.address1,
|
|
address2:req.body.address2,
|
|
pincode:req.body.pincode,
|
|
status:1,
|
|
deviceId:req.body.device
|
|
|
|
// createdAt:Date.now()
|
|
}
|
|
//console.log(req.body.device);
|
|
await models.users.create(data1).then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"User Created Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
});
|
|
|
|
app.put('/deleteCartuser/(:deviceid)/(:sid)',async(req,res)=>{
|
|
|
|
await models.cart.destroy({where:{userId:req.params.deviceid,storeId:req.params.sid},
|
|
|
|
|
|
}).then(result=>{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Cart Deleted",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
app.put('/listmyorder/(:deviceid)/(:sid)',async(req,res)=>{
|
|
|
|
await models.order.findAll({where:{deviceId:req.params.deviceid,storeId:req.params.sid},
|
|
attributes: ['id','date','total','quantity','paymentMethod','userId'],
|
|
include:[
|
|
{ model: models.users,attributes:['name','referralDoctor','email','contactNumber'] },
|
|
{model: models.prescription,attributes: ['storeId','prescription']},
|
|
{model:models.orderProcess ,attributes: ['id',['name','orderStatus']]}
|
|
]
|
|
}).then(result=>{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"List my orders",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
app.put('/listorderdetails/(:oid)',async(req,res)=>{
|
|
|
|
await models.orderDetails.findAll({where:{orderId:req.params.oid},
|
|
attributes: ['medicineId','quantity','amount','total','curdiscount'],
|
|
include:[
|
|
{ model: models.medicines,attributes:['name'] }
|
|
]
|
|
}).then(result=>{
|
|
//console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"List order details",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
/*let sql = "SELECT * FROM register WHERE id="+req.body.userId+" and device_unique_id='"+req.body.deviceId+"'";
|
|
let query = db.query(sql,(err, results) => {
|
|
if(err) throw err
|
|
if(results.length > 0 ){}
|
|
else
|
|
{
|
|
var response_code="2";
|
|
var response_msg=devicee_access_check;
|
|
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
|
|
}
|
|
})*/
|
|
|
|
//******** PLAN Type=1=>Trial, Type=2=>Payment ********
|
|
//4. List Plans
|
|
app.get('/currentPlan/(:storeId)',authVerify,async(req,res)=>{
|
|
await models.store.findAll({where:{id:req.params.storeId},
|
|
attributes: ['planId','planType','trialStatus','planValidity','planStatus','startDate','endDate','storeType'],
|
|
include:[
|
|
{ model: models.plan,attributes:[['name','planName']] }
|
|
],raw:true
|
|
}).then(result=>{
|
|
if(result.length>0)
|
|
{
|
|
var planType=result[0]["planType"];
|
|
var endDate=result[0]["endDate"];
|
|
var storeType=result[0]["storeType"];
|
|
var trialStatus=result[0]["trialStatus"];
|
|
var planName=result[0]['plan.planName'];
|
|
var planStatus=result[0]['planStatus'];
|
|
var current_date = new Date();
|
|
var statusFalse=false;//Subscribe
|
|
var statusTrue=true;
|
|
var isPlanActive=true;
|
|
var isNoPlan=false;
|
|
//***********Condition***********//
|
|
if(planStatus==1)//Plan Active
|
|
{
|
|
if(storeType==1)//store Type 1=Pharmacy
|
|
{
|
|
if(planType==1)//Trial
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
//console.log(updateresult);
|
|
res.status(201).json({
|
|
PlanList: updateresult,
|
|
Message:"Active Plan",
|
|
Status:statusFalse,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate,
|
|
PlanStatus:isPlanActive
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//Expired Condition
|
|
if(current_date>endDate){
|
|
|
|
datan={
|
|
planStatus:2
|
|
}
|
|
models.store.update(datan,{where:{id:req.params.storeId}});
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult,
|
|
Message: "Active Plan",
|
|
Status:statusFalse,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate,
|
|
PlanStatus:isPlanActive
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult1=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult1,
|
|
Message:"Current Plan",
|
|
Status:statusTrue,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate,
|
|
PlanStatus:isPlanActive
|
|
});
|
|
});
|
|
}
|
|
//Expired Condition
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if(planType==1)//Trial
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
//console.log(updateresult);
|
|
res.status(201).json({
|
|
PlanList: updateresult,
|
|
Message:"Active Plan",
|
|
Status:statusFalse,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate,
|
|
PlanStatus:isPlanActive
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//Expired Condition
|
|
if(current_date>endDate){
|
|
|
|
datan={
|
|
planStatus:2
|
|
}
|
|
models.store.update(datan,{where:{id:req.params.storeId}});
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult,
|
|
Message: "Active Plan",
|
|
Status:statusFalse,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate,
|
|
PlanStatus:isPlanActive
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult1=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult1,
|
|
Message:"Current Plan",
|
|
Status:statusTrue,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate,
|
|
PlanStatus:isPlanActive
|
|
});
|
|
});
|
|
}
|
|
//Expired Condition
|
|
}
|
|
}
|
|
}
|
|
else if(planStatus==2 && trialStatus==2)//Plan Expired
|
|
{
|
|
//***********Store Type Condition***********//
|
|
if(storeType==1)//Pharmacy
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult1=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult1,
|
|
Message:"You can't access other features. Pls subscribe to use app",
|
|
Status:statusFalse,
|
|
PlanStatus:isNoPlan
|
|
});
|
|
});
|
|
}
|
|
else
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['id','name','type','amount','validity']})
|
|
.then(updateresult1=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult1,
|
|
Message:"You can't access other features. Pls subscribe to use app",
|
|
Status:statusFalse,
|
|
PlanStatus:isNoPlan
|
|
});
|
|
});
|
|
}
|
|
//***********End Store Type Condition***********//
|
|
}
|
|
//***********End Condition***********//
|
|
}
|
|
|
|
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
/* app.get('/currentPlan/(:storeId)',authVerify,async(req,res)=>{
|
|
//current plan
|
|
await models.store.findAll({where:{id:req.params.storeId},
|
|
attributes: ['planId','planType','planValidity','planStatus','startDate','endDate','storeType'],
|
|
include:[
|
|
{ model: models.plan,attributes:[['name','planName']] }
|
|
],raw:true
|
|
}).then(result=>
|
|
{
|
|
if(result.length>0)
|
|
{
|
|
var planType=result[0]["planType"];
|
|
var endDate=result[0]["endDate"];
|
|
var storeType=result[0]["storeType"];
|
|
var planName=result[0]['plan.planName'];
|
|
var current_date = new Date();
|
|
var statusFalse=false;//Subscribe
|
|
var statusTrue=true;
|
|
if(storeType==1)//store Type 1=Pharmacy
|
|
{
|
|
if(planType==1)//Trial
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
//console.log(updateresult);
|
|
res.status(201).json({
|
|
PlanList: updateresult,
|
|
Message:"Subscribe your plan...",
|
|
Status:statusFalse,
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//Expired Condition
|
|
if(current_date>endDate){
|
|
|
|
datan={
|
|
planStatus:2
|
|
}
|
|
models.store.update(datan,{where:{id:req.params.storeId}});
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult,
|
|
Message: "Your Plan Expired Subscribe Now",
|
|
Status:statusFalse
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:1},attributes:['name','type','amount','validity']})
|
|
.then(updateresult1=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult1,
|
|
Message:"Current Plan",
|
|
Status:statusTrue,
|
|
CurrentPlan:planName,
|
|
ExpiryOn:endDate
|
|
});
|
|
});
|
|
}
|
|
//Expired Condition
|
|
}
|
|
|
|
}
|
|
else if(storeType==2)//2=pharmacy
|
|
{
|
|
if(planType==1)//Trial
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
//console.log(updateresult);
|
|
res.status(201).json({
|
|
PlanList: updateresult,
|
|
Message:"Subscribe your plan...",
|
|
Status:statusFalse
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//Expired Condition
|
|
if(current_date>endDate){
|
|
|
|
datan={
|
|
planStatus:2
|
|
}
|
|
models.store.update(datan,{where:{id:req.params.storeId}});
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['name','type','amount','validity']})
|
|
.then(updateresult=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult,
|
|
Message: "Your Plan Expired Subscribe Now",
|
|
Status:statusFalse
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
models.plan.findAll({where:{status:1,type:2,planFor:2},attributes:['name','type','amount','validity']})
|
|
.then(updateresult1=>
|
|
{
|
|
res.status(201).json({
|
|
PlanList:updateresult1,
|
|
Message:"Current Plan",
|
|
CurrentPlan:planName,
|
|
Status:statusTrue,
|
|
ExpiryOn:endDate
|
|
});
|
|
});
|
|
}
|
|
//Expired Condition
|
|
}
|
|
|
|
}
|
|
}
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
}); */
|
|
//GET MEDICINES LIST
|
|
app.get('/medicinesList/(:storeId)',authVerify,async(req,res)=>{
|
|
await models.medicines.findAll({where:{status:1,storeId:req.params.storeId},
|
|
attributes: [ `id`, `name`,'companyId','storeId', `quantity`, `amount`, `discount`,["concat('"+process.env.IMAGE_URL+"medicine/', image)" , 'image'],'howWorks','directionOfUse','prescription','status'],
|
|
include:[
|
|
{model: models.company,attributes:[['name','companyName']]},
|
|
{model: models.medicineuses,attributes: ['name','medicineId','status']},
|
|
{model: models.medicinesideeffects,attributes: ['name','medicineId','status']}
|
|
]
|
|
})
|
|
.then(result=>{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Medicine List",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
|
|
});
|
|
///STORE BANNER UPDATE
|
|
//MULTER FOR UPLOAD IMAGE
|
|
const storeDocument=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/store"); //call backsrc\assets\uploads
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
cb(null,"md-"+Date.now()+file.originalname);
|
|
}
|
|
|
|
});
|
|
|
|
const storeDocUploaded=multer({
|
|
storage:storeDocument,
|
|
limits: {
|
|
// Setting Image Size Limit to 2MBs
|
|
fileSize: 4000000
|
|
},
|
|
});
|
|
|
|
app.put('/updateStoreDocument/(:storeId)',storeDocUploaded.single('storeDocnew'),authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
|
|
if(req.body.storeDocnew==undefined)
|
|
{
|
|
//console.log("dsdsds");
|
|
var currentimg2=req.file.filename;
|
|
}
|
|
else
|
|
{
|
|
|
|
var currentimg2=req.body.storeDoc;
|
|
}
|
|
|
|
data=
|
|
{
|
|
storeDoc:currentimg2,
|
|
status:1,
|
|
updatedBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.store.update(data,{where:{id:storeId}}).then(result=>{
|
|
//console.log(result);
|
|
//console.log(storeId);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
})
|
|
});
|
|
//GET ORDER BUTTON UPDATE
|
|
app.put('/orderButtonUpdate/(:orderId)',authVerify,async(req,res)=>{
|
|
const orderId=req.params.orderId;
|
|
const data=
|
|
{
|
|
orderProcessId:2
|
|
}
|
|
await models.order.update(data,{where:{id:orderId}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
app.put('/cancelOrderButton/(:orderId)',authVerify,async(req,res)=>{
|
|
const orderId=req.params.orderId;
|
|
const data=
|
|
{
|
|
orderProcessId:3
|
|
}
|
|
await models.order.update(data,{where:{id:orderId}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
//notofications
|
|
app.get('/getOrderNotification/(:storeId)', authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
await models.orderNotification.findAll({where:{status:1,storeId:storeId}
|
|
}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:" Notification Info",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//MULTER FOR UPLOAD IMAGE
|
|
const prescriptionimg=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/prescription"); //call backsrc\assets\uploads
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
cb(null,"md-"+Date.now()+file.originalname);
|
|
}
|
|
|
|
});
|
|
|
|
const prescriptionimgUploaded=multer({
|
|
storage:prescriptionimg,
|
|
|
|
});
|
|
//prescrition upload
|
|
app.post('/prescriptionupload',prescriptionimgUploaded.single('prescription'),async(req,res)=>{
|
|
|
|
const data={
|
|
storeId:req.body.storeId,
|
|
userId:req.body.userId,
|
|
prescription:req.file.filename,
|
|
status:1,
|
|
date:Date.now()
|
|
}
|
|
await models.prescription.create(data).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Upload",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//prescrition upload
|
|
app.get('/prescriptionremove/(:PID)',async(req,res)=>{
|
|
await models.prescription.destroy({where:{id:req.params.PID}}).then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Upload Removed",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//pincode search api
|
|
app.post('/searchPincode',async(req,res)=>{
|
|
const Op = sequelize. Op;
|
|
await models.deliveryPincode.findAll({where: {
|
|
pincode: {
|
|
[Op. like]: '%'+req.body.pincode+'%'
|
|
},status:1,storeId:req.body.storeId},
|
|
attributes:[`deliveryFee`,`free_above`]
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Pincode List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
///PUT USER - DELETE
|
|
app.put('/removeNotification/(:notificationId)',authVerify,async(req,res)=>{
|
|
const noId=req.params.notificationId;
|
|
const data=
|
|
{
|
|
status:0
|
|
}
|
|
|
|
await models.orderNotification.update(data,{where:{id:noId}}).then(result=>{
|
|
res.status(201).json({
|
|
Message:"Successfully Removed",
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Message:"Something went wrong"
|
|
});
|
|
})
|
|
});
|
|
app.get('/getQrCode/(:storeId)', authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
await models.store.findAll({where:{status:1,id:storeId},attributes:[["concat('"+process.env.STORE_URL+"/',storeUrl)",'storeUrl'],'qrCode','storeName']
|
|
}).then(result=>{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"QR Code",
|
|
QRCode:result[0].qrCode,
|
|
StoreName:result[0].storeName,
|
|
storeUrl:result[0].storeUrl
|
|
|
|
});
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
//listsingleorder
|
|
app.get('/listordersingle/(:id)',async(req,res)=>{
|
|
await models.order.findAll({where:{id:req.params.id},
|
|
attributes: ['id','date','total','quantity','deliveryfee','paymentMethod','userId'],
|
|
include:[
|
|
{ model: models.users,attributes:['name','referralDoctor','email','contactNumber','address1','address2','pincode'] },
|
|
{model: models.prescription,attributes: ['storeId','prescription']},
|
|
{model:models.orderProcess ,attributes: ['id',['name','orderStatus']]}
|
|
]
|
|
}).then(result=>{
|
|
console.log(result);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"List my orders",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong"
|
|
|
|
});
|
|
});
|
|
});
|
|
|
|
//UPDATE Storewide Discount Type
|
|
app.put('/updatePrescriptionED/(:storeId)',authVerify,async(req,res)=>{
|
|
const stid=req.params.storeId;
|
|
console.log(stid);
|
|
var data={
|
|
enablePrescription:req.body.enablePrescription
|
|
}
|
|
await models.store.update(data,{where:{status:1,id:stid}})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Prescription Type Updated Successfully",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
//manifest
|
|
app.get('/getManifest/(:storeName)',async(req,res)=>{
|
|
await models.store.findAll({where:{storeUrl:req.params.storeName},
|
|
attributes: ['storeUrl','storeName',["concat('"+process.env.IMAGE_URL+"store/', storeImage)" , 'storeImage']],
|
|
}).then(result=>{
|
|
//console.log(images)
|
|
res.status(201).json({
|
|
"theme_color":"#0D8B85",
|
|
"background_color":"#FFFFFF",
|
|
"display":"standalone",
|
|
"scope":process.env.STORE_URL,
|
|
"start_url":process.env.STORE_URL+'/'+result[0].storeUrl,
|
|
"name":result[0].storeName+" App",
|
|
"short_name":result[0].storeName,
|
|
"icons":[
|
|
{"src":""+result[0].storeImage+"","type":"image/png","sizes":"192x192","purpose":"any maskable"},
|
|
{"src":result[0].storeImage,"type":"image/png","sizes":"512x512","purpose":"any maskable"},
|
|
{"src":result[0].storeImage,"sizes":"256x256","type":"image/png"},
|
|
{"src":result[0].storeImage,"sizes":"384x384","type":"image/png"}
|
|
],
|
|
"description":"Order your medicines online from "+result[0].storeName
|
|
|
|
});
|
|
}).catch(error=>{console.log(error);
|
|
res.status(500).json({
|
|
error
|
|
|
|
});
|
|
});
|
|
});
|
|
app.put('/updatePrescriptionOrder/(:orderId)',authVerify,async(req,res)=>{
|
|
var totalamount=req.body.amount-req.body.discount;
|
|
var data={
|
|
amount:req.body.amount,
|
|
discount:req.body.discount,
|
|
total:totalamount
|
|
}
|
|
const orderId=req.params.orderId;
|
|
models.order.update(data,{where:{status:1,id:orderId}})
|
|
.then(result1=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Order Updated",
|
|
Data:result1
|
|
});
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
});
|
|
});
|
|
|
|
app.get('/viewordereduser/(:userId)',async(req,res)=>{
|
|
await models.users.findAll({where:{id:req.params.userId},
|
|
attributes: ['pincode']})
|
|
.then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Pincode",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
|
|
});
|
|
});
|
|
});
|
|
///STORE BANNER UPDATE
|
|
//MULTER FOR UPLOAD IMAGE
|
|
const UPIImage=multer.diskStorage({
|
|
destination:(req,file,cb)=>{
|
|
cb(null,"uploads/store"); //call backsrc\assets\uploads
|
|
},
|
|
filename: (req,file,cb)=>
|
|
{
|
|
cb(null,"upiqr-"+Date.now()+file.originalname);
|
|
}
|
|
|
|
});
|
|
|
|
const UPIImageUpload=multer({
|
|
storage:UPIImage,
|
|
limits: {
|
|
// Setting Image Size Limit to 2MBs
|
|
fileSize: 4000000
|
|
},
|
|
});
|
|
app.put('/updateUPIQr/(:storeId)',UPIImageUpload.single('UPIImage'),authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
|
|
if(req.body.UPIImage==undefined)
|
|
{
|
|
//console.log("dsdsds");
|
|
var currentimg2=req.file.filename;
|
|
}
|
|
else
|
|
{
|
|
|
|
var currentimg2=req.body.upiQr;
|
|
}
|
|
console.log(currentimg2);
|
|
data=
|
|
{
|
|
upiQr:currentimg2,
|
|
updatedBy:req.body.createdBy,
|
|
updatedAt:Date.now()
|
|
}
|
|
await models.store.update(data,{where:{id:storeId}}).then(result=>{
|
|
//console.log(result);
|
|
//console.log(storeId);
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
})
|
|
});
|
|
//GET BANNER LIST
|
|
app.get('/getUPIQRImage/(:storeId)',authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
await models.store.findAll({where:{status:1,id:storeId},
|
|
|
|
attributes:['id',["concat('"+process.env.IMAGE_URL+"store/', upiQr)" , 'upiQr']]
|
|
})
|
|
.then(result=>{
|
|
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"UPI QR IMage",
|
|
Data:result[0]['upiQr']
|
|
});
|
|
})
|
|
});
|
|
|
|
//store visitors
|
|
app.get('/storevisitors/(:storeid)',async(req,res)=>{
|
|
|
|
await models.storevisitors.findAll({where: {
|
|
storeid:req.params.storeid},
|
|
attributes:[`count`]
|
|
}).then(result=>{
|
|
if(result!=""){
|
|
|
|
var oldcount=result[0]['count'];
|
|
var newcount=oldcount+1;
|
|
if(newcount!=0){
|
|
const data={
|
|
"count":newcount
|
|
}
|
|
models.storevisitors.update(data,{where:{storeid:req.params.storeid}})
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const data={
|
|
"count":1,
|
|
"storeid":req.params.storeid,
|
|
"status":1
|
|
}
|
|
models.storevisitors.create(data)
|
|
}
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"order List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
//cart update
|
|
|
|
//store visitors
|
|
app.post('/updatecart/(:cartid)',async(req,res)=>{
|
|
const data={
|
|
"quantity":req.body.quantity,
|
|
"amount":req.body.amount,
|
|
|
|
}
|
|
await models.cart.update(data,{where: {
|
|
id:req.params.cartid},
|
|
|
|
}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"order List",
|
|
Data:result
|
|
});
|
|
}).catch(error=>{
|
|
console.log(error);
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
app.post('/Verification',async(req,resp)=>
|
|
{
|
|
const secret = "medcifytest@123";
|
|
webhook_signature = req.headers["x-razorpay-signature"];
|
|
var body1 = req.body;
|
|
var expectedSignature = Razorpay.validateWebhookSignature(body1, webhook_signature, secret);
|
|
validateWebhookSignature(body1, webhook_signature, secret);
|
|
var order_id=body1.payload.payment.entity.order_id;
|
|
// console.log("test",webhook_signature)
|
|
var status=body1.payload.payment.entity.status;
|
|
const data={
|
|
paymentStatus:status,
|
|
webhookResponse:webhook_signature,
|
|
}
|
|
console.log("dsds",order_id);
|
|
await models.subscription.update(data,{where:{razorpayOrderId:order_id}}).then(result=>{
|
|
console.log("verresult");
|
|
resp.status(201).json({
|
|
Code:"1",
|
|
Message:"Subscription updated Successfully",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
resp.status(500).json({
|
|
Code:"0",
|
|
Message:"Something went wrong",
|
|
Post: error
|
|
});
|
|
})
|
|
|
|
});
|
|
app.put('/updateFCMToken/(:storeId)',authVerify,async(req,res)=>{
|
|
const storeId=req.params.storeId;
|
|
const data=
|
|
{
|
|
deviceId:req.body.fcmToken
|
|
}
|
|
await models.store.update(data,{where:{id:storeId}}).then(result=>{
|
|
res.status(201).json({
|
|
Code:"1",
|
|
Message:"Successfully Updated",
|
|
Data: result
|
|
});
|
|
}).catch(error=>{
|
|
res.status(500).json({
|
|
Code:"0",
|
|
Message:"No Data"
|
|
});
|
|
})
|
|
});
|
|
module.exports=app;
|
|
//gmodule.exports=qr;
|