-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for environment route testing project
- Loading branch information
Sheetal Godara
authored and
Sheetal Godara
committed
Oct 18, 2023
0 parents
commit f25fadc
Showing
25 changed files
with
12,998 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Install NODE | ||
Install MONGODB(for test/dev as local mongodb server needed) | ||
need to install homebrew and xcode-install for mac | ||
git clone to get updated code/files | ||
npm install to install all packages | ||
npm install for devdependecies such as nodemon,morgan,jest,debug(if not already installed) | ||
|
||
npm run test for locally testing files and coverage to see report | ||
npm run dev for running in dev mode using nodemon and debug | ||
npm run start for running no debug and no nodemon and set production so that helmet runs and also different db to be used | ||
|
||
beware of set/export word | ||
And a extra app.env for setting our secret | ||
Git Main Branch to side Branch for non dev/test +app.env | ||
As per env config is used but hide either by terminal or app.env | ||
|
||
First dev | ||
Along test | ||
Then start | ||
Then git to side branch to app.env | ||
Then postman test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"jwtPrivateKey":"settle_jwtPrivateKey", | ||
"db":"settle_db", | ||
"bucketName":"settle_bucketName", | ||
"userid":"settle_userid", | ||
"password":"settle_password", | ||
"AWSSecretKey":"settle_AWSSecretKey", | ||
"AWSAccessKey":"settle_AWSAccessKey" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name":"Settle", | ||
"jwtPrivateKey":"123", | ||
"bucketName":"1", | ||
"AWSAccessKey":"2", | ||
"AWSSecretKey":"3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name":"Settle - development", | ||
"db":"mongodb://localhost/playground" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name":"Settle -production", | ||
"db":"mongodb://localhost/playground" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"jwtPrivateKey":"1234", | ||
"db":"mongodb://localhost/playground_tests" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const startupDebugger = require('debug')('app:startup'); | ||
const dbDebugger = require('debug')('app:db'); | ||
const express = require('express'); | ||
const app = express(); | ||
const winston = require('winston'); | ||
|
||
require('./startup/config')(); | ||
const logger = require('./startup/logging'); | ||
|
||
if(app.get('env')=== 'production'){ | ||
require('./startup/prod')(app); | ||
app.use((req, res, next) => { | ||
const start = Date.now(); | ||
res.on('finish', () => { | ||
const responseTime = Date.now() - start; | ||
const userAgent = req.headers['user-agent'] || 'Unknown'; | ||
const authToken = req.headers['x-auth-token'] || 'N/A';//maybe avoid and do this for erroror to seelog of unwanted request whomaking | ||
logger.info(`${req.ip} - ${userAgent} - Auth Token: ${authToken} - ${req.method} ${req.originalUrl} - ${res.statusCode} - ${responseTime}ms`); | ||
//logger.info(`${req.ip} - ${req.method} ${req.originalUrl} - ${res.statusCode} - ${responseTime}ms`); | ||
}); | ||
next(); | ||
}); | ||
} | ||
|
||
|
||
process.on('unhandledRejections',(ex) =>{ | ||
//console.log(ex) | ||
throw ex;//convert unhandled to uncaught for winston | ||
}); | ||
|
||
//set DEBUG=app:startup,set by NODE_ENV=development | ||
if((app.get('env')=== 'development')||(app.get('env')=== 'test') ){ | ||
const morgan = require('morgan'); | ||
app.use(morgan('tiny')); | ||
//app.use(morgan('dev')); | ||
|
||
startupDebugger('Morgan enabled...') | ||
} | ||
|
||
require('./startup/routes')(app); | ||
require('./startup/db')(); | ||
require('./startup/validate')(); | ||
|
||
|
||
|
||
//not work as already return otherwise move this code it will show authentication | ||
/* | ||
app.use(function(req,res,next){ | ||
winston.info('authentication ...'); | ||
next(); | ||
}); | ||
*/ | ||
|
||
const port = process.env.PORT||3000 | ||
const server = app.listen(port,()=>logger.info(`listening to port ${port}...`)); | ||
module.exports = server |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const logger = require('../startup/logging'); | ||
module.exports = function(err,req,res,next){ | ||
// error warn info verbose debug silly->message and err object stak trace | ||
logger.log('error',err.message,err); | ||
res.status(500).send(err);//500 for internal mongodb error can be changed to error .message or err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const axios = require("axios"); | ||
const config = require('config'); | ||
const logger = require('../startup/logging'); | ||
|
||
|
||
async function sendmessage(send_to, message,TemplateId) { | ||
const urlencodedmessage = encodeURIComponent(message); | ||
const options = { | ||
method: 'POST', | ||
url: 'https://enterpriseapi.smsgupshup.com/GatewayAPI/rest', | ||
data: { | ||
method: 'sendMessage', | ||
send_to: send_to, | ||
msg: urlencodedmessage, | ||
msg_type: 'TEXT', | ||
v:'1.1', | ||
userid: config.get('userid'), | ||
auth_scheme: 'PLAIN', | ||
password: config.get('password'), | ||
format: 'TEXT', | ||
principalEntityId:'1601568168456313537', | ||
dltTemplateId:TemplateId | ||
} | ||
}; | ||
|
||
const requestURL = options.url + '?method=' + options.data.method + | ||
'&send_to=' + options.data.send_to + | ||
'&msg=' + options.data.msg + | ||
'&msg_type=' + options.data.msg_type + | ||
'&userid=' + options.data.userid + | ||
'&auth_scheme=' + options.data.auth_scheme + | ||
'&password=' + options.data.password + | ||
'&format=' + options.data.format; | ||
console.log(requestURL); | ||
logger.info('Final URL:'+ requestURL); | ||
|
||
|
||
const response = await axios(options); | ||
if (response.status === 200) { | ||
//console.log(response); | ||
//console.log('Message sent successfully'); | ||
return true; | ||
} | ||
} | ||
|
||
module.exports = sendmessage; | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const Joi = require('joi'); | ||
Joi.objectId = require('joi-objectid')(Joi) | ||
|
||
const mongoose = require('mongoose'); | ||
|
||
const KhataSchema = new mongoose.Schema({ | ||
friendName:{type:String,required:true,minLength:1}, | ||
friendPhoneNumber:{type:String,required:true,match: /^[0-9]{10}$/}, | ||
interestRate:{type:Number,required:true,min:0,max:100,default:0}, | ||
interestType:{type:String,required:true,enum:['N','S','CW','CM','CY']} | ||
}); | ||
|
||
const Khata = mongoose.model('Khata',KhataSchema); | ||
|
||
function validateKhata(khata){ | ||
const schema=Joi.object({ | ||
friendName:Joi.string().min(1).required(), | ||
friendPhoneNumber:Joi.string().regex(/^[0-9]{10}$/).messages({'string.pattern.base': `Phone number must have 10 digits.`}).required(), | ||
interestRate:Joi.number().required().min(0).max(100).required(), | ||
interestType:Joi.string().valid('S', 'N', 'CY', 'CW', 'CM').required(), | ||
}); | ||
return schema.validate(khata); | ||
} | ||
|
||
exports.Khata = Khata; | ||
exports.validate = validateKhata; |
Oops, something went wrong.