Skip to content

Commit

Permalink
Merge pull request #554 from abdielbytes/abdiel
Browse files Browse the repository at this point in the history
fix: update user profile
  • Loading branch information
Dev-Tonia authored Aug 24, 2024
2 parents 0ad7145 + b33328c commit 6769adf
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 234 deletions.
14 changes: 8 additions & 6 deletions app/Http/Controllers/Api/V1/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,8 @@ public function show(User $user)
'username' => '',
'jobTitle' => $user->profile->job_title ?? null,
'pronouns' => $user->profile->pronoun ?? null,
'department' => null,
'email' => $user->email,
'bio' => $user->profile->bio ?? null,
'social_links' => null,
'language' => null,
'region' => null,
'timezones' => null,
'profile_pic_url' => $user->profile->avatar_url ?? null,
'deletedAt' => $user->profile->deleted_at ?? null
],
Expand Down Expand Up @@ -138,7 +133,14 @@ public function update(Request $request, string $id)
'first_name' => 'nullable|string|max:255',
'last_name' => 'nullable|string|max:255',
"email" => 'nullable|string|email|max:255|unique:users,email,' . $id,
"phone" => 'nullable|string'
"phone" => 'nullable|string',
'pronouns' => 'nullable|string|max:255',
'job_title' => 'nullable|string|max:255',
'social' => 'nullable|string|max:255',
'bio' => 'nullable|string|max:500',
'phone_number' => 'nullable|string|max:20',
'avatar_url' => 'nullable|string|url',
'recovery_email' => 'nullable|string|email|max:255'
]);

if ($validator->fails()) {
Expand Down
42 changes: 23 additions & 19 deletions app/Http/Controllers/UserNotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,40 @@ public function update(Request $request, $notificationId)
/**
* Remove the specified resource from storage.
*/
public function destroy()
public function destroy(Request $request)
{
try {

UserNotification::query()->where([
['user_id', auth()->id()],
['status', 'unread']
])->update([
'status' => 'read'
]);

// Check if the user is authenticated
$user = Auth::user();

// Update the status of all notifications (read or unread) for the authenticated user to 'read'
UserNotification::query()
->where('user_id', $user->id)
->update(['status' => 'read']);

// Return a success response
return response()->json([
'status' => 'success',
'message' => 'notifications cleared successfully',
'status_code' => Response::HTTP_OK,
'data' => UserNotification::query()->where('user_id', auth()->id())->get(),
'data' => 'All notifications have been cleared.',
'message' => 'All notifications cleared successfully',
'status_code' => Response::HTTP_OK
], Response::HTTP_OK);
} catch (ModelNotFoundException $exception) {
// Handle case where notifications are not found
return response()->json([
'status' => 'error',
'message' => 'notifications not found',
'status_code' => Response::HTTP_NOT_FOUND,
'data' => null,
'error' => 'Notifications not found',
'message' => 'No notifications found to clear',
'status_code' => Response::HTTP_NOT_FOUND
], Response::HTTP_NOT_FOUND);
} catch (\Exception $exception) {
Log::error($exception->getMessage());
return response()->json([
'status' => 'error',
'message' => 'something went wrong',
'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR,
'data' => null,
'error' => 'Internal Server Error',
'message' => 'Something went wrong while clearing notifications',
'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

}
Loading

0 comments on commit 6769adf

Please sign in to comment.