Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Dev #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified README.md
Binary file not shown.
34 changes: 34 additions & 0 deletions _helpers/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const mongoose = require("mongoose");
const environment = require("../environment");
const defaultUserSetting = require("../models/defaultUserSetting");

mongoose.Promise = global.Promise;

mongoose
.connect(environment.mongoDbConnectionString, {useNewUrlParser: true})
.then(() => {
console.log("DB connected");
})
.catch((err) => {
console.log(err);
});

module.exports = {
members: require("../models/member.model"),
admin: require("../models/admin.model"),
role: require("../models/role.model"),
otp: require("../models/otp.model"),
payment: require("../models/payment"),
feedback: require("../models/feedback.model"),
packages: require("../models/packages.model"),
upis: require("../models/upi"),
wallet: require("../models/wallet"),
withdraw: require("../models/withdraw.model"),
game: require("../models/game.model"),
game2: require("../models/game2.model"),
game1F: require("../models/game1F.model"),
game2F: require("../models/game2F.model"),
profit: require("../models/profit"),
orderId: require("../models/orderId.model"),
subscription: require("../models/subscribedUser"),
};
21 changes: 21 additions & 0 deletions _helpers/error-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = errorHandler;

function errorHandler(err, req, res, next) {
if (typeof (err) === 'string') {
// custom application error
return res.status(400).json({ message: err });
}

if (err.name === 'ValidationError') {
// mongoose validation error
return res.status(400).json({ message: err.message });
}

if (err.name === 'UnauthorizedError') {
// jwt authentication error
return res.status(401).json({ message: 'Invalid Token' });
}

// default to 500 server error
return res.status(500).json({ message: err.message });
}
88 changes: 88 additions & 0 deletions _helpers/helperMethods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

function fn_filter(query) {
query = JSON.parse(query);
// let filter;
// if(query.filterValue!=undefined||query.filterkey!=undefined){
// var filterkey=JSON.stringify(query.filterkey);
// var filterValue=JSON.stringify(query.filterValue);
// let obj={
// filterkey,
// filterValue
// }
// delete query.filterValue; delete query.filterkey;
// filter=JSON.parse(`{${obj.filterkey}:${obj.filterValue}}`)
// }
// filter=Object.assign(filter,query);


let filter = {};
for (let i = 0; i < query.length; i++) {
if (query[i].filterValue != undefined || query[i].filterkey != undefined) {
var filterkey = query[i].filterkey;
var filterValue = query[i].filterValue;
let obj = {
filterkey,
filterValue
}
delete query[i].filterValue; delete query[i].filterkey;
// console.log("for Loop",filter);
filter[obj.filterkey] = obj.filterValue;
}
}
let where = [];
for (let [col, data] of Object.entries(filter)) {
//console.log("col",`${col}: ${data}`);
for (let [operator, value] of Object.entries(data)) {
//console.log("Oprator",`${operator}: ${value}`);
switch (operator) {
case 'eq': {
//where.push({ [col]: new RegExp('/^' + value + '/i') }) //exact match case insensitive, i represents insensitive
//where.push({ [col]: { $regex: '/' + value + '/' } })
where.push({ [col]: new RegExp('^' + value + '') })
break;
}
case 'ne': {
where.push({ [col]: { $regex: value } })
break;
}
case 'contains': {
where.push({ [col]: new RegExp(value, "i") })// "like"
break;
}
case 'beginsWith': {
where.push({ [col]: new RegExp('/^O /' + value + '') })
//where.push({ col: { $regex: /^O /, $options: 'm' } })
break;
}
case 'ge': {
where.push({ [col]: { $gte: value } })
break;
}
case 'gt': {
where.push({ [col]: { $gt: value } })
break;
}
case 'lt': {
where.push({ [col]: { $lt: value } })
break;
}
case 'lte': {
where.push({ [col]: { $lte: value } })
break;
}
case 'between': {
where.push({ [col]: { $gte: value[0], $lte: value[1] } })
break;
}
default:
break;
}
}
}

return where;
}

