buy&sell w/o sell images #6

Open
kaleeswari wants to merge 1 commits from buy&sell into main
2 changed files with 627 additions and 9 deletions

View File

@ -26,7 +26,12 @@ This is generated when user verify the otp...then check each and every process t
----------------
BUY & SELL status
------------
0-deleted
1-request
2-completed
3.expired
//=================================API Document===========================
1. GetOTP(POST)
@ -342,11 +347,11 @@ This is generated when user verify the otp...then check each and every process t
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 2 for no data & message
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
25.24.Get location by using region(GET)
25.Get location by using region(GET)
==================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
@ -355,6 +360,262 @@ This is generated when user verify the otp...then check each and every process t
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 2 for no data & message
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
===================================================================================
======/////BUY & SELL
==================================================================================
//1.List all buy sell product category (GET)
=====================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all category from buysell_category
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//2.seller products to buyer screeen(GET)
==========================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from seller_products and use join query for all detail
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
3.//particular seller products to buyer screeen using categoryId(GET)
=================================================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from seller_products and use join query for all detail with category id
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//4.buy filters(GET)
=====================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from seller_products and use join query for all detail with productId,area,qtyFrom,qtyTo,priceFrom,priceTo
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//5.particular product to buyer using primaryID(GET)
===============================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from seller_products and use join query for all detail with primaryID(id) in table
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//6.particular product images to buyer using primaryID(GET)
===============================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from seller_product_image with primaryID(id) from seller_products table & seller_product_primary_id in seller_product_image table
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//7.add buyer products(POST)
============================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->Insert all details in buyer_products table (categoryId,productId,qty,unitId,pricePerUnit,area,validDate,about,sessionid)
-->check there is any data from query
-->if inserted
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//8.myrequest Page for buyer(GET)
======================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->get all details from buyer_products table using join query to get needed details
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//9.Change completed and deleted (PUT)
======================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->change status from buyer_products table using with status 0 for delete & 2 for completed & 3 for expired
-->if changed
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//10.edit myrequest(PUT)
=========================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->update edited details in buyer_products table using primaryId
-->if updated
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//1.Buyer products to seller screeen(GET)
==========================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from buyer_products and use join query for all detail
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
3.//particular buyer products to seller screeen using categoryId(GET)
=================================================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from buyer_products and use join query for all detail with category id
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//4.sell filters(GET)
=====================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from buyer_products and use join query for all detail with productId,area,qtyFrom,qtyTo,priceFrom,priceTo
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//5.particular product to seller using primaryID(GET)
===============================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from buyer_products and use join query for all detail with primaryID(id) in table
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//7.add seller products(POST)
============================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->Insert all details in seller_products table (categoryId,productId,qty,unitId,pricePerUnit,area,validDate,about,sessionid)
-->check there is any data from query
-->if inserted
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//7.add Images of seller products(POST)
============================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->Insert all details in seller_product_images table (productImages,sessionid)
-->check there is any data from query
-->if inserted
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//8.myrequest Page for seller(GET)
======================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->get all details from seller_products table using join query to get needed details
-->check there is any data from query
-->if yes
-->sent code 1 for success & message
-->if no
-->sent code 0 for no data & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//9.Change completed and deleted (PUT)
======================================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->change status from seller_products table using with status 0 for delete & 2 for completed & 3 for expired
-->if changed
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"
//10.edit myrequest for seller(PUT)
=========================
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->update edited details in buyer_products table using primaryId
-->if updated
-->sent code 1 for success & message
-->if no
-->show code is 2 for error & message is "this mobile number is register with another device please check"

View File

@ -19,7 +19,9 @@ const multer = require('multer');
const { monitorEventLoopDelay } = require('perf_hooks');
const { notEqual } = require('assert');
app.use(bodyparser.json());
app.get('/',function(requ,res){
res.send("welcome");
});
//1.getotp
app.post('/getOtp',function(requ,res){
@ -1105,10 +1107,7 @@ app.get('/viewProduct/:bPPrimaryId',checkToken,function(req,res){
about_product:req.body.about,
status:1,
created_by:req.body.sessionid
}
}
let sql = "INSERT INTO buyer_products SET ?";
let query = db.query(sql,data,(err, results) => {
@ -1116,7 +1115,365 @@ app.get('/viewProduct/:bPPrimaryId',checkToken,function(req,res){
res.send(JSON.stringify({ "code":"1","message":"success","data": results}));
});
});
//===================
//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"}));
});
});
//=====================