Skip to content

Commit

Permalink
Merge branch 'release/v1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jokj624 committed Jan 3, 2023
2 parents 1788d9a + 93f83fe commit 94bbbcc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express, { Request, Response } from 'express';
import { UserTokenUpdateDto } from '../interfaces/IUser';
import { isValidObjectId } from '../modules/checkObjectIdValidation';
import { userService } from '../services';
const sc = require('../modules/statusCode');
const util = require('../modules/util');
Expand Down Expand Up @@ -69,7 +70,46 @@ const updateUserToken = async (req: Request, res: Response) => {
}
};

/**
* @route DELETE /user/{userId}
* @desc delete user
* @access Public
*/
const deleteUser = async (
req: Request,
res: Response,
): Promise<void | Response> => {
const { userId } = req.params;

const isValidId = isValidObjectId(userId);
if (!isValidId) {
return res
.status(sc.BAD_REQUEST)
.send(util.fail(sc.BAD_REQUEST, responseMessage.BAD_REQUEST));
}
try {
const deleteCount = await userService.deleteUser(userId);
if (!deleteCount) {
return res
.status(sc.NOT_FOUND)
.send(util.fail(sc.NOT_FOUND, responseMessage.NOT_FOUND));
}

res.status(sc.NO_CONTENT).send();
} catch (error) {
console.log(error);
res
.status(sc.INTERNAL_SERVER_ERROR)
.send(
util.fail(
sc.INTERNAL_SERVER_ERROR,
responseMessage.INTERNAL_SERVER_ERROR,
),
);
}
};
export default {
registerUser,
updateUserToken,
deleteUser,
};
4 changes: 3 additions & 1 deletion src/loaders/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const connectDB = async () => {
'mutable-content': 1,
},
},
image: reminder.ogImage as string,
fcm_options: {
image: reminder.ogImage as string,
},
},
token: reminder.userId['fcmToken'],
};
Expand Down
1 change: 1 addition & 0 deletions src/modules/responseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
BAD_REQUEST: '잘못된 요청 파라미터',
NULL_VALUE: '필요한 값이 없습니다',
NOT_FOUND: '존재하지 않는 자원',

Expand Down
1 change: 1 addition & 0 deletions src/routes/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const router = Router();

router.post('/', userController.registerUser);
router.put('/:userId/refresh-token', userController.updateUserToken);
router.delete('/:userId', userController.deleteUser);

export default router;
18 changes: 18 additions & 0 deletions src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,25 @@ const updateUserToken = async (
}
};

const deleteUser = async (userId: string): Promise<void | Object> => {
try {
const user = await User.findById(userId);
if (!user) return undefined;

const filter = {
_id: userId,
};

const result = await User.deleteOne(filter);

return result;
} catch (error) {
console.log(error);
throw error;
}
};
export default {
createUser,
updateUserToken,
deleteUser,
};

0 comments on commit 94bbbcc

Please sign in to comment.