Skip to content

Commit

Permalink
disable update projects on pending/active projects
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 16, 2023
1 parent 87ec7ce commit 37b2dd6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
9 changes: 4 additions & 5 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,12 @@ public function changeStatus($id, Request $request)
{
$project = Project::findOrFail($id);
$projectArray = $project->toArray();
$project['preview'] = $project->getFirstMediaUrl('preview') ?? null;
// dd($project);

$projectArray['preview'] = $project->getFirstMediaUrl('preview') ?? null;
Validator::make(
$projectArray,
[
'name' => ['required', 'max:255'],
'start' => ['required', 'date', 'after_or_equal:tomorrow'],
'start' => ['required', 'date', 'after_or_equal:today'],
'end' => ['required', 'date', 'after:start'],
'target_budget' => ['required', 'numeric', 'min:1'],
'categories' => ['required', 'array', 'min:1'],
Expand All @@ -124,8 +122,9 @@ public function changeStatus($id, Request $request)
)->validate();

try {
(new ProjectService(Project::class))->changeStatus($id, $request->get('status'));
(new ProjectService(Project::class))->changeStatus($project, $request->get('status'));
} catch (\Exception $exception) {
dd($exception->getMessage());
return redirect()->back()
->with('error', $exception->getMessage());
}
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Resources/Project/EditProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function toArray(Request $request): array
'troffees_count' => 2,
'score' => 100,
],
'is_active' => $this->is_active,
'is_pending' => $this->is_pending,
'can_be_archived' => $this->can_be_archived,
];
}
}
6 changes: 4 additions & 2 deletions app/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private function createDraftProject(array $data): Project|RegionalProject
}
$slug = \Str::slug($data['name']);
$count = Project::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();
$data['organization_id'] = auth()->user()->organization_id;
$data['slug'] = $slug;
if ($count > 0) {
$data['slug'] .= '-' . ($count + 1);
Expand All @@ -68,6 +69,7 @@ private function sendCreateNotifications($project): void
private function createPendingProject(array $data): Project|RegionalProject
{
$data['slug'] = \Str::slug($data['name']);
$data['organization_id'] = auth()->user()->organization_id;
$project = $this->project::create($data);
$this->sendCreateNotifications($project);

Expand All @@ -77,9 +79,9 @@ private function createPendingProject(array $data): Project|RegionalProject
/**
* @throws \Exception
*/
public function changeStatus($id, string $status): void
public function changeStatus(Project|RegionalProject $project, string $status): void
{

$this->project = $project;
$this->project->status = ProjectStatus::pending->value;
$this->project->status_updated_at = now();
$this->project->save();
Expand Down
4 changes: 2 additions & 2 deletions lang/ro/custom_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
return [
'activity_domains_ids' => 'Trebuie să selectați cel puțin un domeniu de activitate.',
'counties_ids' => 'Trebuie să selectați cel puțin un județ.',
'start_date' =>[
'start_date' => [
'after_or_equal' => 'Data de început nu poate fi in trecut.',
]
],
];

0 comments on commit 37b2dd6

Please sign in to comment.