npm-module-nodejs 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of npm-module-nodejs might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/config/constant.js +5 -0
- package/index.js +36 -0
- package/models/EmployeeData.js +66 -0
- package/package.json +28 -0
- package/routes/EmployeeAPI.js +119 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Squbix
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Add Numbers
|
2
|
+
=========
|
3
|
+
|
4
|
+
A small library that adds two numbers
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
`npm install @jdaudier/number-formatter`
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
var numFormatter = require('@jdaudier/number-formatter');
|
13
|
+
|
14
|
+
var formattedNum = numFormatter(35666);
|
15
|
+
|
16
|
+
|
17
|
+
Output should be `35,666`
|
18
|
+
|
19
|
+
|
20
|
+
## Tests
|
21
|
+
|
22
|
+
`npm test`
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
|
@@ -0,0 +1,5 @@
|
|
1
|
+
var Network = {
|
2
|
+
dev : "mongodb+srv://suryakant1996:Surya%407787@cluster0.e9njntp.mongodb.net/Squbix_Database?retryWrites=true&w=majority",
|
3
|
+
prod: "mongodb+srv://SqubixDigital:Nigam12345Squbix12345@cluster0.pi9wrt0.mongodb.net/Squbix-Digital?retryWrites=true&w=majority"
|
4
|
+
}
|
5
|
+
module.exports = { Network };
|
package/index.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
const express = require('express');
|
2
|
+
const mongoose = require('mongoose');
|
3
|
+
const bodyParser = require('body-parser');
|
4
|
+
const employeeRoutes = require('./routes/EmployeeAPI');
|
5
|
+
|
6
|
+
|
7
|
+
require("dotenv").config({ path: "./.env" });
|
8
|
+
const app = express();
|
9
|
+
var cors = require('cors');
|
10
|
+
const { Network } = require('./config/constant');
|
11
|
+
app.use(cors())
|
12
|
+
app.options('*', cors())
|
13
|
+
const PORT = process.env.PORT || 5007;
|
14
|
+
// Connect to the database
|
15
|
+
mongoose
|
16
|
+
.connect(Network.dev, { useNewUrlParser: true })
|
17
|
+
.then(() => console.log(`Database connected successfully`))
|
18
|
+
.catch((err) => console.log(err));
|
19
|
+
// Since mongoose's Promise is deprecated, we override it with Node's Promise
|
20
|
+
mongoose.Promise = global.Promise;
|
21
|
+
app.use((req, res, next) => {
|
22
|
+
res.header('Access-Control-Allow-Origin', '*');
|
23
|
+
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
24
|
+
res.header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
|
25
|
+
res.header("Access-Control-Allow-Headers: Authorization");
|
26
|
+
next();
|
27
|
+
});
|
28
|
+
app.use(bodyParser.json());
|
29
|
+
app.use(employeeRoutes);
|
30
|
+
app.use((err, req, res, next) => {
|
31
|
+
console.log(err);
|
32
|
+
next();
|
33
|
+
});
|
34
|
+
app.listen(PORT, () => {
|
35
|
+
console.log(`Server running on PORT ${PORT}`);
|
36
|
+
});
|
@@ -0,0 +1,66 @@
|
|
1
|
+
const { Timestamp } = require("mongodb");
|
2
|
+
const mongoose = require("mongoose");
|
3
|
+
|
4
|
+
const EmployeeSchema = new mongoose.Schema({
|
5
|
+
name: {
|
6
|
+
type: String,
|
7
|
+
required: true,
|
8
|
+
trim: true,
|
9
|
+
},
|
10
|
+
email: {
|
11
|
+
type: String,
|
12
|
+
required: true,
|
13
|
+
trim: true,
|
14
|
+
lowercase: true,
|
15
|
+
unique: true
|
16
|
+
},
|
17
|
+
designation: {
|
18
|
+
type: String,
|
19
|
+
required: true,
|
20
|
+
trim: true,
|
21
|
+
},
|
22
|
+
employee_id: {
|
23
|
+
type: String,
|
24
|
+
required: true,
|
25
|
+
trim: true,
|
26
|
+
unique: true
|
27
|
+
},
|
28
|
+
joining_date: {
|
29
|
+
type: String,
|
30
|
+
required: true,
|
31
|
+
trim: true,
|
32
|
+
},
|
33
|
+
phone_number: {
|
34
|
+
type: String,
|
35
|
+
required: true,
|
36
|
+
trim: true,
|
37
|
+
unique: true
|
38
|
+
},
|
39
|
+
address: {
|
40
|
+
type: String,
|
41
|
+
required: true,
|
42
|
+
trim: true,
|
43
|
+
},
|
44
|
+
dob: {
|
45
|
+
type: String,
|
46
|
+
required: true,
|
47
|
+
trim: true,
|
48
|
+
},
|
49
|
+
leaving_date: {
|
50
|
+
type: String,
|
51
|
+
trim: true,
|
52
|
+
},
|
53
|
+
timestamp:{
|
54
|
+
type:Date
|
55
|
+
},
|
56
|
+
employee_status:{
|
57
|
+
type: String,
|
58
|
+
trim: true,
|
59
|
+
},
|
60
|
+
},{collection: 'employee_details'},{
|
61
|
+
versionKey: false // You should be aware of the outcome after set to false
|
62
|
+
},{ timestamps: true });
|
63
|
+
|
64
|
+
const Employee = mongoose.model("employee_details", EmployeeSchema);
|
65
|
+
|
66
|
+
module.exports = Employee;
|
package/package.json
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"name": "npm-module-nodejs",
|
3
|
+
"version": "1.0.2",
|
4
|
+
"description": "Npm module test",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
8
|
+
"start": "nodemon index.js"
|
9
|
+
},
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "git+https://github.com/Squbix-Digital-Private-Limited/npm-module-nodejs.git"
|
13
|
+
},
|
14
|
+
"keywords": [],
|
15
|
+
"author": "“Suryakant”",
|
16
|
+
"license": "MIT",
|
17
|
+
"bugs": {
|
18
|
+
"url": "https://github.com/Squbix-Digital-Private-Limited/npm-module-nodejs/issues"
|
19
|
+
},
|
20
|
+
"homepage": "https://github.com/Squbix-Digital-Private-Limited/npm-module-nodejs#readme",
|
21
|
+
"dependencies": {
|
22
|
+
"cors": "^2.8.5",
|
23
|
+
"dotenv": "^16.0.2",
|
24
|
+
"express": "^4.18.1",
|
25
|
+
"mongoose": "^6.6.1",
|
26
|
+
"nodemon": "^2.0.20"
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
const express = require('express');
|
2
|
+
const router = express.Router();
|
3
|
+
const EmployeeSchema = require('../models/EmployeeData');
|
4
|
+
|
5
|
+
async function getEmployee(id) {
|
6
|
+
// try {
|
7
|
+
const getEmployeeByID = await EmployeeSchema.findOne({ employee_id: id});
|
8
|
+
// res.json(getEmployeeByID);
|
9
|
+
// } catch (e) {
|
10
|
+
// next
|
11
|
+
// res.send({ message: e });
|
12
|
+
// }
|
13
|
+
return getEmployeeByID;
|
14
|
+
}
|
15
|
+
module.exports = {getEmployee};
|
16
|
+
|
17
|
+
// // Redis config.................
|
18
|
+
// const Redis = require('redis')
|
19
|
+
// let redisClient;
|
20
|
+
// (async () => {
|
21
|
+
// redisClient = Redis.createClient(6379, 'localhost');
|
22
|
+
|
23
|
+
// redisClient.on("error", (error) => console.error(`Error : ${error}`));
|
24
|
+
|
25
|
+
// await redisClient.connect();
|
26
|
+
// })();
|
27
|
+
|
28
|
+
// router.get('/getEmployee/:id',async(req, res, next) => {
|
29
|
+
|
30
|
+
// try {
|
31
|
+
// const value = await redisClient.get("employee");
|
32
|
+
// const empData = await JSON.parse(value)
|
33
|
+
// if(value!=null && empData.employee_id===req.params.id){
|
34
|
+
// console.log("cache hit")
|
35
|
+
// res.json(JSON.parse(value));
|
36
|
+
// }else{
|
37
|
+
// const getEmployeeByID = await EmployeeSchema.findOne({ employee_id: req.params.id});
|
38
|
+
// await redisClient.set("employee",JSON.stringify(getEmployeeByID))
|
39
|
+
// console.log("cache miss")
|
40
|
+
// res.json(getEmployeeByID);
|
41
|
+
// }
|
42
|
+
// } catch (e) {
|
43
|
+
// next
|
44
|
+
// res.send({ message: e });
|
45
|
+
// }
|
46
|
+
// });
|
47
|
+
// // End Redis config.................
|
48
|
+
|
49
|
+
// router.get('/getEmployee',async (req, res) => {
|
50
|
+
// let token = req.headers['authorization']
|
51
|
+
// const{response} = jwtValidator(token)
|
52
|
+
// if(response.err){
|
53
|
+
// return res.status(401).send(response.err)
|
54
|
+
// }else{
|
55
|
+
// const getEmployee = await EmployeeSchema.find();
|
56
|
+
// res.json(getEmployee);
|
57
|
+
// }
|
58
|
+
// });
|
59
|
+
// router.get('/getEmployee/:id', async(req, res, next) => {
|
60
|
+
// try {
|
61
|
+
// const getEmployeeByID = await EmployeeSchema.findOne({ employee_id: req.params.id});
|
62
|
+
// res.json(getEmployeeByID);
|
63
|
+
// } catch (e) {
|
64
|
+
// next
|
65
|
+
// res.send({ message: e });
|
66
|
+
// }
|
67
|
+
// });
|
68
|
+
// router.post('/createEmployee', async(req, res) => {
|
69
|
+
// if (req.body) {
|
70
|
+
// var myObj = req.body
|
71
|
+
// let token = req.headers['authorization']
|
72
|
+
// const{response} = jwtValidator(token)
|
73
|
+
// if(response.err){
|
74
|
+
// return res.status(401).send(response.err)
|
75
|
+
// }else{
|
76
|
+
// let empStatus
|
77
|
+
// if(req.body.leaving_date){
|
78
|
+
// empStatus = "Inactive"
|
79
|
+
// }else{
|
80
|
+
// empStatus="Active"
|
81
|
+
// }
|
82
|
+
// let employeesData={...myObj,employee_status:empStatus, timestamp: new Date()}
|
83
|
+
// const createEmployee = await EmployeeSchema.create(employeesData);
|
84
|
+
// res.json(createEmployee);
|
85
|
+
// }
|
86
|
+
// } else {
|
87
|
+
// res.json({
|
88
|
+
// error: 'The input field is empty',
|
89
|
+
// });
|
90
|
+
// }
|
91
|
+
// });
|
92
|
+
// router.post('/updateEmployee/:id', async(req, res) => {
|
93
|
+
// if (req.body) {
|
94
|
+
// let token = req.headers['authorization']
|
95
|
+
// const{response} = jwtValidator(token)
|
96
|
+
// if(response.err){
|
97
|
+
// return res.status(401).send(response.err)
|
98
|
+
// }else{
|
99
|
+
// let employeesData={ $set: req.body}
|
100
|
+
// const updateEmployee = await EmployeeSchema.updateOne({ _id: req.params.id},employeesData);
|
101
|
+
// res.json(updateEmployee);
|
102
|
+
// }
|
103
|
+
// } else {
|
104
|
+
// res.json({
|
105
|
+
// error: 'The input field is empty',
|
106
|
+
// });
|
107
|
+
// }
|
108
|
+
// });
|
109
|
+
// router.delete('/deleteEmployee/:id', async(req, res) => {
|
110
|
+
// let token = req.headers['authorization']
|
111
|
+
// const{response} = jwtValidator(token)
|
112
|
+
// if(response.err){
|
113
|
+
// return res.status(401).send(response.err)
|
114
|
+
// }else{
|
115
|
+
// const deleteEmployee = await EmployeeSchema.findOneAndDelete({ _id: req.params.id })
|
116
|
+
// res.json(deleteEmployee);
|
117
|
+
// }
|
118
|
+
// });
|
119
|
+
module.exports = router;
|