Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user details handling module added #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions build/controllers/usersController.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/controllers/usersController.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions build/models/users.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/models/users.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions build/routes/usersRoutes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/routes/usersRoutes.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/controllers/usersController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'fs'

exports.addUser = (req,res) =>{
let newUser = {
"name":req.body.name,
"email":req.body.email
}
fs.readFile('src/usersDetails.json', (err, data) => {
var json = JSON.parse(data) //converting contents of usersDetails to json objects
json.push(newUser)

fs.writeFile("src/usersDetails.json", JSON.stringify(json,null, 2),(err)=>{
if (err) throw err;
res.status(200).send('The data to append was appended to file!');
})
})
}


3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ app.use('/api/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

import userRoutes from '../src/routes/usersRoutes'
app.use('/users',userRoutes)

app.get('/', (req, res) => {
res.status(200).json({
status: 'success',
Expand Down
6 changes: 6 additions & 0 deletions src/routes/usersRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import express from 'express'
import usersController from '../controllers/usersController'
const router = express.Router()

router.post('/',usersController.addUser)
module.exports = router
Empty file added src/usersDetails.json
Empty file.