initialPUSH:GWM
This commit is contained in:
parent
87fa39c2a0
commit
f150df4efb
53
.gitignore
vendored
53
.gitignore
vendored
@ -1,50 +1,3 @@
|
|||||||
# These are some examples of commonly ignored file patterns.
|
/node_modules
|
||||||
# You should customize this list as applicable to your project.
|
/storage
|
||||||
# Learn more about .gitignore:
|
.env
|
||||||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
|
||||||
|
|
||||||
# Node artifact files
|
|
||||||
node_modules/
|
|
||||||
dist/
|
|
||||||
|
|
||||||
# Compiled Java class files
|
|
||||||
*.class
|
|
||||||
|
|
||||||
# Compiled Python bytecode
|
|
||||||
*.py[cod]
|
|
||||||
|
|
||||||
# Log files
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# Package files
|
|
||||||
*.jar
|
|
||||||
|
|
||||||
# Maven
|
|
||||||
target/
|
|
||||||
dist/
|
|
||||||
|
|
||||||
# JetBrains IDE
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# Unit test reports
|
|
||||||
TEST*.xml
|
|
||||||
|
|
||||||
# Generated by MacOS
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Generated by Windows
|
|
||||||
Thumbs.db
|
|
||||||
|
|
||||||
# Applications
|
|
||||||
*.app
|
|
||||||
*.exe
|
|
||||||
*.war
|
|
||||||
|
|
||||||
# Large media files
|
|
||||||
*.mp4
|
|
||||||
*.tiff
|
|
||||||
*.avi
|
|
||||||
*.flv
|
|
||||||
*.mov
|
|
||||||
*.wmv
|
|
||||||
|
|
||||||
|
|||||||
16
app/config/db.config.js
Normal file
16
app/config/db.config.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const { logMsg } = require('../services/logger');
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
"development": {
|
||||||
|
"username": process.env.USER_NAME,
|
||||||
|
"password": process.env.PASSWORD,
|
||||||
|
"database": process.env.DATABASE,
|
||||||
|
"port": process.env.PORT,
|
||||||
|
"host": process.env.HOST,
|
||||||
|
"dialect": "mssql",
|
||||||
|
"logging": (message) =>(logMsg.info(message))
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
20
app/controllers/test.controller.js
Normal file
20
app/controllers/test.controller.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const { sequelize,Test} = require('../models')
|
||||||
|
const { logMsg } = require('../services/logger.js');
|
||||||
|
|
||||||
|
exports.Welcome = (req, res) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const Msg = "Welcome....!";
|
||||||
|
console.log(Msg);
|
||||||
|
logMsg.info("Api Call Success");
|
||||||
|
res.send({'status':200 , message:"Success." ,'data': Msg});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch(err) {
|
||||||
|
res.status(500).send({'status':404,
|
||||||
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||||
|
}); } //end of try catch
|
||||||
|
|
||||||
|
};
|
||||||
39
app/controllers/working.notes.controller.js
Normal file
39
app/controllers/working.notes.controller.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const { sequelize,Workingnotes} = require('../models')
|
||||||
|
const { logMsg } = require('../services/logger.js');
|
||||||
|
|
||||||
|
exports.createNotes = async (req, res) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Workingnotes.create(req.body);
|
||||||
|
res.send({'status':200 , message:"Success." ,'data': "no data"});
|
||||||
|
|
||||||
|
} catch(err) {
|
||||||
|
res.status(500).send({'status':404,
|
||||||
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||||
|
}); } //end of try catch
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.notesList = async (req, res) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(req.query.entity_reference == undefined)
|
||||||
|
{
|
||||||
|
notesData = await Workingnotes.findAll({where :{losid : req.query.losid , module_name : req.query.module_name}});
|
||||||
|
res.send({'status':200 , message:"Success." ,'data': notesData});
|
||||||
|
}else{
|
||||||
|
notesData = await Workingnotes.findAll({where :{losid : req.query.losid , module_name : req.query.module_name , entity_reference : req.query.entity_reference}});
|
||||||
|
res.send({'status':200 , message:"Success." ,'data': notesData});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch(err) {
|
||||||
|
res.status(500).send({'status':404,
|
||||||
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||||
|
}); } //end of try catch
|
||||||
|
|
||||||
|
};
|
||||||
31
app/models/Test.js
Normal file
31
app/models/Test.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
'use strict'
|
||||||
|
const { Model } = require('sequelize')
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
class Test extends Model {
|
||||||
|
/**
|
||||||
|
* Helper method for defining associations.
|
||||||
|
* This method is not a part of Sequelize lifecycle.
|
||||||
|
* The `models/index` file will call this method automatically.
|
||||||
|
*/
|
||||||
|
// define association here
|
||||||
|
// static associate({ Financials }) {
|
||||||
|
// this.hasMany(Financials, { foreignKey: 'entity_id', as: 'financialsData' })
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
Test.init(
|
||||||
|
{
|
||||||
|
losid: { type: DataTypes.STRING },
|
||||||
|
createdby: { type: DataTypes.INTEGER },
|
||||||
|
updatedby: { type: DataTypes.INTEGER },
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
tableName: 'test',
|
||||||
|
modelName: 'Test',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return Test
|
||||||
|
}
|
||||||
36
app/models/Workingnotes.js
Normal file
36
app/models/Workingnotes.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict'
|
||||||
|
const { Model } = require('sequelize')
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
class Workingnotes extends Model {
|
||||||
|
/**
|
||||||
|
* Helper method for defining associations.
|
||||||
|
* This method is not a part of Sequelize lifecycle.
|
||||||
|
* The `models/index` file will call this method automatically.
|
||||||
|
*/
|
||||||
|
// define association here
|
||||||
|
// static associate({ Financials }) {
|
||||||
|
// this.hasMany(Financials, { foreignKey: 'entity_id', as: 'financialsData' })
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
Workingnotes.init(
|
||||||
|
{
|
||||||
|
losid: { type: DataTypes.STRING },
|
||||||
|
module_name: { type: DataTypes.STRING },
|
||||||
|
entity_reference: { type: DataTypes.STRING },
|
||||||
|
notes: { type: DataTypes.STRING },
|
||||||
|
user_id: { type: DataTypes.INTEGER },
|
||||||
|
is_active: { type: DataTypes.INTEGER },
|
||||||
|
createdby: { type: DataTypes.INTEGER },
|
||||||
|
updatedby: { type: DataTypes.INTEGER },
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
tableName: 'working_notes',
|
||||||
|
modelName: 'Workingnotes',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return Workingnotes
|
||||||
|
}
|
||||||
39
app/models/index.js
Normal file
39
app/models/index.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
const basename = path.basename(__filename);
|
||||||
|
const env = process.env.NODE_ENV || 'development';
|
||||||
|
const config = require(__dirname + '/../config/db.config.js')[env];
|
||||||
|
//console.log(env);
|
||||||
|
//console.log(config);
|
||||||
|
const db = {};
|
||||||
|
|
||||||
|
let sequelize;
|
||||||
|
if (config.use_env_variable) {
|
||||||
|
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||||
|
} else {
|
||||||
|
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs
|
||||||
|
.readdirSync(__dirname)
|
||||||
|
.filter(file => {
|
||||||
|
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||||
|
})
|
||||||
|
.forEach(file => {
|
||||||
|
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
|
||||||
|
db[model.name] = model;
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.keys(db).forEach(modelName => {
|
||||||
|
if (db[modelName].associate) {
|
||||||
|
db[modelName].associate(db);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
db.sequelize = sequelize;
|
||||||
|
db.Sequelize = Sequelize;
|
||||||
|
|
||||||
|
module.exports = db;
|
||||||
110
app/routes/routes.js
Normal file
110
app/routes/routes.js
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
module.exports = app => {
|
||||||
|
const request = require("request");
|
||||||
|
const cors=require('cors');
|
||||||
|
const Mycontroller = require("../controllers/test.controller.js");
|
||||||
|
const Notescontroller = require("../controllers/working.notes.controller.js");
|
||||||
|
const { logMsg } = require('../services/logger.js');
|
||||||
|
var router = require("express").Router();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/demo:
|
||||||
|
* get:
|
||||||
|
* summary: Demo Api
|
||||||
|
* description: Welcome Message
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: success
|
||||||
|
*/
|
||||||
|
router.get("/demo", Mycontroller.Welcome);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/notesList:
|
||||||
|
* get:
|
||||||
|
* summary: view notes list
|
||||||
|
* description:
|
||||||
|
* parameters:
|
||||||
|
* - in: query
|
||||||
|
* name: losid
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* required: true
|
||||||
|
* - in: query
|
||||||
|
* name: module_name
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* required: true
|
||||||
|
* - in: query
|
||||||
|
* name: entity_reference
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* required: false
|
||||||
|
* example:
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: success
|
||||||
|
*/
|
||||||
|
router.get("/notesList", Notescontroller.notesList);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* definitions:
|
||||||
|
* createNotes:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* losid:
|
||||||
|
* type: string
|
||||||
|
* description: losid
|
||||||
|
* example: MW112233
|
||||||
|
* module_name:
|
||||||
|
* type: string
|
||||||
|
* description: gst (module_name)
|
||||||
|
* example: gst
|
||||||
|
* entity_reference:
|
||||||
|
* type: string
|
||||||
|
* description: (gst_no/cin_no)->entity_
|
||||||
|
* example: cin756kjbjh76
|
||||||
|
* notes:
|
||||||
|
* type: string
|
||||||
|
* description:
|
||||||
|
* example: notes...
|
||||||
|
* user_id:
|
||||||
|
* type: integer
|
||||||
|
* description:
|
||||||
|
* example: 1
|
||||||
|
* createdby:
|
||||||
|
* type: integer
|
||||||
|
* description:
|
||||||
|
* example: 1
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/createNotes:
|
||||||
|
* post:
|
||||||
|
* summary: Pull SalesPd Data
|
||||||
|
* description: Pull SalesPd Data
|
||||||
|
* requestBody:
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/definitions/createNotes'
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: success
|
||||||
|
* 500:
|
||||||
|
* description: failed
|
||||||
|
*/
|
||||||
|
router.post("/createNotes", Notescontroller.createNotes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// routes started here
|
||||||
|
app.use('/api', router);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
27
app/services/logger.js
Normal file
27
app/services/logger.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Configurations of logger.
|
||||||
|
*/
|
||||||
|
var winston = require('winston');
|
||||||
|
require('winston-daily-rotate-file');
|
||||||
|
|
||||||
|
var transport = new winston.transports.DailyRotateFile({
|
||||||
|
filename: 'storage/log/msg.log',
|
||||||
|
datePattern: 'YYYY-MM-DD',
|
||||||
|
zippedArchive: true,
|
||||||
|
maxSize: '20m',
|
||||||
|
maxFiles: '14d'
|
||||||
|
});
|
||||||
|
|
||||||
|
transport.on('rotate', function(oldFilename, newFilename) {
|
||||||
|
// do something fun
|
||||||
|
});
|
||||||
|
|
||||||
|
const logger = winston.createLogger({
|
||||||
|
transports: [
|
||||||
|
transport
|
||||||
|
]
|
||||||
|
});
|
||||||
|
module.exports = {
|
||||||
|
'logMsg': logger,
|
||||||
|
};
|
||||||
|
|
||||||
3737
package-lock.json
generated
Normal file
3737
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "smc_cet_workingnotes_backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "nodemon server.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"body-parser": "^1.19.0",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"log4js": "^6.3.0",
|
||||||
|
"mssql": "^7.2.0",
|
||||||
|
"request": "^2.88.2",
|
||||||
|
"sequelize": "^6.6.5",
|
||||||
|
"swagger-jsdoc": "^6.1.0",
|
||||||
|
"swagger-ui-express": "^4.1.6",
|
||||||
|
"sync": "^0.2.5",
|
||||||
|
"winston": "^3.3.3",
|
||||||
|
"winston-daily-rotate-file": "^4.5.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
62
server.js
Normal file
62
server.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
require('dotenv').config();
|
||||||
|
const express = require('express')
|
||||||
|
const app = express()
|
||||||
|
//it is used to clear cache
|
||||||
|
app.use(function(req, res, next) {
|
||||||
|
res.set("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0")
|
||||||
|
res.set("Pragma", "no-cache")
|
||||||
|
res.set("Expires", 0)
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
const {logMsg} = require('./app/services/logger.js');
|
||||||
|
|
||||||
|
const swaggerJsdoc = require('swagger-jsdoc');
|
||||||
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
definition: {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: {
|
||||||
|
title: 'Smc_cet_working_notes',
|
||||||
|
version: '1.0.0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
apis: ['./app/routes/routes.js'], // files containing annotations as above
|
||||||
|
};
|
||||||
|
|
||||||
|
const swaggerDocument = swaggerJsdoc(options);
|
||||||
|
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /:
|
||||||
|
* get:
|
||||||
|
* description: Welcome to swagger-jsdoc!
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Returns a mysterious string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
res.json({ message: "Welcome to the application." });
|
||||||
|
logMsg.info("Server Sent A Welcome to the application!");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.use(express.json())
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
|
||||||
|
require("./app/routes/routes.js")(app);
|
||||||
|
|
||||||
|
const PORT_NUMBER = process.env.SERVER_PORT
|
||||||
|
app.listen({ port: PORT_NUMBER }, async () => {
|
||||||
|
console.log('Server up on http://localhost:'+PORT_NUMBER)
|
||||||
|
|
||||||
|
//await sequelize.authenticate()
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user