-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented addEmployee and getEmployees
- Loading branch information
1 parent
b2070a6
commit 470165d
Showing
7 changed files
with
1,557 additions
and
2 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
/node_modules | ||
/examples | ||
.env | ||
/.env | ||
.vscode |
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,34 @@ | ||
const Employee = require("../models/Employee.model"); | ||
|
||
const addEmployee = (req, res) => { | ||
const { name, position, salary } = req.body; | ||
|
||
const employee = new Employee({ | ||
name, | ||
position, | ||
salary, | ||
}); | ||
|
||
employee | ||
.save() | ||
.then((createdEmployee) => { | ||
res.json(createdEmployee); | ||
}) | ||
.catch((error) => { | ||
res.status(400).json(error); | ||
}); | ||
}; | ||
|
||
const getEmployees = async (req, res) => { | ||
try { | ||
const employees = await Employee.find(); | ||
res.json(employees); | ||
} catch (error) { | ||
res.status(400).json(error); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
addEmployee, | ||
getEmployees, | ||
}; |
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,10 @@ | ||
const mongoose = require("mongoose"); | ||
const { Schema } = mongoose; | ||
|
||
const employeeSchema = new Schema({ | ||
name: String, | ||
position: String, | ||
salary: Number, | ||
}); | ||
|
||
module.exports = Employee = mongoose.model('Employee', employeeSchema); |
Oops, something went wrong.