Skip to content

Commit

Permalink
feat: req17 refac
Browse files Browse the repository at this point in the history
  • Loading branch information
dopimentel committed Feb 21, 2024
1 parent 4711de7 commit d552b27
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 0 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ app.get('/post/:id', auth, postController.getById);
app.put('/post/:id', auth, postController.update);
app.delete('/post/:id', auth, postController.exclude);
app.delete('/user/me', auth, userController.exclude);
// async (req, res) => {
// const { id } = req.params;
// const { title, content } = req.body;
// const post = await postService.update({ id, title, content });
// res.status(200).json(post);
// });

app.use(error);

Expand Down
1 change: 0 additions & 1 deletion src/controllers/postController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const update = async (req, res, next) => {
const exclude = async (req, res, next) => {
const { id } = req.params;
const { userId } = req.body;
console.log(userId, id);
const response = await deletePostService.exclude({ id, userId });
if (response.error) return next(response.error);
res.status(204).json(response);
Expand Down
1 change: 0 additions & 1 deletion src/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const extractToken = (authorization) => authorization.split(' ')[1];

const auth = (req, _res, next) => {
const authorization = req.header('Authorization');
console.log(authorization);
if (!authorization) {
const err = new Error('Token not found');
err.status = 401;
Expand Down
13 changes: 13 additions & 0 deletions src/services/delete.userService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { User } = require('../models');
const { getById } = require('./userService');

const exclude = async ({ userId }) => {
const user = await getById(userId);
if (!user) return { error: { status: 404, message: 'User does not exist' } };
await User.destroy({ where: { id: userId } });
return user;
};

module.exports = {
exclude,
};

0 comments on commit d552b27

Please sign in to comment.