Buy & Sell
448
routes/api.js
@ -18,6 +18,7 @@ var db= require('../lib/db');
|
||||
const multer = require('multer');
|
||||
const { monitorEventLoopDelay } = require('perf_hooks');
|
||||
const { notEqual } = require('assert');
|
||||
const { json } = require('body-parser');
|
||||
app.use(bodyparser.json());
|
||||
|
||||
|
||||
@ -911,6 +912,10 @@ app.get('/getLocByRegion',checkToken,function(req,res){
|
||||
//===========================================================
|
||||
//************BUY & SELL***************************************** */
|
||||
//=============================================================
|
||||
|
||||
//=========BUY==========
|
||||
|
||||
|
||||
//1.list all seller product category to buyer screeen
|
||||
app.get('/buysellCategory',checkToken,function(req,res){
|
||||
|
||||
@ -936,7 +941,7 @@ app.get('/buysellCategory',checkToken,function(req,res){
|
||||
});
|
||||
//===================================
|
||||
//2.list all seller products to buyer screeen
|
||||
app.get('/buysellProducts',checkToken,function(req,res){
|
||||
app.get('/buyProducts',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT sp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM seller_products as sp left join buysell_category as bsc on bsc.id=sp.cat_id left join buysell_product_master as bspm on bspm.id=sp.product left join measurement as m on m.id=sp.unit left join pincodes as p on p.id=sp.area WHERE sp.status=1";
|
||||
|
||||
@ -963,6 +968,10 @@ app.get('/buysellProducts',checkToken,function(req,res){
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -970,7 +979,7 @@ app.get('/buysellProducts',checkToken,function(req,res){
|
||||
//====================
|
||||
|
||||
//3.list particular seller products to buyer screeen
|
||||
app.get('/buysellProducts/:categoryId',checkToken,function(req,res){
|
||||
app.get('/buyProducts/:categoryId',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT sp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM seller_products as sp left join buysell_category as bsc on bsc.id=sp.cat_id left join buysell_product_master as bspm on bspm.id=sp.product left join measurement as m on m.id=sp.unit left join pincodes as p on p.id=sp.area WHERE sp.status=1 and sp.cat_id="+req.params.categoryId;
|
||||
|
||||
@ -997,6 +1006,10 @@ app.get('/buysellProducts/:categoryId',checkToken,function(req,res){
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1042,9 +1055,9 @@ app.get('/buyFilter',checkToken,function(req,res){
|
||||
});
|
||||
//========================
|
||||
//5.view particular product to buyer
|
||||
app.get('/viewProduct/:bPPrimaryId',checkToken,function(req,res){
|
||||
app.get('/viewbuyProduct/:bPPrimaryId',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT sp.*,bspm.name as productname,bspm.image,m.name as unitname,r.name as sellername FROM seller_products as sp left join buysell_product_master as bspm on bspm.id=sp.product left join measurement as m on m.id=sp.unit left join register as r on r.id=sp.seller WHERE sp.status=1 and sp.id="+req.params.bPPrimaryId;
|
||||
let sql = "SELECT sp.*,p.region as location,bspm.name as productname,bspm.image,m.name as unitname,r.name as sellername FROM seller_products as sp left join buysell_product_master as bspm on bspm.id=sp.product left join measurement as m on m.id=sp.unit left join register as r on r.id=sp.seller left join pincodes as p on p.id=sp.area WHERE sp.status=1 and sp.id="+req.params.bPPrimaryId;
|
||||
let query = db.query(sql,(err, resultss) => {
|
||||
|
||||
if(resultss.length > 0 ){
|
||||
@ -1117,6 +1130,421 @@ app.get('/viewProduct/:bPPrimaryId',checkToken,function(req,res){
|
||||
});
|
||||
});
|
||||
|
||||
//===================
|
||||
//8.myrequest Page for buyer
|
||||
|
||||
app.get('/myRequest/:userId',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT bp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM buyer_products as bp left join buysell_category as bsc on bsc.id=bp.cat_id left join buysell_product_master as bspm on bspm.id=bp.product left join measurement as m on m.id=bp.unit left join pincodes as p on p.id=bp.area WHERE bp.status!=0 and bp.buyer="+req.params.userId;
|
||||
|
||||
let query = db.query(sql,(err, results) => {
|
||||
if (err) throw err;
|
||||
if(results.length>0)
|
||||
{
|
||||
var finalresult=[];
|
||||
async.eachSeries(results,(finres,callback)=>
|
||||
{
|
||||
var unitname=finres.unitname;
|
||||
var uniprice_per_unittname=finres.price_per_unit;
|
||||
var pro_status=finres.status;
|
||||
|
||||
if(pro_status=="1"){ var productStatus="Requested";}
|
||||
if(pro_status=="2"){ var productStatus="Completed";}
|
||||
if(pro_status=="3"){ var productStatus="Expired";}
|
||||
var singleprice=uniprice_per_unittname+"/"+unitname;
|
||||
finres.singleprice=singleprice;
|
||||
finres.productStatus=productStatus;
|
||||
let resultupdated=finres;
|
||||
finalresult.push(resultupdated);
|
||||
|
||||
callback(null,resultupdated);
|
||||
},
|
||||
(err)=>{
|
||||
if(err) throw err;
|
||||
res.send(JSON.stringify({"code":"1","message":"success","data": finalresult}));
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
});
|
||||
//=================
|
||||
//9.change completed and deleted
|
||||
|
||||
app.put('/changeRequest/:bPPrimaryId',checkToken,function(req,res){
|
||||
let data = { status:req.body.status}
|
||||
let sql = "UPDATE buyer_products SET ? WHERE id="+req.params.bPPrimaryId+"";
|
||||
let query = db.query(sql,data, (err, results) => {
|
||||
if(err) throw err;
|
||||
if(req.body.status=="0")
|
||||
{
|
||||
var message="Deleted successfully";
|
||||
}
|
||||
if(req.body.status=="2")
|
||||
{
|
||||
var message="Updated successfully";
|
||||
}
|
||||
res.send(JSON.stringify({ "code":"1","message":message}));
|
||||
});
|
||||
|
||||
});
|
||||
//=================
|
||||
//10.edit myrequest
|
||||
app.put('/editRequest/:bPPrimaryId',checkToken,function(req,res){
|
||||
let data = {
|
||||
qty:req.body.qty,
|
||||
unit:req.body.unitId,
|
||||
price_per_unit:req.body.pricePerUnit,
|
||||
area:req.body.area,
|
||||
about_product:req.body.about
|
||||
|
||||
}
|
||||
let sql = "UPDATE buyer_products SET ? WHERE id="+req.params.bPPrimaryId+"";
|
||||
let query = db.query(sql,data, (err, results) => {
|
||||
|
||||
if(err) throw err;
|
||||
|
||||
res.send(JSON.stringify({ "code":"1","message":"Updated successfully"}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
//=====================
|
||||
|
||||
//=========SELL========================
|
||||
//1.list all buyer products to seller screeen
|
||||
app.get('/sellProducts',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT bp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM buyer_products as bp left join buysell_category as bsc on bsc.id=bp.cat_id left join buysell_product_master as bspm on bspm.id=bp.product left join measurement as m on m.id=bp.unit left join pincodes as p on p.id=bp.area WHERE bp.status=1";
|
||||
|
||||
let query = db.query(sql,(err, results) => {
|
||||
if (err) throw err;
|
||||
if(results.length>0)
|
||||
{
|
||||
var finalresult=[];
|
||||
async.eachSeries(results,(finres,callback)=>
|
||||
{
|
||||
var unitname=finres.unitname;
|
||||
var uniprice_per_unittname=finres.price_per_unit;
|
||||
var singleprice=uniprice_per_unittname+"/"+unitname;
|
||||
finres.singleprice=singleprice;
|
||||
let resultupdated=finres;
|
||||
finalresult.push(resultupdated);
|
||||
|
||||
callback(null,resultupdated);
|
||||
},
|
||||
(err)=>{
|
||||
if(err) throw err;
|
||||
res.send(JSON.stringify({"code":"1","message":"success","data": finalresult}));
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
});
|
||||
//========================
|
||||
//2.get particular buyer products to seller screeen
|
||||
app.get('/sellProducts/:categoryId',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT bp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM buyer_products as bp left join buysell_category as bsc on bsc.id=bp.cat_id left join buysell_product_master as bspm on bspm.id=bp.product left join measurement as m on m.id=bp.unit left join pincodes as p on p.id=bp.area WHERE bp.status=1 and bp.cat_id="+req.params.categoryId;
|
||||
|
||||
let query = db.query(sql,(err, results) => {
|
||||
if (err) throw err;
|
||||
if(results.length>0)
|
||||
{
|
||||
var finalresult=[];
|
||||
async.eachSeries(results,(finres,callback)=>
|
||||
{
|
||||
var unitname=finres.unitname;
|
||||
var uniprice_per_unittname=finres.price_per_unit;
|
||||
var singleprice=uniprice_per_unittname+"/"+unitname;
|
||||
finres.singleprice=singleprice;
|
||||
let resultupdated=finres;
|
||||
finalresult.push(resultupdated);
|
||||
|
||||
callback(null,resultupdated);
|
||||
},
|
||||
(err)=>{
|
||||
if(err) throw err;
|
||||
res.send(JSON.stringify({"code":"1","message":"success","data": finalresult}));
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
});
|
||||
//==================
|
||||
|
||||
//3.sell filters
|
||||
app.get('/sellFilter',checkToken,function(req,res){
|
||||
|
||||
|
||||
let sql = "SELECT bp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM buyer_products as bp left join buysell_category as bsc on bsc.id=bp.cat_id left join buysell_product_master as bspm on bspm.id=bp.product left join measurement as m on m.id=bp.unit left join pincodes as p on p.id=bp.area WHERE bp.status=1 and bp.product="+req.body.productId+" and bp.area="+req.body.area+" and bp.qty >= "+req.body.qtyFrom+" AND bp.qty <= "+req.body.qtyTo+" and bp.price_per_unit >= "+req.body.priceFrom+" AND bp.price_per_unit <= "+req.body.priceTo;
|
||||
|
||||
let query = db.query(sql,(err, results) => {
|
||||
if (err) throw err;
|
||||
if(results.length>0)
|
||||
{
|
||||
var finalresult=[];
|
||||
async.eachSeries(results,(finres,callback)=>
|
||||
{
|
||||
var unitname=finres.unitname;
|
||||
var uniprice_per_unittname=finres.price_per_unit;
|
||||
var singleprice=uniprice_per_unittname+"/"+unitname;
|
||||
finres.singleprice=singleprice;
|
||||
let resultupdated=finres;
|
||||
finalresult.push(resultupdated);
|
||||
|
||||
callback(null,resultupdated);
|
||||
},
|
||||
(err)=>{
|
||||
if(err) throw err;
|
||||
res.send(JSON.stringify({"code":"1","message":"success","data": finalresult}));
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
//========================
|
||||
//4.view particular product to seller
|
||||
app.get('/viewsellProduct/:bPPrimaryId',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT bp.*,p.region as location,bspm.name as productname,bspm.image,m.name as unitname,r.name as sellername FROM buyer_products as bp left join buysell_product_master as bspm on bspm.id=bp.product left join measurement as m on m.id=bp.unit left join register as r on r.id=bp.buyer left join pincodes as p on p.id=bp.area WHERE bp.status=1 and bp.id="+req.params.bPPrimaryId;
|
||||
let query = db.query(sql,(err, resultss) => {
|
||||
console.log(sql);
|
||||
if(resultss.length > 0 ){
|
||||
var response_code="1";
|
||||
var response_msg="Success";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var response_code="0";
|
||||
var response_msg="No Data";
|
||||
}
|
||||
|
||||
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
//=================
|
||||
//5.add seller products
|
||||
app.post('/sellerRequestProduct',checkToken,function(req,res){
|
||||
|
||||
let data=
|
||||
{
|
||||
seller:req.body.sessionid,
|
||||
cat_id: req.body.categoryId,
|
||||
product:req.body.productId,
|
||||
qty:req.body.qty,
|
||||
unit:req.body.unitId,
|
||||
price_per_unit:req.body.pricePerUnit,
|
||||
area:req.body.area,
|
||||
valid_date:req.body.validDate,
|
||||
about_product:req.body.about,
|
||||
status:1,
|
||||
created_by:req.body.sessionid
|
||||
}
|
||||
|
||||
let sql = "INSERT INTO seller_products SET ?";
|
||||
let query = db.query(sql,data,(err, results) => {
|
||||
if(err) throw err
|
||||
res.send(JSON.stringify({ "code":"1","message":"success","data": results}));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
const filestorageengines=multer.diskStorage({
|
||||
destination:(req,file,cb)=>{
|
||||
cb(null,"./uploads");
|
||||
},
|
||||
filename: (req,file,cb)=>
|
||||
{
|
||||
|
||||
cb(null,"pr-"+Date.now()+ path.extname(file.originalname));
|
||||
}
|
||||
});
|
||||
const uploaded=multer({
|
||||
storage:filestorageengines
|
||||
});
|
||||
|
||||
|
||||
app.post('/insertImages/:primaryId',uploaded.array('productImages'),function(req,res){
|
||||
req.files.forEach(function(value, key) {
|
||||
let data=
|
||||
{
|
||||
seller_product_primary_id:req.params.primaryId,
|
||||
status: 1,
|
||||
created_by: req.body.sessionid,
|
||||
image: value.filename
|
||||
}
|
||||
let sql = "INSERT INTO seller_product_images SET ?";
|
||||
let query = db.query(sql,data,(err, results) => {
|
||||
if(err) throw err
|
||||
|
||||
res.send(JSON.stringify({ "code":"1","message":"success","data": results}));
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
//======================
|
||||
//6.myrequest Page for seller
|
||||
|
||||
app.get('/myRequestSeller/:userId',checkToken,function(req,res){
|
||||
|
||||
let sql = "SELECT sp.*,bsc.name as categoryname,bspm.name as productname,bspm.image,m.name as unitname,p.region as areaname FROM seller_products as sp left join buysell_category as bsc on bsc.id=sp.cat_id left join buysell_product_master as bspm on bspm.id=sp.product left join measurement as m on m.id=sp.unit left join pincodes as p on p.id=sp.area WHERE sp.status!=0 and sp.seller="+req.params.userId;
|
||||
|
||||
let query = db.query(sql,(err, results) => {
|
||||
if (err) throw err;
|
||||
if(results.length>0)
|
||||
{
|
||||
var finalresult=[];
|
||||
async.eachSeries(results,(finres,callback)=>
|
||||
{
|
||||
var unitname=finres.unitname;
|
||||
var uniprice_per_unittname=finres.price_per_unit;
|
||||
var pro_status=finres.status;
|
||||
|
||||
if(pro_status=="1"){ var productStatus="Requested";}
|
||||
if(pro_status=="2"){ var productStatus="Completed";}
|
||||
if(pro_status=="3"){ var productStatus="Expired";}
|
||||
var singleprice=uniprice_per_unittname+"/"+unitname;
|
||||
finres.singleprice=singleprice;
|
||||
finres.productStatus=productStatus;
|
||||
let resultupdated=finres;
|
||||
finalresult.push(resultupdated);
|
||||
|
||||
callback(null,resultupdated);
|
||||
},
|
||||
(err)=>{
|
||||
if(err) throw err;
|
||||
res.send(JSON.stringify({"code":"1","message":"success","data": finalresult}));
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(JSON.stringify({"code":"0","message":"No data"}));
|
||||
}
|
||||
});
|
||||
});
|
||||
//=================
|
||||
//7.change completed and deleted for seller
|
||||
|
||||
app.put('/changeRequestSeller/:bPPrimaryId',checkToken,function(req,res){
|
||||
let data = { status:req.body.status}
|
||||
let sql = "UPDATE seller_products SET ? WHERE id="+req.params.bPPrimaryId+"";
|
||||
let query = db.query(sql,data, (err, results) => {
|
||||
if(err) throw err;
|
||||
if(req.body.status=="0")
|
||||
{
|
||||
var message="Deleted successfully";
|
||||
}
|
||||
if(req.body.status=="2")
|
||||
{
|
||||
var message="Updated successfully";
|
||||
}
|
||||
res.send(JSON.stringify({ "code":"1","message":message}));
|
||||
});
|
||||
|
||||
});
|
||||
//=================
|
||||
//8.edit myrequest
|
||||
app.put('/editRequestSeller/:bPPrimaryId',checkToken,function(req,res){
|
||||
let data = {
|
||||
qty:req.body.qty,
|
||||
unit:req.body.unitId,
|
||||
price_per_unit:req.body.pricePerUnit,
|
||||
area:req.body.area,
|
||||
about_product:req.body.about
|
||||
|
||||
}
|
||||
let sql = "UPDATE seller_products SET ? WHERE id="+req.params.bPPrimaryId+"";
|
||||
let query = db.query(sql,data, (err, results) => {
|
||||
|
||||
if(err) throw err;
|
||||
|
||||
res.send(JSON.stringify({ "code":"1","message":"Updated successfully"}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
//=====================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1128,24 +1556,12 @@ app.get('/viewProduct/:bPPrimaryId',checkToken,function(req,res){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//| |
|
||||
//| API CRUD FOR CATEGORY |
|
||||
//| |
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//======================================
|
||||
|
||||
|
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 4.9 KiB |
BIN
uploads/pr-1642426481768.jpeg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
uploads/pr-1642426481770.jpg
Normal file
After Width: | Height: | Size: 19 KiB |