Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
UwicyezaG committed May 7, 2024
1 parent 610ca15 commit 57ef6e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/__test__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ describe.only('PUT/user/update', () =>{
// Create a new user
const res = await request(app).post('/user/register').send(newUser);

Check warning on line 132 in src/__test__/route.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'res' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 132 in src/__test__/route.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'res' is assigned a value but never used
const userRepository = getRepository(User);
const updateUser = {
firstName: "Biguseers2399",
lastName: "1",
email: "john.doe23@example.com",
gender: "Male",
phoneNumber: "0790easdas7dsdfd76175",
photoUrl: "photo",
}
const user = await userRepository.findOne({ where: { email: updateUser.email } });

const user = await userRepository.findOne({ where: { email: newUser.email } });
if(user){
const updateUser = {
id: user.id,
firstName: "Biguseers2399",
lastName: "1",
email: "john.doe23@example.com",
gender: "Male",
phoneNumber: "0790easdas7dsdfd76175",
photoUrl: "photo",
}

Check warning on line 145 in src/__test__/route.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

Missing semicolon
const res = await request(app).put('/user/update').send(updateUser)

Check warning on line 146 in src/__test__/route.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

Missing semicolon
expect(res.status).toBe(201);
expect(res.body).toEqual({
Expand Down
8 changes: 5 additions & 3 deletions src/services/userServices/userProfileUpdateServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ declare module "express"{

export const userProfileUpdateServices = async (req: Request, res: Response) =>{
try {
console.log(req.body)
if(!req.body){
return responseError(res, 401, "body required")
}

const { firstName, lastName, gender, phoneNumber, photoUrl, email } = req.body;
const { firstName, lastName, gender, phoneNumber, photoUrl, email, id} = req.body;

// Validate user input
if (!firstName.trim() && !lastName.trim() && !gender.trim() && !phoneNumber.trim() && !photoUrl.trim() && !email.trim()) {
if (!firstName.trim() && !lastName.trim() && !gender.trim() && !phoneNumber.trim() && !photoUrl.trim() && !email.trim() && !id.trim()) {
return responseError(res, 400, 'Fill all the field');
}

Expand All @@ -34,6 +33,9 @@ try {
if (!existingUser){
return responseError(res, 401, "User not found")
}
if (existingUser.id !== id) {
return responseError(res, 403, "You are not authorized to edit this profile.");
}

existingUser.firstName = firstName
existingUser.lastName = lastName
Expand Down

0 comments on commit 57ef6e1

Please sign in to comment.