buy commit

This commit is contained in:
Kaleeswari 2022-01-13 19:22:20 +05:30
parent 8a48e1a95a
commit eb6aa11df5
12 changed files with 1119 additions and 499 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env
node_modules

View File

@ -20,6 +20,14 @@ otp section
1 - trial plan
2 - market
--------------------
JsonWebToken (sign,verify) methods
This is generated when user verify the otp...then check each and every process there is any unmatched data
----------------
//=================================API Document===========================
1. GetOTP(POST)
===========
@ -40,7 +48,7 @@ otp section
-->final result sent as response
-->check that response is seccess or error
-->Get userid from select query by using mobile number
-->if success means update those values into register table by using userId
-->if success means update those values into register table by using userId and generate jwttoken also
-->not success means show error
3.ResendOTP(POST)
@ -53,7 +61,7 @@ otp section
4.Listplans(GET)
==========
-->using userid and deviceid we have to check there is any data in register table(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->check trial_status is 0 or 1 in register table (trial_status from select query of userid & deviceid)
-->if 0 means show all palns in plan table
@ -65,7 +73,7 @@ otp section
5.SubscribePlan(POST)
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->get mobile and plan from application also get plan table all details using select query
-->check there is any match from select query of planid and given request plan id
@ -81,7 +89,7 @@ otp section
6.Listnews(GET)
==========
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select news from news table with desc order and status=1
-->check there is any match from select query
@ -94,7 +102,7 @@ otp section
7.Listcategories(GET)
================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select category from category table with status=1 & using these category id get marketcount from market_product table
-->sent all data to async method to get result from single object data
@ -105,7 +113,7 @@ otp section
8.Listmarkets(GET)
============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select needed details
-->check there is any match from select query
@ -118,7 +126,7 @@ otp section
9.Categorydetails(/categoryId(GET))
=================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from product table by using categoryId with status=1
-->check there is any match from select query
@ -132,7 +140,7 @@ otp section
10.Total items from market count(this week (GET))
=========================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from product_price table by using thisweek data(7days intervel) with status=1
-->check there is any match from select query
@ -145,7 +153,7 @@ otp section
11.Recent News count(This week (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from news table by using thisweek data(7days intervel) with status=1
-->check there is any match from select query
@ -158,7 +166,7 @@ otp section
12. Statewise product with price(productId(GET)
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from market and state table with status=1
-->check there is any match from select query
@ -172,7 +180,7 @@ otp section
13.News category(This week (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from newscategory table with status=1
-->check there is any match from select query
@ -185,7 +193,7 @@ otp section
14.This Week news filter(This week (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from news table by using thisweek data(7days intervel) with status=1
-->check there is any match from select query
@ -198,7 +206,7 @@ otp section
14.Next week news filter(This week (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from news table by using nextweek data(7days intervel) with status=1
-->check there is any match from select query
@ -211,7 +219,7 @@ otp section
15.Last month news filter(This week (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from news table by using lastmonth data(30days intervel) with status=1
-->check there is any match from select query
@ -224,7 +232,7 @@ otp section
16.Custom range news filter(startdate ,enddate (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from news table by using passing start date and end date with status=1
-->check there is any match from select query
@ -237,7 +245,7 @@ otp section
17.List particular news category(NewscategoryId (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from newscategory table by using NewscategoryId with status=1
-->check there is any match from select query
@ -250,7 +258,7 @@ otp section
18.List particular news (NewsId (GET))
==============
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from newstable by using NewsId with status=1
-->check there is any match from select query
@ -263,7 +271,7 @@ otp section
19.Weekly price graph(marketid,productid(GET)
===================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from product_price by using marketid,productid with status=1 with(weekly intervals)
-->check there is any match from select query
@ -276,7 +284,7 @@ otp section
20.monthly price graph(marketid,productid(GET)
===================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from product_price by using marketid,productid with status=1 with(monthly intervals)
-->check there is any match from select query
@ -289,7 +297,7 @@ otp section
20.statewise price graph(stateid,productid(GET)
===================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from product_price by using stateid,productid with status=1
-->check there is any match from select query
@ -302,7 +310,7 @@ otp section
22.View user profile (GET)
===================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->select all details from register by using userId with join of pincodes,plans also
-->check there is any match from select query
@ -315,7 +323,7 @@ otp section
23.Edit user profile((GET)
==================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->get details from get method and post location,email,name into register table
-->check there is any match from select query
@ -327,7 +335,7 @@ otp section
24.Get location by using pincode(GET)
==================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->hit select query by using pincode
-->check there is any match from select query (like query)
@ -340,7 +348,7 @@ otp section
25.24.Get location by using region(GET)
==================
-->using userid and deviceid ,we have to check there is any data in register table with deviceid and userid(this is for check which device is having this app with this mobile number)
-->using mobile,userid and deviceid we have to check json web token matched or not...
-->if yes
-->hit select query by using region name (like query)
-->check there is any match from select query

32
auth/token_validation.js Normal file
View File

@ -0,0 +1,32 @@
const { verify } = require('jsonwebtoken');
module.exports={
checkToken : (req,res,next)=>{
let token=req.get('authorization');
if(token)
{
token=token.slice(7);
verify(token,process.env.JWT_SECRET_KEY,(err,decoded)=>{
if(err)
{
res.json({
"code":"2",
"message":"This mobile number is register on another device please check"
})
}
else
{
next();
}
});
}
else
{
res.json({
"success":"0",
"message":"Unauthorized user Credentials"
})
}
}
}

View File

@ -1,15 +0,0 @@
const WebSocket = require('ws')
const url = 'ws://localhost:9000'
const connection = new WebSocket(url)
connection.onopen = () => {
connection.send("Message From Client")
}
connection.onerror = (error) => {
console.log("WebSocket error:", error)
}
connection.onmessage = (e) => {
console.log(e.data)
}

View File

@ -1,3 +1,4 @@
require('dotenv').config();
var express = require('express');
var bodyparser = require('body-parser');
var mysql = require('mysql');

View File

@ -1,9 +1,9 @@
var mysql = require('mysql');
var connection=mysql.createConnection({
host :'localhost',
user :'root',
password :'',
database :'cma_api'
host :process.env.DB_HOST,
user :process.env.DB_USER,
password :process.env.DB_PASS,
database :process.env.MYSQL_DB
});
connection.connect(function(error){
if(error)

217
node_modules/.package-lock.json generated vendored
View File

@ -6,6 +6,7 @@
"packages": {
"node_modules/@sindresorhus/is": {
"version": "0.14.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6"
@ -13,6 +14,7 @@
},
"node_modules/@szmarczak/http-timer": {
"version": "1.1.2",
"dev": true,
"license": "MIT",
"dependencies": {
"defer-to-connect": "^1.0.1"
@ -23,6 +25,7 @@
},
"node_modules/abbrev": {
"version": "1.1.1",
"dev": true,
"license": "ISC"
},
"node_modules/accepts": {
@ -52,6 +55,7 @@
},
"node_modules/ansi-align": {
"version": "3.0.1",
"dev": true,
"license": "ISC",
"dependencies": {
"string-width": "^4.1.0"
@ -59,6 +63,7 @@
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -66,6 +71,7 @@
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"dev": true,
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
@ -79,6 +85,7 @@
},
"node_modules/anymatch": {
"version": "3.1.2",
"dev": true,
"license": "ISC",
"dependencies": {
"normalize-path": "^3.0.0",
@ -131,6 +138,7 @@
},
"node_modules/balanced-match": {
"version": "1.0.2",
"dev": true,
"license": "MIT"
},
"node_modules/bcrypt-pbkdf": {
@ -149,6 +157,7 @@
},
"node_modules/binary-extensions": {
"version": "2.2.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -175,6 +184,7 @@
},
"node_modules/boxen": {
"version": "5.1.2",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-align": "^3.0.0",
@ -195,6 +205,7 @@
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"dev": true,
"license": "MIT",
"dependencies": {
"balanced-match": "^1.0.0",
@ -203,6 +214,7 @@
},
"node_modules/braces": {
"version": "3.0.2",
"dev": true,
"license": "MIT",
"dependencies": {
"fill-range": "^7.0.1"
@ -211,6 +223,11 @@
"node": ">=8"
}
},
"node_modules/buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
"node_modules/buffer-from": {
"version": "1.1.2",
"license": "MIT"
@ -252,6 +269,7 @@
},
"node_modules/cacheable-request": {
"version": "6.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"clone-response": "^1.0.2",
@ -268,6 +286,7 @@
},
"node_modules/cacheable-request/node_modules/get-stream": {
"version": "5.2.0",
"dev": true,
"license": "MIT",
"dependencies": {
"pump": "^3.0.0"
@ -281,6 +300,7 @@
},
"node_modules/cacheable-request/node_modules/lowercase-keys": {
"version": "2.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -288,6 +308,7 @@
},
"node_modules/camelcase": {
"version": "6.2.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=10"
@ -302,6 +323,7 @@
},
"node_modules/chalk": {
"version": "4.1.2",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.1.0",
@ -316,6 +338,7 @@
},
"node_modules/chalk/node_modules/has-flag": {
"version": "4.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -323,6 +346,7 @@
},
"node_modules/chalk/node_modules/supports-color": {
"version": "7.2.0",
"dev": true,
"license": "MIT",
"dependencies": {
"has-flag": "^4.0.0"
@ -341,6 +365,7 @@
},
"node_modules/chokidar": {
"version": "3.5.2",
"dev": true,
"license": "MIT",
"dependencies": {
"anymatch": "~3.1.2",
@ -360,10 +385,12 @@
},
"node_modules/ci-info": {
"version": "2.0.0",
"dev": true,
"license": "MIT"
},
"node_modules/cli-boxes": {
"version": "2.2.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6"
@ -374,6 +401,7 @@
},
"node_modules/clone-response": {
"version": "1.0.2",
"dev": true,
"license": "MIT",
"dependencies": {
"mimic-response": "^1.0.0"
@ -381,6 +409,7 @@
},
"node_modules/color-convert": {
"version": "2.0.1",
"dev": true,
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
@ -391,6 +420,7 @@
},
"node_modules/color-name": {
"version": "1.1.4",
"dev": true,
"license": "MIT"
},
"node_modules/combined-stream": {
@ -405,6 +435,7 @@
},
"node_modules/concat-map": {
"version": "0.0.1",
"dev": true,
"license": "MIT"
},
"node_modules/concat-stream": {
@ -422,6 +453,7 @@
},
"node_modules/configstore": {
"version": "5.0.1",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"dot-prop": "^5.2.0",
@ -501,6 +533,7 @@
},
"node_modules/crypto-random-string": {
"version": "2.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -537,6 +570,7 @@
},
"node_modules/decompress-response": {
"version": "3.3.0",
"dev": true,
"license": "MIT",
"dependencies": {
"mimic-response": "^1.0.0"
@ -547,6 +581,7 @@
},
"node_modules/deep-extend": {
"version": "0.6.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=4.0.0"
@ -554,6 +589,7 @@
},
"node_modules/defer-to-connect": {
"version": "1.1.3",
"dev": true,
"license": "MIT"
},
"node_modules/delayed-stream": {
@ -604,6 +640,7 @@
},
"node_modules/dot-prop": {
"version": "5.3.0",
"dev": true,
"license": "MIT",
"dependencies": {
"is-obj": "^2.0.0"
@ -612,8 +649,17 @@
"node": ">=8"
}
},
"node_modules/dotenv": {
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-11.0.0.tgz",
"integrity": "sha512-Fp/b504Y5W+e+FpCxTFMUZ7ZEQkQYF0rx+KZtmwixJxGQbLHrhCwo3FjZgNC8vIfrSi29PABNbMoCGD9YoiXbQ==",
"engines": {
"node": ">=12"
}
},
"node_modules/duplexer3": {
"version": "0.1.4",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/ecc-jsbn": {
@ -624,12 +670,21 @@
"safer-buffer": "^2.1.0"
}
},
"node_modules/ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
"dependencies": {
"safe-buffer": "^5.0.1"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"license": "MIT"
},
"node_modules/emoji-regex": {
"version": "8.0.0",
"dev": true,
"license": "MIT"
},
"node_modules/encodeurl": {
@ -641,6 +696,7 @@
},
"node_modules/end-of-stream": {
"version": "1.4.4",
"dev": true,
"license": "MIT",
"dependencies": {
"once": "^1.4.0"
@ -648,6 +704,7 @@
},
"node_modules/escape-goat": {
"version": "2.1.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -773,6 +830,7 @@
},
"node_modules/fill-range": {
"version": "7.0.1",
"dev": true,
"license": "MIT",
"dependencies": {
"to-regex-range": "^5.0.1"
@ -832,6 +890,7 @@
},
"node_modules/get-stream": {
"version": "4.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"pump": "^3.0.0"
@ -849,6 +908,7 @@
},
"node_modules/glob-parent": {
"version": "5.1.2",
"dev": true,
"license": "ISC",
"dependencies": {
"is-glob": "^4.0.1"
@ -859,6 +919,7 @@
},
"node_modules/global-dirs": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"ini": "2.0.0"
@ -872,6 +933,7 @@
},
"node_modules/got": {
"version": "9.6.0",
"dev": true,
"license": "MIT",
"dependencies": {
"@sindresorhus/is": "^0.14.0",
@ -892,6 +954,7 @@
},
"node_modules/graceful-fs": {
"version": "4.2.8",
"dev": true,
"license": "ISC"
},
"node_modules/har-schema": {
@ -914,6 +977,7 @@
},
"node_modules/has-flag": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=4"
@ -921,6 +985,7 @@
},
"node_modules/has-yarn": {
"version": "2.1.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -928,6 +993,7 @@
},
"node_modules/http-cache-semantics": {
"version": "4.1.0",
"dev": true,
"license": "BSD-2-Clause"
},
"node_modules/http-errors": {
@ -973,10 +1039,12 @@
},
"node_modules/ignore-by-default": {
"version": "1.0.1",
"dev": true,
"license": "ISC"
},
"node_modules/import-lazy": {
"version": "2.1.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=4"
@ -984,6 +1052,7 @@
},
"node_modules/imurmurhash": {
"version": "0.1.4",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.8.19"
@ -995,6 +1064,7 @@
},
"node_modules/ini": {
"version": "2.0.0",
"dev": true,
"license": "ISC",
"engines": {
"node": ">=10"
@ -1009,6 +1079,7 @@
},
"node_modules/is-binary-path": {
"version": "2.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"binary-extensions": "^2.0.0"
@ -1024,6 +1095,7 @@
},
"node_modules/is-ci": {
"version": "2.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"ci-info": "^2.0.0"
@ -1034,6 +1106,7 @@
},
"node_modules/is-extglob": {
"version": "2.1.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
@ -1041,6 +1114,7 @@
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -1048,6 +1122,7 @@
},
"node_modules/is-glob": {
"version": "4.0.3",
"dev": true,
"license": "MIT",
"dependencies": {
"is-extglob": "^2.1.1"
@ -1058,6 +1133,7 @@
},
"node_modules/is-installed-globally": {
"version": "0.4.0",
"dev": true,
"license": "MIT",
"dependencies": {
"global-dirs": "^3.0.0",
@ -1072,6 +1148,7 @@
},
"node_modules/is-npm": {
"version": "5.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=10"
@ -1082,6 +1159,7 @@
},
"node_modules/is-number": {
"version": "7.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.12.0"
@ -1089,6 +1167,7 @@
},
"node_modules/is-obj": {
"version": "2.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -1096,6 +1175,7 @@
},
"node_modules/is-path-inside": {
"version": "3.0.3",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -1107,6 +1187,7 @@
},
"node_modules/is-yarn-global": {
"version": "0.3.0",
"dev": true,
"license": "MIT"
},
"node_modules/isarray": {
@ -1123,6 +1204,7 @@
},
"node_modules/json-buffer": {
"version": "3.0.0",
"dev": true,
"license": "MIT"
},
"node_modules/json-schema": {
@ -1137,6 +1219,32 @@
"version": "5.0.1",
"license": "ISC"
},
"node_modules/jsonwebtoken": {
"version": "8.5.1",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
"integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==",
"dependencies": {
"jws": "^3.2.2",
"lodash.includes": "^4.3.0",
"lodash.isboolean": "^3.0.3",
"lodash.isinteger": "^4.0.4",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1",
"semver": "^5.6.0"
},
"engines": {
"node": ">=4",
"npm": ">=1.4.28"
}
},
"node_modules/jsonwebtoken/node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"node_modules/jsprim": {
"version": "1.4.2",
"license": "MIT",
@ -1150,8 +1258,28 @@
"node": ">=0.6.0"
}
},
"node_modules/jwa": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
"integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
"dependencies": {
"buffer-equal-constant-time": "1.0.1",
"ecdsa-sig-formatter": "1.0.11",
"safe-buffer": "^5.0.1"
}
},
"node_modules/jws": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
"dependencies": {
"jwa": "^1.4.1",
"safe-buffer": "^5.0.1"
}
},
"node_modules/keyv": {
"version": "3.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"json-buffer": "3.0.0"
@ -1159,6 +1287,7 @@
},
"node_modules/latest-version": {
"version": "5.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"package-json": "^6.3.0"
@ -1167,8 +1296,44 @@
"node": ">=8"
}
},
"node_modules/lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
"integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8="
},
"node_modules/lodash.isboolean": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
},
"node_modules/lodash.isinteger": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
},
"node_modules/lodash.isnumber": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
"integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w="
},
"node_modules/lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
},
"node_modules/lodash.isstring": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
},
"node_modules/lodash.once": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
},
"node_modules/lowercase-keys": {
"version": "1.0.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
@ -1176,6 +1341,7 @@
},
"node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
@ -1186,6 +1352,7 @@
},
"node_modules/make-dir": {
"version": "3.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"semver": "^6.0.0"
@ -1199,6 +1366,7 @@
},
"node_modules/make-dir/node_modules/semver": {
"version": "6.3.0",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
@ -1261,6 +1429,7 @@
},
"node_modules/mimic-response": {
"version": "1.0.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=4"
@ -1268,6 +1437,7 @@
},
"node_modules/minimatch": {
"version": "3.0.4",
"dev": true,
"license": "ISC",
"dependencies": {
"brace-expansion": "^1.1.7"
@ -1344,8 +1514,10 @@
},
"node_modules/nodemon": {
"version": "2.0.15",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.15.tgz",
"integrity": "sha512-gdHMNx47Gw7b3kWxJV64NI+Q5nfl0y5DgDbiVtShiwa7Z0IZ07Ll4RLFo6AjrhzMtoEZn5PDE3/c2AbVsiCkpA==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"chokidar": "^3.5.2",
"debug": "^3.2.7",
@ -1371,6 +1543,7 @@
},
"node_modules/nodemon/node_modules/debug": {
"version": "3.2.7",
"dev": true,
"license": "MIT",
"dependencies": {
"ms": "^2.1.1"
@ -1378,10 +1551,12 @@
},
"node_modules/nodemon/node_modules/ms": {
"version": "2.1.3",
"dev": true,
"license": "MIT"
},
"node_modules/nopt": {
"version": "1.0.10",
"dev": true,
"license": "MIT",
"dependencies": {
"abbrev": "1"
@ -1392,6 +1567,7 @@
},
"node_modules/normalize-path": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
@ -1399,6 +1575,7 @@
},
"node_modules/normalize-url": {
"version": "4.5.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -1437,6 +1614,7 @@
},
"node_modules/once": {
"version": "1.4.0",
"dev": true,
"license": "ISC",
"dependencies": {
"wrappy": "1"
@ -1444,6 +1622,7 @@
},
"node_modules/p-cancelable": {
"version": "1.1.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6"
@ -1451,6 +1630,7 @@
},
"node_modules/package-json": {
"version": "6.5.0",
"dev": true,
"license": "MIT",
"dependencies": {
"got": "^9.6.0",
@ -1464,6 +1644,7 @@
},
"node_modules/package-json/node_modules/semver": {
"version": "6.3.0",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
@ -1494,6 +1675,7 @@
},
"node_modules/picomatch": {
"version": "2.3.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8.6"
@ -1504,6 +1686,7 @@
},
"node_modules/prepend-http": {
"version": "2.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=4"
@ -1537,10 +1720,12 @@
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"dev": true,
"license": "MIT"
},
"node_modules/pump": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"end-of-stream": "^1.1.0",
@ -1556,6 +1741,7 @@
},
"node_modules/pupa": {
"version": "2.1.1",
"dev": true,
"license": "MIT",
"dependencies": {
"escape-goat": "^2.0.0"
@ -1600,6 +1786,7 @@
},
"node_modules/rc": {
"version": "1.2.8",
"dev": true,
"license": "(BSD-2-Clause OR MIT OR Apache-2.0)",
"dependencies": {
"deep-extend": "^0.6.0",
@ -1613,6 +1800,7 @@
},
"node_modules/rc/node_modules/ini": {
"version": "1.3.8",
"dev": true,
"license": "ISC"
},
"node_modules/readable-stream": {
@ -1630,6 +1818,7 @@
},
"node_modules/readdirp": {
"version": "3.6.0",
"dev": true,
"license": "MIT",
"dependencies": {
"picomatch": "^2.2.1"
@ -1640,6 +1829,7 @@
},
"node_modules/registry-auth-token": {
"version": "4.2.1",
"dev": true,
"license": "MIT",
"dependencies": {
"rc": "^1.2.8"
@ -1650,6 +1840,7 @@
},
"node_modules/registry-url": {
"version": "5.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"rc": "^1.2.8"
@ -1696,6 +1887,7 @@
},
"node_modules/responselike": {
"version": "1.0.2",
"dev": true,
"license": "MIT",
"dependencies": {
"lowercase-keys": "^1.0.0"
@ -1718,6 +1910,7 @@
},
"node_modules/semver-diff": {
"version": "3.1.1",
"dev": true,
"license": "MIT",
"dependencies": {
"semver": "^6.3.0"
@ -1728,6 +1921,7 @@
},
"node_modules/semver-diff/node_modules/semver": {
"version": "6.3.0",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
@ -1785,6 +1979,7 @@
},
"node_modules/signal-exit": {
"version": "3.0.6",
"dev": true,
"license": "ISC"
},
"node_modules/sqlstring": {
@ -1839,6 +2034,7 @@
},
"node_modules/string-width": {
"version": "4.2.3",
"dev": true,
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
@ -1851,6 +2047,7 @@
},
"node_modules/strip-ansi": {
"version": "6.0.1",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
@ -1861,6 +2058,7 @@
},
"node_modules/strip-json-comments": {
"version": "2.0.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
@ -1868,6 +2066,7 @@
},
"node_modules/supports-color": {
"version": "5.5.0",
"dev": true,
"license": "MIT",
"dependencies": {
"has-flag": "^3.0.0"
@ -1878,6 +2077,7 @@
},
"node_modules/to-readable-stream": {
"version": "1.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6"
@ -1885,6 +2085,7 @@
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"dev": true,
"license": "MIT",
"dependencies": {
"is-number": "^7.0.0"
@ -1902,6 +2103,7 @@
},
"node_modules/touch": {
"version": "3.1.0",
"dev": true,
"license": "ISC",
"dependencies": {
"nopt": "~1.0.10"
@ -1937,6 +2139,7 @@
},
"node_modules/type-fest": {
"version": "0.20.2",
"dev": true,
"license": "(MIT OR CC0-1.0)",
"engines": {
"node": ">=10"
@ -1962,6 +2165,7 @@
},
"node_modules/typedarray-to-buffer": {
"version": "3.1.5",
"dev": true,
"license": "MIT",
"dependencies": {
"is-typedarray": "^1.0.0"
@ -1979,10 +2183,12 @@
},
"node_modules/undefsafe": {
"version": "2.0.5",
"dev": true,
"license": "MIT"
},
"node_modules/unique-string": {
"version": "2.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"crypto-random-string": "^2.0.0"
@ -2000,6 +2206,7 @@
},
"node_modules/update-notifier": {
"version": "5.1.0",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"boxen": "^5.0.0",
@ -2026,6 +2233,7 @@
},
"node_modules/update-notifier/node_modules/semver": {
"version": "7.3.5",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
@ -2046,6 +2254,7 @@
},
"node_modules/url-parse-lax": {
"version": "3.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"prepend-http": "^2.0.0"
@ -2104,6 +2313,7 @@
},
"node_modules/widest-line": {
"version": "3.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"string-width": "^4.0.0"
@ -2114,6 +2324,7 @@
},
"node_modules/wrap-ansi": {
"version": "7.0.0",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.0.0",
@ -2129,10 +2340,12 @@
},
"node_modules/wrappy": {
"version": "1.0.2",
"dev": true,
"license": "ISC"
},
"node_modules/write-file-atomic": {
"version": "3.0.3",
"dev": true,
"license": "ISC",
"dependencies": {
"imurmurhash": "^0.1.4",
@ -2162,6 +2375,7 @@
},
"node_modules/xdg-basedir": {
"version": "4.0.0",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -2176,6 +2390,7 @@
},
"node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
}
}

544
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
"start": "nodemon index.js"
},
"author": "",
"license": "ISC",
@ -16,17 +16,21 @@
"crypto": "^1.0.1",
"cryptr": "^6.0.2",
"dateformat": "^5.0.2",
"dotenv": "^11.0.0",
"express": "^4.17.1",
"express-session": "^1.17.2",
"https": "^1.0.0",
"jsonwebtoken": "^8.5.1",
"md5": "^2.3.0",
"msg91": "^0.0.6",
"msg91-sms": "^1.0.1",
"multer": "^1.4.3",
"mysql": "^2.18.1",
"nodemon": "^2.0.15",
"path": "^0.12.7",
"sendotp": "^1.2.9",
"ws": "^8.4.0"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}

View File

@ -1,24 +1,31 @@
require('dotenv').config();
var express = require('express');
var bodyparser = require('body-parser');
var path = require('path');
const async = require('async');
const { sign } = require('jsonwebtoken');
const { checkToken } = require('../auth/token_validation');
var msg91_templateID="61d28c1778947f078d22b313";
var msg91_authkey="154257AQ8i7Tb161d288f4P1";
var devicee_access_check="This mobile number is register on another device please check";
var devicee_access_check="sThis mobile number is register on another device please check";
const http = require("https");
var app = express();
var db= require('../lib/db');
const multer = require('multer');
const { monitorEventLoopDelay } = require('perf_hooks');
const { notEqual } = require('assert');
app.use(bodyparser.json());
//1.getotp
app.post('/getOtp',function(requ,res){
var mob =requ.body.mobile;
var ccode =requ.body.countryCode;
var mobwithccode = ccode + mob;
@ -173,17 +180,23 @@ let otp = bufferObjotp.toString("utf8");
if(alerttype=="success"){
var sql = "UPDATE register SET mobile_verification ="+otp+" ,mobile_verify_status =1 ,device_type="+requ.body.deviceType+" ,device_token="+requ.body.deviceToken+",device_unique_id='"+requ.body.deviceId+"' WHERE id=" +userId;
var response_code="2";
const jsonwebtoken= sign({mobile:requ.body.mobile,userId:userId,deviceId:requ.body.deviceId},process.env.JWT_SECRET_KEY);
let query = db.query(sql,(err, result) => {
if(err) throw err
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"userId": userId,"token":jsonwebtoken}));
});
}
else
{
var sql = "UPDATE register SET mobile_verification ="+otp+" WHERE id=" +userId;
var response_code="3";
let query = db.query(sql,(err, result) => {
if(err) throw err
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"userId": userId}));
});
}
let query = db.query(sql,(err, result) => {
if(err) throw err
rese.send(JSON.stringify({ "code":response_code,"message":alertinfo,"userId": userId}));
});
});
});
@ -256,7 +269,7 @@ app.post('/resendOtp',function(requ,rese){
//=================================
//4. List Plans
app.get('/listPlans',function(req,res){
app.get('/listPlans',checkToken,function(req,res){
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
@ -297,11 +310,8 @@ app.get('/listPlans',function(req,res){
});
//========================
//5.subscribe plans
app.post('/subscribePlans',function(req,res){
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 ){
app.post('/subscribePlans',checkToken,function(req,res){
let date_ob = new Date();
let date = ("0" + date_ob.getDate()).slice(-2);
let month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
@ -358,26 +368,12 @@ let date = ("0" + date_ob.getDate()).slice(-2);
}
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
});
//==================
//6.News
app.get('/listNews',function(req,res){
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 ){
app.get('/listNews',checkToken,function(req,res){
let sql = "SELECT * FROM news WHERE status=1 ORDER BY id DESC";
let query = db.query(sql,(err, results) => {
@ -395,22 +391,12 @@ app.get('/listNews',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": results}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=======================
//7.categories
app.get('/listCategories',function(req,res){
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 ){
app.get('/listCategories',checkToken,function(req,res){
let sql = "SELECT * FROM category WHERE status=1";
let query = db.query(sql,(err, results) => {
@ -445,22 +431,12 @@ app.get('/listCategories',function(req,res){
},
);
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=================================
//8.markets
app.get('/listMarkets',function(req,res){
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 ){
app.get('/listMarkets',checkToken,function(req,res){
let sql = "SELECT m.id,m.location,m.city,m.state,m.country,m.product_id,m.category_id,m.created,m.updated,m.status,m.created_by,m.name as marketName,ca.name as categoryName,c.name as cityName,cn.name as countryName,s.name as stateName FROM market as m LEFT JOIN cities as c ON c.id=m.city LEFT JOIN countries as cn ON cn.id=m.country LEFT JOIN states as s ON s.id=m.state LEFT JOIN category as ca on ca.id=m.category_id WHERE m.status=1";
let query = db.query(sql,(err, results) => {
if(results.length > 0 ){
@ -476,76 +452,56 @@ app.get('/listMarkets',function(req,res){
}
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": results}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//====================
//9.Detailed category info
app.get('/categoryDetail/:categoryId',(req, res) => {
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 ){
let sql="SELECT * FROM product WHERE category_id="+req.params.categoryId+" status=1"
let query = db.query(sql, (err, resultss) => {
if(err) throw err;
if(resultss.length > 0 ){
var process=resultss;
let finalresult=[];
async.eachSeries(
process,
(result,callback) => {
var PID=result.id;
let sql1 = "SELECT DISTINCT market_id as marketCount FROM market_product WHERE product_id="+PID;
db.query(sql1, (err, marCount) => {
var marketCounts=marCount.length;
result.marketCounts=marketCounts;
let resultupdated=result;
finalresult.push(resultupdated);
callback(null,resultupdated);
});
},
(err)=>{
if(err) throw err;
var response_code="1";
var response_msg="success";
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": finalresult}));
},
);
}
else
{
var response_code="0";
var response_msg="No Data";
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": finalresult}));
}
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
app.get('/categoryDetail/:categoryId',checkToken,(req, res) => {
let sql="SELECT * FROM product WHERE category_id="+req.params.categoryId+" and status=1"
let query = db.query(sql, (err, resultss) => {
if(err) throw err;
if(resultss.length > 0 ){
var process=resultss;
let finalresult=[];
async.eachSeries(
process,
(result,callback) => {
var PID=result.id;
let sql1 = "SELECT DISTINCT market_id as marketCount FROM market_product WHERE product_id="+PID;
db.query(sql1, (err, marCount) => {
var marketCounts=marCount.length;
result.marketCounts=marketCounts;
let resultupdated=result;
finalresult.push(resultupdated);
callback(null,resultupdated);
});
},
(err)=>{
if(err) throw err;
var response_code="1";
var response_msg="success";
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": finalresult}));
},
);
}
else
{
var response_code="0";
var response_msg="No Data";
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": finalresult}));
}
});
});
//==========================
//10.Total items from market
app.get('/totalItemFromMarket',function(req,res){
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 ){
app.get('/totalItemFromMarket',checkToken,function(req,res){
let sql = "SELECT count(id)as marketItemCount FROM product_price WHERE created_date > DATE_SUB(NOW(), INTERVAL 1 WEEK) and status=1";
let query = db.query(sql,(err, results) => {
@ -562,22 +518,12 @@ app.get('/totalItemFromMarket',function(req,res){
}
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": results}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==========================
//8. Recent News
app.get('/recentNewsCount',function(req,res){
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 ){
app.get('/recentNewsCount',checkToken,function(req,res){
let sql = "SELECT count(id)as recentNews FROM news WHERE created_date > DATE_SUB(NOW(), INTERVAL 1 WEEK) and status=1";
let query = db.query(sql,(err, results) => {
@ -594,22 +540,12 @@ app.get('/recentNewsCount',function(req,res){
}
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": results}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==========================
//11. statewise product with price using product id
app.get('/statewiseProduct/:productId',function(req,res){
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 ){
app.get('/statewiseProduct/:productId',checkToken,function(req,res){
let sql = "SELECT DISTINCT s.name as stateName, s.id FROM market as m inner join states as s on s.id=m.state where m.status=1";
let query = db.query(sql, (err, resultss) => {
@ -640,22 +576,12 @@ app.get('/statewiseProduct/:productId',function(req,res){
);
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==============================
//12.News category
app.get('/listNewsCategory',function(req,res){
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 ){
app.get('/listNewsCategory',checkToken,function(req,res){
let sql = "SELECT * FROM news_category WHERE status=1 ORDER BY id DESC";
let query = db.query(sql,(err, resultss) => {
@ -673,22 +599,12 @@ app.get('/listNewsCategory',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==========================
//13.This week filter
app.get('/thisweekNews',function(req,res){
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 ){
app.get('/thisweekNews',checkToken,function(req,res){
let sql = "SELECT * FROM news WHERE created_date > DATE_SUB(NOW(), INTERVAL 1 WEEK) and status=1";
let query = db.query(sql,(err, resultss) => {
@ -707,23 +623,13 @@ app.get('/thisweekNews',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==================================
//14.next week filter
app.get('/nextweekNews',function(req,res){
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 ){
app.get('/nextweekNews',checkToken,function(req,res){
let sql = "SELECT * FROM news WHERE created_date >= DATE_ADD(NOW(), INTERVAL 1 WEEK) and status=1";
let query = db.query(sql,(err, resultss) => {
@ -742,23 +648,12 @@ app.get('/nextweekNews',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==========================
//15.last month filter
app.get('/lastmonthNews',function(req,res){
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 ){
app.get('/lastmonthNews',checkToken,function(req,res){
let sql = "SELECT * FROM news WHERE YEAR(created_date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH) AND MONTH(created_date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH) and status=1";
let query = db.query(sql,(err, resultss) => {
@ -777,22 +672,12 @@ app.get('/lastmonthNews',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=================
//16.custom range filter
app.get('/customrangeNews/:startDate/:endDate',function(req,res){
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 ){
app.get('/customrangeNews/:startDate/:endDate',checkToken,function(req,res){
let sql = "select * from news where created_date between '"+req.params.startDate+"' and '"+req.params.endDate+"' and status=1";
let query = db.query(sql,(err, resultss) => {
@ -811,22 +696,12 @@ app.get('/customrangeNews/:startDate/:endDate',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==============
//17.particular news category
app.get('/listNewsCategory/:newsCatId',function(req,res){
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 ){
app.get('/listNewsCategory/:newsCatId',checkToken,function(req,res){
let sql = "SELECT * FROM news where categories="+req.params.newsCatId+" and status=1";
let query = db.query(sql,(err, resultss) => {
@ -844,22 +719,12 @@ app.get('/listNewsCategory/:newsCatId',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=======================
//18.particular news details
app.get('/listNews/:newsId',function(req,res){
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 ){
app.get('/listNews/:newsId',checkToken,function(req,res){
let sql = "SELECT * FROM news where id="+req.params.newsId+" and status=1";
let query = db.query(sql,(err, resultss) => {
@ -877,22 +742,12 @@ app.get('/listNews/:newsId',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//======================
//19.price graph using productid & marketid
app.get('/weeklyPriceGraph/:marketId/:productId',function(req,res){
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 ){
app.get('/weeklyPriceGraph/:marketId/:productId',checkToken,function(req,res){
let sql = "SELECT * FROM product_price where created_date >= DATE_SUB(NOW(), INTERVAL 1 WEEK) and product_id="+req.params.productId+" AND market_id="+req.params.marketId+" and status=1";
let query = db.query(sql,(err, resultss) => {
@ -911,22 +766,12 @@ app.get('/weeklyPriceGraph/:marketId/:productId',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=================
//20.price graph using productid & marketid //lastmonth
app.get('/monthlyPriceGraph/:marketId/:productId',function(req,res){
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 ){
app.get('/monthlyPriceGraph/:marketId/:productId',checkToken,function(req,res){
let sql = "SELECT * FROM product_price where YEAR(created_date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH) AND MONTH(created_date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH) and product_id="+req.params.productId+" AND market_id="+req.params.marketId+" and status=1";
let query = db.query(sql,(err, resultss) => {
@ -946,22 +791,12 @@ app.get('/monthlyPriceGraph/:marketId/:productId',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=====================
//21.price graph using productid & marketid==>pending
app.get('/statewisePriceGraph/:stateId/:productId',function(req,res){
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 ){
app.get('/statewisePriceGraph/:stateId/:productId',checkToken,function(req,res){
let sql = "SELECT pp.*,m.name as marketName FROM product_price as pp left join market as m on m.id=pp.market_id where pp.product_id="+req.params.productId+" AND m.state="+req.params.stateId+" and pp.status=1";
let query = db.query(sql,(err, results) => {
@ -980,22 +815,12 @@ app.get('/statewisePriceGraph/:stateId/:productId',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": results}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//==============================
//22.show user profile
app.get('/viewUserProfile',function(req,res){
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 ){
app.get('/viewUserProfile',checkToken,function(req,res){
let sql = "SELECT pc.id as locationId,pc.pincode,pc.region,pc.taluk,pc.district,pc.state,r.*,p.name as planName FROM register as r inner join plan as p on p.id=r.plan_type left join pincodes as pc on pc.id=r.location where r.id="+req.body.userId+"";
let query = db.query(sql,(err, resultss) => {
@ -1014,22 +839,12 @@ app.get('/viewUserProfile',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//=================
//23.edit user profile
app.get('/editUserProfile',function(req,res){
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 ){
app.get('/editUserProfile',checkToken,function(req,res){
var data={
name:req.body.fullName,
location:req.body.location,
@ -1042,22 +857,12 @@ app.get('/editUserProfile',function(req,res){
var response_msg="Updated Successfully";
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//================
//24.get location by using pincode
app.get('/getLocByPincode',function(req,res){
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 ){
app.get('/getLocByPincode',checkToken,function(req,res){
let sql = "SELECT * FROM pincodes WHERE pincode like '"+req.body.pincode+"%'";
let query = db.query(sql,(err, resultss) => {
@ -1075,23 +880,13 @@ app.get('/getLocByPincode',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//================
//25.get location by using region
app.get('/getLocByRegion',function(req,res){
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 ){
app.get('/getLocByRegion',checkToken,function(req,res){
let sql = "SELECT * FROM pincodes WHERE region like '"+req.body.region+"%'";
console.log(sql);
let query = db.query(sql,(err, resultss) => {
@ -1110,16 +905,221 @@ app.get('/getLocByRegion',function(req,res){
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": resultss}));
});
}
else
{
var response_code="2";
var response_msg=devicee_access_check;
res.send(JSON.stringify({ "code":response_code,"message":response_msg,"data": ""}));
}
});
});
//================
//===========================================================
//************BUY & SELL***************************************** */
//=============================================================
//1.list all seller product category to buyer screeen
app.get('/buysellCategory',checkToken,function(req,res){
let sql = "SELECT * FROM buysell_category WHERE status=1";
let query = db.query(sql,(err, resultss) => {
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}));
});
});
//===================================
//2.list all seller products to buyer screeen
app.get('/buysellProducts',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";
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}));
}
);
}
});
});
//====================
//3.list particular seller products to buyer screeen
app.get('/buysellProducts/: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;
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}));
}
);
}
});
});
//==================
//4.buy filters
app.get('/buyFilter',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.product="+req.body.productId+" and sp.area="+req.body.area+" and sp.qty >= "+req.body.qtyFrom+" AND sp.qty <= "+req.body.qtyTo+" and sp.price_per_unit >= "+req.body.priceFrom+" AND sp.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"}));
}
});
});
//========================
//5.view particular product to buyer
app.get('/viewProduct/: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 query = db.query(sql,(err, resultss) => {
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}));
});
});
//=================
//6.view particular product images
app.get('/viewProductImages/:bPPrimaryId',checkToken,function(req,res){
let sql = "SELECT image from seller_product_images where status=1 and seller_product_primary_id="+req.params.bPPrimaryId;
let query = db.query(sql,(err, resultss) => {
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}));
});
});
//=========================
//7.add buyer products
app.post('/buyerRequestProduct',checkToken,function(req,res){
let data=
{
buyer: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 buyer_products SET ?";
let query = db.query(sql,data,(err, results) => {
if(err) throw err
res.send(JSON.stringify({ "code":"1","message":"success","data": results}));
});
});
//===========================================================
//************API END***************************************** */
@ -1465,5 +1465,5 @@ app.put('/deletePlans/:planId',(req, res) => {
app.listen(8000);
app.listen(process.env.PORT,()=>{console.log(process.env.PORT);});
module.exports = app;

View File

View File

@ -1,57 +0,0 @@
***********************API***********************
Category
--------
GET - List all categories
POST- Create all categories
//<id>
GET - Detailed category info
PUT - Update category info
DELETE - Delete category
Market
-------
GET - List all markets
POST- Create all markets
//<id>
GET - Detailed market info
PUT - Update market info
DELETE - Delete market
Plan
-----
GET - List all plans
POST- Create all plans
//<id>
GET - Detailed plan info
PUT - Update plan info
DELETE - Delete plan
Products
--------
GET - List all products
POST- Create all products
//<id>
GET - Detailed product info
PUT - Update product info
DELETE - Delete product
Cities
------
GET - List all cities
Country
------
GET - List all country
State
------
GET - List all state
measurements
------
GET - List all measurements
Roles
------
GET - List all roles