Skip to content

Commit 0ad8259

Browse files
committed
update self account
1 parent 2a2ca27 commit 0ad8259

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

src/api/user/handler/UserHandler.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ export abstract class UserHandler {
1010
this.putUser = this.putUser.bind(this);
1111
this.getUserInfo = this.getUserInfo.bind(this);
1212
this.getUserMeetings = this.getUserMeetings.bind(this);
13+
this.putUserSelf = this.putUserSelf.bind(this);
1314
}
1415

16+
abstract putUserSelf(
17+
req: Request,
18+
res: Response,
19+
next: NextFunction
20+
): Promise<any>;
21+
1522
abstract getUserMeetings(
1623
req: Request,
1724
res: Response,

src/api/user/handler/UserHandlerImpl.ts

+23
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ export class UserHandlerImpl extends UserHandler {
4646
this.schemaValidator = schemaValidator;
4747
}
4848

49+
async putUserSelf(
50+
req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
51+
res: Response<any, Record<string, any>>,
52+
next: NextFunction
53+
): Promise<any> {
54+
const { username } = getTokenPayload(res);
55+
const payload: IPutUserPayload = req.body;
56+
57+
try {
58+
this.schemaValidator.validate({ schema: UserPutPayloadSchema, payload });
59+
60+
await this.userService.updateUserByUsername(username, payload);
61+
62+
return res
63+
.status(200)
64+
.json(
65+
createResponse(RESPONSE_MESSAGE.SUCCESS, "succesfully edit user")
66+
);
67+
} catch (error) {
68+
return next(error);
69+
}
70+
}
71+
4972
async getUserMeetings(
5073
req: Request,
5174
res: Response,

src/api/user/router/UserRouterImpl.ts

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class UserRouterImpl extends BaseRouter {
3737
USER_ROLE.STUDENT,
3838
]),
3939
this.handler.getUserCredential
40+
).put(
41+
this.authorizationMiddlware.authorize([USER_ROLE.ADMIN]),
42+
this.handler.putUserSelf
4043
);
4144

4245
// * user login

src/repository/user/UserPrismaRepositoryImpl.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class UserPrismaRepositoryImpl extends UserRepository {
2626
fullname: edittedUser.profile?.fullname,
2727
nickname: edittedUser.profile?.nickname,
2828
username: edittedUser.username,
29+
githubUsername: edittedUser.profile?.githubUsername,
30+
instagramUsername: edittedUser.profile?.instagramUsername,
2931
},
3032
},
3133
},

src/services/user/UserServiceImpl.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export class UserServiceImpl extends UserService {
3939
payload.username ?? user.username,
4040
payload.fullname ?? user.profile?.fullname ?? "",
4141
payload.fullname?.split(" ").at(1) ?? user.profile?.nickname ?? "",
42-
payload.classOf ?? user.profile?.classOf ?? ""
42+
payload.classOf ?? user.profile?.classOf ?? "",
43+
{
44+
githubUsername: user.profile?.githubUsername,
45+
instagramUsername: user.profile?.instagramUsername,
46+
}
4347
),
4448
}
4549
);

src/utils/interfaces/request/IPutUserPayload.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { USER_ROLE } from "@prisma/client";
22

33
export interface IPutUserPayload {
4+
readonly githubUsername?: string;
5+
readonly instagramUsername?: string;
46
readonly username?: string;
57
readonly password?: string;
68
readonly fullname?: string;

src/utils/validator/user/Joi/UserPutPayloadSchema.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Joi from "joi";
22

33
export const UserPutPayloadSchema = Joi.object({
44
username: Joi.string().optional(),
5+
githubUsername: Joi.string().optional(),
6+
instagramUsername: Joi.string().optional(),
57
password: Joi.string().optional(),
68
role: Joi.string().optional(),
79
classOf: Joi.string().min(4).max(5).optional(),

0 commit comments

Comments
 (0)