check if user accept notifications
This commit is contained in:
@@ -97,28 +97,35 @@ class EventsController extends Controller
|
|||||||
return $task->users;
|
return $task->users;
|
||||||
})->unique('id');
|
})->unique('id');
|
||||||
|
|
||||||
|
|
||||||
if (Carbon::now()->lessThanOrEqualTo($event->end)) {
|
if (Carbon::now()->lessThanOrEqualTo($event->end)) {
|
||||||
$notification = Notification::create([
|
$webParticipants = $participants->filter(fn($user) => $user->web_notifications);
|
||||||
'content' => "L'événement {$event->name} a été supprimé. Vous n'y participez donc plus."
|
|
||||||
]);
|
if ($webParticipants->isNotEmpty()) {
|
||||||
$notification->users()->attach($participants->pluck('id'));
|
$notification = Notification::create([
|
||||||
|
'content' => "L'événement {$event->name} a été supprimé. Vous n'y participez donc plus."
|
||||||
|
]);
|
||||||
|
$notification->users()->attach($webParticipants->pluck('id'));
|
||||||
|
|
||||||
|
foreach ($webParticipants as $user) {
|
||||||
|
broadcast(new EventParticipationCancelled(
|
||||||
|
$user->id,
|
||||||
|
$event,
|
||||||
|
$notification->id,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($participants as $user) {
|
foreach ($participants as $user) {
|
||||||
broadcast(new EventParticipationCancelled(
|
if ($user->email_notifications) {
|
||||||
$user->id,
|
$data = [
|
||||||
$event,
|
'name' => $user->name,
|
||||||
$notification->id,
|
'lastname' => $user->lastname,
|
||||||
));
|
'eventName' => $event->name,
|
||||||
|
'start' => $event->start,
|
||||||
$data = [
|
'end' => $event->end,
|
||||||
'name' => $user->name,
|
];
|
||||||
'lastname' => $user->lastname,
|
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
|
||||||
'eventName' => $event->name,
|
}
|
||||||
'start' => $event->start,
|
|
||||||
'end' => $event->end,
|
|
||||||
];
|
|
||||||
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,15 +35,14 @@ class TasksController extends Controller
|
|||||||
$event = Event::find($request["event_id"]);
|
$event = Event::find($request["event_id"]);
|
||||||
|
|
||||||
$event->tasks()->create([
|
$event->tasks()->create([
|
||||||
"name" => $request["name"],
|
"name" => $request["name"],
|
||||||
"description" => $request["description"],
|
"description" => $request["description"],
|
||||||
"start" => $request["start"],
|
"start" => $request["start"],
|
||||||
"end" => $request["end"],
|
"end" => $request["end"],
|
||||||
"location" => $request["location"],
|
"location" => $request["location"],
|
||||||
"max_participants" => $request["max_participants"],
|
"max_participants" => $request["max_participants"],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
return response()->json(['message' => "Task created"], 200);
|
return response()->json(['message' => "Task created"], 200);
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
@@ -98,27 +97,31 @@ class TasksController extends Controller
|
|||||||
|
|
||||||
if($user && Carbon::now()->lessThanOrEqualTo($task->end)) {
|
if($user && Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||||
|
|
||||||
$notification = Notification::create([
|
if ($user->web_notifications) {
|
||||||
'content' => "Vous avez été assigné à la tâche {$task->name} de l'événement {$event->name}."
|
$notification = Notification::create([
|
||||||
]);
|
'content' => "Vous avez été assigné à la tâche {$task->name} de l'événement {$event->name}."
|
||||||
$notification->users()->attach($user->id);
|
]);
|
||||||
|
$notification->users()->attach($user->id);
|
||||||
|
|
||||||
broadcast(new VolunteerAssignedToTask(
|
broadcast(new VolunteerAssignedToTask(
|
||||||
$user->id,
|
$user->id,
|
||||||
$task,
|
$task,
|
||||||
$event,
|
$event,
|
||||||
$notification->id,
|
$notification->id,
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$data = [
|
if ($user->email_notifications) {
|
||||||
'name' => $user->name,
|
$data = [
|
||||||
'lastname' => $user->lastname,
|
'name' => $user->name,
|
||||||
'taskName' => $task->name,
|
'lastname' => $user->lastname,
|
||||||
'start' => $task->start,
|
'taskName' => $task->name,
|
||||||
'end' => $task->end,
|
'start' => $task->start,
|
||||||
'eventName' => $event->name,
|
'end' => $task->end,
|
||||||
];
|
'eventName' => $event->name,
|
||||||
Mail::to($user->email)->send(new VolunteerAssignToTaskMail($data));
|
];
|
||||||
|
Mail::to($user->email)->send(new VolunteerAssignToTaskMail($data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['message' => "Task assigned"], 200);
|
return response()->json(['message' => "Task assigned"], 200);
|
||||||
@@ -141,7 +144,6 @@ class TasksController extends Controller
|
|||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteTask(Request $request, int $id): JsonResponse {
|
public function deleteTask(Request $request, int $id): JsonResponse {
|
||||||
@@ -161,29 +163,37 @@ class TasksController extends Controller
|
|||||||
|
|
||||||
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||||
if ($participants->isNotEmpty()) {
|
if ($participants->isNotEmpty()) {
|
||||||
$notification = Notification::create([
|
$webParticipants = $participants->filter(fn($user) => $user->web_notifications);
|
||||||
'content' => "La tâche {$task->name} pour l'événement {$event->name} a été supprimée. Vous n'y participez donc plus."
|
|
||||||
]);
|
|
||||||
$notification->users()->attach($participants->pluck('id'));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($participants as $user) {
|
if ($webParticipants->isNotEmpty()) {
|
||||||
broadcast(new TaskParticipationCancelled(
|
$notification = Notification::create([
|
||||||
$user->id,
|
'content' => "La tâche {$task->name} pour l'événement {$event->name} a été supprimée. Vous n'y participez donc plus."
|
||||||
$task,
|
]);
|
||||||
$event,
|
$notification->users()->attach($webParticipants->pluck('id'));
|
||||||
$notification->id,
|
|
||||||
));
|
|
||||||
|
|
||||||
$data = [
|
foreach ($webParticipants as $user) {
|
||||||
'name' => $user->name,
|
broadcast(new TaskParticipationCancelled(
|
||||||
'lastname' => $user->lastname,
|
$user->id,
|
||||||
'taskName' => $task->name,
|
$task,
|
||||||
'start' => $event->start,
|
$event,
|
||||||
'end' => $task->end,
|
$notification->id,
|
||||||
'eventName' => $event->name,
|
));
|
||||||
];
|
}
|
||||||
Mail::to($user->email)->send(new TaskParticipationCancelledMail($data));
|
}
|
||||||
|
|
||||||
|
foreach ($participants as $user) {
|
||||||
|
if ($user->email_notifications) {
|
||||||
|
$data = [
|
||||||
|
'name' => $user->name,
|
||||||
|
'lastname' => $user->lastname,
|
||||||
|
'taskName' => $task->name,
|
||||||
|
'start' => $event->start,
|
||||||
|
'end' => $task->end,
|
||||||
|
'eventName' => $event->name,
|
||||||
|
];
|
||||||
|
Mail::to($user->email)->send(new TaskParticipationCancelledMail($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +216,7 @@ class TasksController extends Controller
|
|||||||
try {
|
try {
|
||||||
$task = Task::find($id);
|
$task = Task::find($id);
|
||||||
if((
|
if((
|
||||||
$task->start !== $request["start"] || $task->end !== $request["end"]
|
$task->start !== $request["start"] || $task->end !== $request["end"]
|
||||||
) &&
|
) &&
|
||||||
Carbon::now()->lessThanOrEqualTo($task->end)
|
Carbon::now()->lessThanOrEqualTo($task->end)
|
||||||
){
|
){
|
||||||
@@ -216,30 +226,35 @@ class TasksController extends Controller
|
|||||||
$event = Event::find($task->events_id);
|
$event = Event::find($task->events_id);
|
||||||
|
|
||||||
foreach ($participants as $user) {
|
foreach ($participants as $user) {
|
||||||
$notification = Notification::create([
|
if ($user->web_notifications) {
|
||||||
'content' => "La date de la tâche {$task->name} de l'événement {$event->name} à été mis à jour. Cette tâche aura maintenant lieu du {$formatedTaskStart} au {$formatedTaskEnd}."
|
$notification = Notification::create([
|
||||||
]);
|
'content' => "La date de la tâche {$task->name} de l'événement {$event->name} à été mis à jour. Cette tâche aura maintenant lieu du {$formatedTaskStart} au {$formatedTaskEnd}."
|
||||||
$notification->users()->attach($user->id);
|
]);
|
||||||
broadcast(new TaskDateUpdated(
|
$notification->users()->attach($user->id);
|
||||||
$user->id,
|
|
||||||
$task,
|
|
||||||
$event,
|
|
||||||
FormatDate::formatDate($request["start"]),
|
|
||||||
FormatDate::formatDate($request["end"]),
|
|
||||||
$notification->id,
|
|
||||||
));
|
|
||||||
|
|
||||||
$data = [
|
broadcast(new TaskDateUpdated(
|
||||||
'name' => $user->name,
|
$user->id,
|
||||||
'lastname' => $user->lastname,
|
$task,
|
||||||
'taskName' => $task->name,
|
$event,
|
||||||
'oldStart' => $formatedTaskStart,
|
FormatDate::formatDate($request["start"]),
|
||||||
'oldEnd' => $formatedTaskEnd,
|
FormatDate::formatDate($request["end"]),
|
||||||
'newStart' => $request["start"],
|
$notification->id,
|
||||||
'newEnd' => $request["end"],
|
));
|
||||||
'eventName' => $event->name,
|
}
|
||||||
];
|
|
||||||
Mail::to($user->email)->send(new TaskDateUpdateMail($data));
|
if ($user->email_notifications) {
|
||||||
|
$data = [
|
||||||
|
'name' => $user->name,
|
||||||
|
'lastname' => $user->lastname,
|
||||||
|
'taskName' => $task->name,
|
||||||
|
'oldStart' => $formatedTaskStart,
|
||||||
|
'oldEnd' => $formatedTaskEnd,
|
||||||
|
'newStart' => $request["start"],
|
||||||
|
'newEnd' => $request["end"],
|
||||||
|
'eventName' => $event->name,
|
||||||
|
];
|
||||||
|
Mail::to($user->email)->send(new TaskDateUpdateMail($data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,26 +316,31 @@ class TasksController extends Controller
|
|||||||
$task->users()->detach($id);
|
$task->users()->detach($id);
|
||||||
|
|
||||||
if ($user && Carbon::now()->lessThanOrEqualTo($task->end)) {
|
if ($user && Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||||
$notification = Notification::create([
|
if ($user->web_notifications) {
|
||||||
'content' => "Vous avez été désassigné de la tâche {$task->name} de l'événement {$event->name}."
|
$notification = Notification::create([
|
||||||
]);
|
'content' => "Vous avez été désassigné de la tâche {$task->name} de l'événement {$event->name}."
|
||||||
$notification->users()->attach($user->id);
|
]);
|
||||||
broadcast(new VolunteerUnassignedFromTask(
|
$notification->users()->attach($user->id);
|
||||||
$user->id,
|
|
||||||
$task,
|
|
||||||
$event,
|
|
||||||
$notification->id,
|
|
||||||
));
|
|
||||||
|
|
||||||
$data = [
|
broadcast(new VolunteerUnassignedFromTask(
|
||||||
'name' => $user->name,
|
$user->id,
|
||||||
'lastname' => $user->lastname,
|
$task,
|
||||||
'taskName' => $task->name,
|
$event,
|
||||||
'start' => $task->start,
|
$notification->id,
|
||||||
'end' => $task->end,
|
));
|
||||||
'eventName' => $event->name,
|
}
|
||||||
];
|
|
||||||
Mail::to($user->email)->send(new VolunteerUnassignToTaskMail($data));
|
if ($user->email_notifications) {
|
||||||
|
$data = [
|
||||||
|
'name' => $user->name,
|
||||||
|
'lastname' => $user->lastname,
|
||||||
|
'taskName' => $task->name,
|
||||||
|
'start' => $task->start,
|
||||||
|
'end' => $task->end,
|
||||||
|
'eventName' => $event->name,
|
||||||
|
];
|
||||||
|
Mail::to($user->email)->send(new VolunteerUnassignToTaskMail($data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['message' => "User unassigned successfully"], 200);
|
return response()->json(['message' => "User unassigned successfully"], 200);
|
||||||
|
|||||||
@@ -55,27 +55,29 @@ class UserController extends Controller
|
|||||||
"email_notifications" => 1,
|
"email_notifications" => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$notification = Notification::create([
|
$notification = Notification::create([
|
||||||
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"
|
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"
|
||||||
]);
|
]);
|
||||||
$admins = User::whereIn('role', [1, 2])->get();
|
$admins = User::whereIn('role', [1, 2])->get();
|
||||||
$notification->users()->attach(
|
|
||||||
$admins->pluck('id')->toArray()
|
$webAdmins = $admins->filter(fn($admin) => $admin->web_notifications);
|
||||||
);
|
$notification->users()->attach($webAdmins->pluck('id')->toArray());
|
||||||
|
|
||||||
broadcast(new UserCreated(
|
broadcast(new UserCreated(
|
||||||
$user,
|
$user,
|
||||||
$notification->id,
|
$notification->id,
|
||||||
));
|
));
|
||||||
|
|
||||||
foreach ($admins as $admin) {
|
foreach ($admins as $admin) {
|
||||||
$data = [
|
if ($admin->email_notifications) {
|
||||||
'adminName' => $admin->name,
|
$data = [
|
||||||
'adminLastname' => $admin->lastname,
|
'adminName' => $admin->name,
|
||||||
'userName' => $user->name,
|
'adminLastname' => $admin->lastname,
|
||||||
'userLastname' => $user->lastname,
|
'userName' => $user->name,
|
||||||
];
|
'userLastname' => $user->lastname,
|
||||||
Mail::to($admin->email)->send(new RegisterMail($data));
|
];
|
||||||
|
Mail::to($admin->email)->send(new RegisterMail($data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'User created successfully']);
|
return response()->json(['message' => 'User created successfully']);
|
||||||
@@ -104,14 +106,17 @@ class UserController extends Controller
|
|||||||
"validate" => 1,
|
"validate" => 1,
|
||||||
"role" => 3,
|
"role" => 3,
|
||||||
"phone" => $phone->formatInternational(),
|
"phone" => $phone->formatInternational(),
|
||||||
|
"web_notifications" => 1,
|
||||||
|
"email_notifications" => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$data = [
|
if ($user->email_notifications) {
|
||||||
'name' => $user->name,
|
$data = [
|
||||||
'lastname' => $user->lastname,
|
'name' => $user->name,
|
||||||
];
|
'lastname' => $user->lastname,
|
||||||
Mail::to($user->email)->send(new CreateUserByAdminMail($data));
|
];
|
||||||
|
Mail::to($user->email)->send(new CreateUserByAdminMail($data));
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'User created successfully',
|
'message' => 'User created successfully',
|
||||||
@@ -123,11 +128,13 @@ class UserController extends Controller
|
|||||||
try {
|
try {
|
||||||
$user = User::find($request->user()->id);
|
$user = User::find($request->user()->id);
|
||||||
|
|
||||||
$data = [
|
if ($user->email_notifications) {
|
||||||
'name' => $user->name,
|
$data = [
|
||||||
'lastname' => $user->lastname,
|
'name' => $user->name,
|
||||||
];
|
'lastname' => $user->lastname,
|
||||||
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
];
|
||||||
|
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
||||||
|
}
|
||||||
|
|
||||||
$user->delete();
|
$user->delete();
|
||||||
return response()->json(['message' => 'User deleted successfully']);
|
return response()->json(['message' => 'User deleted successfully']);
|
||||||
@@ -138,7 +145,6 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getUser(Request $request, int $id): JsonResponse {
|
public function getUser(Request $request, int $id): JsonResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return response()->json(UserService::getData($id));
|
return response()->json(UserService::getData($id));
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
@@ -147,7 +153,6 @@ class UserController extends Controller
|
|||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteById(Request $request, int $id): JsonResponse {
|
public function deleteById(Request $request, int $id): JsonResponse {
|
||||||
@@ -159,11 +164,13 @@ class UserController extends Controller
|
|||||||
try {
|
try {
|
||||||
$user = User::find($id);
|
$user = User::find($id);
|
||||||
|
|
||||||
$data = [
|
if ($user->email_notifications) {
|
||||||
'name' => $user->name,
|
$data = [
|
||||||
'lastname' => $user->lastname,
|
'name' => $user->name,
|
||||||
];
|
'lastname' => $user->lastname,
|
||||||
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
];
|
||||||
|
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
||||||
|
}
|
||||||
|
|
||||||
$user->delete();
|
$user->delete();
|
||||||
return response()->json(['message' => 'User deleted successfully']);
|
return response()->json(['message' => 'User deleted successfully']);
|
||||||
@@ -183,11 +190,13 @@ class UserController extends Controller
|
|||||||
try {
|
try {
|
||||||
$userToDeactivate->update(['validate' => 0]);
|
$userToDeactivate->update(['validate' => 0]);
|
||||||
|
|
||||||
$data = [
|
if ($userToDeactivate->email_notifications) {
|
||||||
'name' => $userToDeactivate->name,
|
$data = [
|
||||||
'lastname' => $userToDeactivate->lastname,
|
'name' => $userToDeactivate->name,
|
||||||
];
|
'lastname' => $userToDeactivate->lastname,
|
||||||
Mail::to($userToDeactivate->email)->send(new DeactivateAccountMail($data));
|
];
|
||||||
|
Mail::to($userToDeactivate->email)->send(new DeactivateAccountMail($data));
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'User deactivated successfully']);
|
return response()->json(['message' => 'User deactivated successfully']);
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
@@ -196,13 +205,10 @@ class UserController extends Controller
|
|||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request): JsonResponse {
|
public function update(Request $request): JsonResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$phone = new PhoneNumber($request["phone"], 'FR');
|
$phone = new PhoneNumber($request["phone"], 'FR');
|
||||||
|
|
||||||
$user = User::find($request->user()->id);
|
$user = User::find($request->user()->id);
|
||||||
@@ -212,12 +218,10 @@ class UserController extends Controller
|
|||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return response()->json(['message' => 'User updated successfully']);
|
return response()->json(['message' => 'User updated successfully']);
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validate(Request $request, int $id): JsonResponse {
|
public function validate(Request $request, int $id): JsonResponse {
|
||||||
@@ -234,14 +238,15 @@ class UserController extends Controller
|
|||||||
$user->verified_at = now();
|
$user->verified_at = now();
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$data = [
|
if ($user->email_notifications) {
|
||||||
'name' => $user->name,
|
$data = [
|
||||||
'lastname' => $user->lastname,
|
'name' => $user->name,
|
||||||
];
|
'lastname' => $user->lastname,
|
||||||
Mail::to($user->email)->send(new ValidateMail($data));
|
];
|
||||||
|
Mail::to($user->email)->send(new ValidateMail($data));
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'User validated successfully']);
|
return response()->json(['message' => 'User validated successfully']);
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
@@ -261,24 +266,27 @@ class UserController extends Controller
|
|||||||
|
|
||||||
$role = GetRole::getRole($request['role']);
|
$role = GetRole::getRole($request['role']);
|
||||||
|
|
||||||
$notification = Notification::create([
|
if ($user->web_notifications) {
|
||||||
'content' => "Votre rôle à changé pour : {$role}",
|
$notification = Notification::create([
|
||||||
]);
|
'content' => "Votre rôle à changé pour : {$role}",
|
||||||
$notification->users()->attach($user->id);
|
]);
|
||||||
|
$notification->users()->attach($user->id);
|
||||||
|
|
||||||
broadcast(new VolunteerRoleUpdated(
|
broadcast(new VolunteerRoleUpdated(
|
||||||
$user->id,
|
$user->id,
|
||||||
$role,
|
$role,
|
||||||
$notification->id,
|
$notification->id,
|
||||||
));
|
));
|
||||||
|
}
|
||||||
$data = [
|
|
||||||
'name' => $user->name,
|
|
||||||
'lastname' => $user->lastname,
|
|
||||||
'role' => $role,
|
|
||||||
];
|
|
||||||
Mail::to($user->email)->send(new UpdateRoleMail($data));
|
|
||||||
|
|
||||||
|
if ($user->email_notifications) {
|
||||||
|
$data = [
|
||||||
|
'name' => $user->name,
|
||||||
|
'lastname' => $user->lastname,
|
||||||
|
'role' => $role,
|
||||||
|
];
|
||||||
|
Mail::to($user->email)->send(new UpdateRoleMail($data));
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'User role added successfully']);
|
return response()->json(['message' => 'User role added successfully']);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
@@ -288,16 +296,12 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getUsers(Request $request): JsonResponse {
|
public function getUsers(Request $request): JsonResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$users = User::where('validate', 1)
|
$users = User::where('validate', 1)
|
||||||
->orderBy('verified_at', 'desc')
|
->orderBy('verified_at', 'desc')
|
||||||
->pluck('id');
|
->pluck('id');
|
||||||
|
|
||||||
return response()->json($users);
|
return response()->json($users);
|
||||||
|
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
@@ -305,7 +309,6 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getUserTasks(Request $request): JsonResponse {
|
public function getUserTasks(Request $request): JsonResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return response()->json(['data' => $request->user()->tasks]);
|
return response()->json(['data' => $request->user()->tasks]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -315,7 +318,6 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getUserByIdTasks(Request $request, int $id): JsonResponse {
|
public function getUserByIdTasks(Request $request, int $id): JsonResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return response()->json(['data' => User::find($id)->tasks]);
|
return response()->json(['data' => User::find($id)->tasks]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -325,7 +327,6 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getUserTaskById(Request $request, int $idTask): JsonResponse {
|
public function getUserTaskById(Request $request, int $idTask): JsonResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return response()->json(['data' => $request->user()->tasks->find($idTask)]);
|
return response()->json(['data' => $request->user()->tasks->find($idTask)]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -340,11 +341,9 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$users = User::where('validate', 0)->pluck('id');
|
$users = User::where('validate', 0)->pluck('id');
|
||||||
|
|
||||||
return response()->json($users);
|
return response()->json($users);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
@@ -358,7 +357,7 @@ class UserController extends Controller
|
|||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return response()->json($user);
|
return response()->json($user);
|
||||||
}catch(\Exception $e){
|
} catch(\Exception $e){
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
}
|
}
|
||||||
@@ -371,10 +370,9 @@ class UserController extends Controller
|
|||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return response()->json($user);
|
return response()->json($user);
|
||||||
}catch(\Exception $e){
|
} catch(\Exception $e){
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
return response()->json(['message' => "Server error"], 500);
|
return response()->json(['message' => "Server error"], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user