Skip to content

Commit ed26aa8

Browse files
allow delete profile
1 parent 92a86b5 commit ed26aa8

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

users/src/profile/delete.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Request, Response } from "express";
2+
import { Profile } from "../entities/Profile";
3+
import { ApiResponse, StatusMessageType } from "../types";
4+
import { handleServerError } from "../utils";
5+
import { getAuth } from "firebase-admin/auth";
6+
import { Activity } from "../entities/Activity";
7+
8+
export async function deleteProfileHandler(req: Request, res: Response) {
9+
const em = req.orm.em.fork();
10+
const uid = req.userToken.uid;
11+
12+
try {
13+
await em.nativeDelete(Profile, { uid: uid });
14+
await em.nativeDelete(Activity, { uid: uid });
15+
16+
const response: ApiResponse = {
17+
statusMessage: {
18+
message: "Profile deleted successfully",
19+
type: StatusMessageType.SUCCESS,
20+
},
21+
payload: {},
22+
};
23+
res.status(200).send(response);
24+
} catch (err: any) {
25+
handleServerError(err, res);
26+
}
27+
}

users/src/profile/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Router } from "express";
22
import { updateProfileHandler, updateProfileMulter } from "./update";
33
import { viewProfileHandler } from "./view";
4+
import { deleteProfileHandler } from "./delete";
45

56
const router = Router();
67

78
router.post("/", updateProfileMulter, updateProfileHandler);
89
router.get("/", viewProfileHandler);
10+
router.delete("/", deleteProfileHandler);
911

1012
export default router;

0 commit comments

Comments
 (0)