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
30 changes: 30 additions & 0 deletions src/controllers/editProfileControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require('dotenv').config();
const User = require('./../models/user')
const {ERROR, SUCCESS} = require('.././assests/constants')



const editProfile = async (req, res) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(req, res, next) are the parameters for controllers

try {
const id = req.params.id;
const userData = await User.findById({userId: id});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user models does not have this find by id method you are trying to call here. Did you test this to see that it works

if (userData) {
res.status(SUCCESS).json({
message:'userData found successfully',
data:userData
})
}else {
res.status(ERROR).json({
message: 'Wrong data found'
})
}

}catch (err) {
res.status(ERROR).json({
message: err.message
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inside catch, all you need to do is next(err)....pass error into next so that the universal error handler will take care of it

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inside catch, all you need to do is next(err)....pass error into next function so that the universal error handler will take care of it

}
}
module.exports = {
editProfile
}
15 changes: 15 additions & 0 deletions src/routes/editProfileRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require('express');
const router = express.Router()
const {editProfileControllers} = require('../controllers/editProfileControllers')


router.post('/edit', editProfileControllers.editProfile)








module.exports = router
2 changes: 2 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const express = require('express');
const walletRouter = require('./routes/walletRoutes');
const accountRouter = require('./routes/accountRoutes');
const bvnRouter = require('./routes/bvnRoutes');
const editProfileRouter = require('./routes/editProfileRoutes')

const transactionRouter = require('./routes/transactionRoutes');

Expand All @@ -18,5 +19,6 @@ app.use('/api/v1/wallet', walletRouter);
app.use('/api/v1/account', accountRouter);
app.use('/api/v1/transfer', transactionRouter);
app.use('/api/v1/bvn', bvnRouter);
app.use('/api/v1/edit', editProfileRouter);

module.exports = app;