Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
checkg/**.js
node_modules/
package-lock.json
yarn.lock
Binary file not shown.
6 changes: 6 additions & 0 deletions Shivani_Bansal/NodeAssignment/.vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file added Shivani_Bansal/NodeAssignment/.vs/slnx.sqlite
Binary file not shown.
47 changes: 47 additions & 0 deletions Shivani_Bansal/NodeAssignment/controllers/employee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const model =require('../models')
class Employee{
constructor(){
}
async create(req,res) {
let employeeObj ={
name: req.body.name,
email: req.body.email,
designation: req.body.designation,
password:req.body.password,
projectId:req.body.projectId,
_id:req.body._id

}
console.log(employeeObj)
const employee= await model.employee.save(employeeObj)
res.send(employee)
}
async update(req,res) {
let updateObj={
name: req.body.name,
email: req.body.email,

designation: req.body.designation,

}
console.log(updateObj)
const employee= await model.employee.update(updateObj)
res.send(employee)

}
async delete(req,res){
console.log(req.params._id)
const employee =await model.employee.delete({_id: req.params.parameter})
res.send("deleted")
}
async show(req,res){
const employee = await model.employee.get({_id: req.params.parameter})
res.send(employee)
}

async index(req,res){
const employeeList = await model.employee.get();
res.send(employeeList)
}
}
module.exports = new Employee();
4 changes: 4 additions & 0 deletions Shivani_Bansal/NodeAssignment/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const employee = require('./employee')
module.exports = {
employee: employee
}
17 changes: 17 additions & 0 deletions Shivani_Bansal/NodeAssignment/database/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require('mongoose')
const url = "mongodb://localhost/company" //default port 27017 for mongoose
mongoose.Promise = global.Promise;

//connecting to database
mongoose.connect(url,{useNewUrlParser: true, keepAlive:1}).then((res)=>
{
console.log("Connection established")
// console.log(res)
}).catch(error =>{
console.log(error.message)
})
//removes unwanted parts , parallel connection
module.exports = mongoose;



34 changes: 34 additions & 0 deletions Shivani_Bansal/NodeAssignment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const express = require('express');
const jwt = require("jsonwebtoken");
const bodyParser = require('body-parser');
const app = express();
const database = require('./database/config');
app.use(bodyParser.json());
var cors = require('cors')
const model =require('./models');
app.use(cors());
app.use(express.json()); //Read
require('./routes/route.js')(app);

app.post('/login', async(req,res) =>
{
// console.log(req.body.email)
email = req.body.email;
password = req.body.password;
console.log(email, password)
user = await model.employee.search({ email, password})

if(!user){
return res.send('Email or Password incorrect');
}


const token = jwt.sign({designation: user.designation, email: user.email}, 'cybergroup');

res.header('x-auth-token', token).send('Login Successfully');
})

const port = process.env.PORT || 3000;
app.listen(port, () =>{
console.log(`Listening port ${port}`);
})
29 changes: 29 additions & 0 deletions Shivani_Bansal/NodeAssignment/models/employee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');
const schema = require('../schemas')
const employeeSchema = mongoose.Schema(schema.employee);
class Employee{
constructor(){
this.model=mongoose.model('employee', employeeSchema)
}
async get(criteria ={}){
return this.model.find(criteria)
}
async save(employeeObj){
return this.model.create(employeeObj)
}
async update(criteria={},updateObj){
return this.model.update(criteria,updateObj)
}
async delete(criteria={})
{
return this.model.deleteOne(criteria)
}

async search(employeeObj){
console.log(employeeObj);
const employee = await this.model.findOne(employeeObj)
console.log(employee);
return employee;
}
}
module.exports =new Employee();
5 changes: 5 additions & 0 deletions Shivani_Bansal/NodeAssignment/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// import { model } from "mongoose";
const employee= require('./employee');
module.exports ={
employee: employee
}
Loading