Skip to content

Commit

Permalink
add tenant, email in update user
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakharnagore committed Aug 24, 2024
1 parent f7833be commit 6132bcc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class UserController {
return res.status(400).json({ errors: result.array() });
}

const { firstName, lastName, role } = req.body;
const { firstName, lastName, role, email, tenantId } = req.body;
const userId = req.params.id;

if (isNaN(Number(userId))) {
Expand All @@ -64,6 +64,8 @@ export class UserController {
firstName,
lastName,
role,
email,
tenantId,
});

this.logger.info("User has been updated", { id: userId });
Expand Down
4 changes: 3 additions & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export class UserService {
}
async update(
userId: number,
{ firstName, lastName, role }: LimitedUserData,
{ firstName, lastName, role, email, tenantId }: LimitedUserData,
) {
try {
return await this.userRepository.update(userId, {
firstName,
lastName,
role,
email,
tenant: tenantId ? { id: tenantId } : undefined,
});
} catch (err) {
const error = createHttpError(
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface LimitedUserData {
firstName: string;
lastName: string;
role: string;
email: string;
tenantId: number;
}

export interface UpdateUserRequest extends Request {
Expand Down
13 changes: 13 additions & 0 deletions src/validators/update-user-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ export default checkSchema({
notEmpty: true,
trim: true,
},
email: {
isEmail: {
errorMessage: "Invalid email",
},
notEmpty: true,
errorMessage: "Email is required!",
trim: true,
},
tenantId: {
notEmpty: true,
errorMessage: "Tenant id is required!",
trim: true,
},
});

0 comments on commit 6132bcc

Please sign in to comment.