Skip to content

FOUR-12621: Create an API to get the processes related to the specific Category #5744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function index(Request $request)
if (!empty($filter)) {
$processes->filter($filter);
}
// Filter by category
$category = $request->input('category', null);
if (!empty($category)) {
$processes->processCategory($category);
}

if (!empty($pmql)) {
try {
Expand Down
8 changes: 8 additions & 0 deletions ProcessMaker/Models/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ public function scopeArchived($query)
return $query->where('processes.status', 'ARCHIVED');
}

/**
* Scope a query to include a specific category
*/
public function scopeProcessCategory($query, int $id)
{
return $query->where('processes.process_category_id', $id);
}

public function getCollaborations()
{
$this->bpmnDefinitions = app(BpmnDocumentInterface::class, ['process' => $this]);
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/Api/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,29 @@ public function testSorting()
]);
}

/**
* Test filter by Category
*/
public function testFilterCategory()
{
// Create Category
$categoryA = ProcessCategory::factory()->create();
$categoryB = ProcessCategory::factory()->create();
// Now we create process related to this
Process::factory()->count(5)->create([
'process_category_id' => $categoryB->id,
]);
// Get process without category
$response = $this->apiCall('GET', route('api.processes.index', ['per_page' => 5, 'page' => 1]));
$response->assertJsonCount(5, 'data');
// Get process related categoryA
$response = $this->apiCall('GET', route('api.processes.index', ['category' => $categoryA->id]));
$response->assertJsonCount(0, 'data');
// Get process related categoryB
$response = $this->apiCall('GET', route('api.processes.index', ['category' => $categoryB->id]));
$response->assertJsonCount(5, 'data');
}

/**
* Test pagination of process list
*/
Expand Down