module.exports = {
fn_filter
}
30 changes: 30 additions & 0 deletions _helpers/jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const expressJwt = require('express-jwt');
//const config = require('config.json');
//const userService = require('../users/user.service');

module.exports = jwt;

function jwt() {
const secret = 'SOME SECRET VALUE';// config.secret;
return expressJwt({ secret, isRevoked }).unless({
path: [
// public routes that don't require authentication
'/users/authenticate',
'/users/register'
]
});
}

async function isRevoked(req, payload, done) {
// const user = await userService.getById(payload.sub);

// // revoke token if user no longer exists
// if (!user) {
// return done(null, true);
// }


return done(null, true);

//done();
};
45 changes: 45 additions & 0 deletions _helpers/sms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var request = require("request");
const db = require("../_helpers/db");
const express = require("express");



function SendOtp(mobile) {


const OTP = Math.floor(000000 + Math.random() * 999999);
console.log(OTP)

var options = {
method: "GET",
url: "https://api.authkey.io/request",
qs: {
authkey: "14f46e8842e516f7",
sms: `Use ${OTP} as your OTP to access your {#company#}, OTP is confidential and valid for {#time#}`,
mobile:`${mobile}`,
sender: "AUTHKY",
template: "Authkey otp message"

},


};
console.log(options)

request(options, function (error, response, body) {
if (error) {
console.log("error sms");
console.log(error);
}

console.log(body);


});

//2. save mobilenumber and otp in smslog table
}

module.exports = {
SendOtp,
};
80 changes: 80 additions & 0 deletions controllers/admin.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const express = require("express");
const router = express.Router();
const adminService = require("../service/admin.service");

router.get("/:id", read);
router.get("/", readAll);
router.post("/deleted", deletedMember);
router.post("/", add);
router.put("/:id", update);
router.put("/update/:id", update1);
router.delete("/:id", remove);
router.get("/user/:_id", readByUser);
router.post("/user1/:_id", readByUser1);
router.get("/user2/:_id", readByUser2);

function readByUser(req, res, next) {
adminService
.readByUser(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function readByUser2(req, res, next) {
adminService
.readByUser2(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function readByUser1(req, res, next) {
adminService
.readByUser1(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}

function add(req, res, next) {
console.log(req.body);
adminService
.add(req, res)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function update(req, res, next) {
adminService
.update(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function update1(req, res, next) {
adminService
.update1(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function remove(req, res, next) {
adminService
.remove(req, res, next)
.then((data) => res.send(data))
.catch((err) => next(err));
}

function read(req, res, next) {
adminService
.read(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function readAll(req, res, next) {
adminService
.readAll(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function deletedMember(req, res, next) {
adminService
.deletedMember(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}

module.exports = router;
51 changes: 51 additions & 0 deletions controllers/defaultUserSetting.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const express = require("express");
const router = express.Router();
const defaultUserSettingService = require("../service/defaultUserSetting.service");

router.get("/:id", read);
router.get("/", readAll);
router.get("/state/:stateId", readByState);
router.post("/", add);
router.put("/:id", update);
router.delete("/:id", remove);

function add(req, res, next) {
console.log(req.body)
defaultUserSettingService
.add(req,res)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function update(req, res, next) {
defaultUserSettingService
.update(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function remove(req, res, next) {
defaultUserSettingService
.remove(req,res,next)
.then((data) => res.send(data))
.catch((err) => next(err));
}

function read(req, res, next) {
defaultUserSettingService
.read(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function readAll(req, res, next) {
defaultUserSettingService
.readAll(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function readByState(req, res, next) {
defaultUserSettingService
.readByState(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}

module.exports = router;
23 changes: 23 additions & 0 deletions controllers/emailRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require("express");
const router = express.Router();

const sendEmail1 = require("../service/sendEmail");

router.post("/sendEmail", send);
router.get("/", readAll);

function send(req, res, next) {
console.log(req.body)
sendEmail1
.sendEmail(req,res)
.then((data) => res.send(data))
.catch((err) => next(err));
}
function readAll(req, res, next) {
sendEmail1
.readAll(req)
.then((data) => res.send(data))
.catch((err) => next(err));
}

module.exports = router;
Loading