diff --git a/app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php b/app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php deleted file mode 100644 index d4dab4635..000000000 --- a/app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php +++ /dev/null @@ -1,19 +0,0 @@ -authorize('update', $workday->workdayable); - $workday->delete(); - $workday->save(); - - return new WorkdayResource($workday); - } -} diff --git a/app/Http/Controllers/V2/Workdays/StoreWorkdayController.php b/app/Http/Controllers/V2/Workdays/StoreWorkdayController.php deleted file mode 100644 index 908a0073d..000000000 --- a/app/Http/Controllers/V2/Workdays/StoreWorkdayController.php +++ /dev/null @@ -1,61 +0,0 @@ -getEntityFromRequest($request); - $this->authorize('read', $model); - - $request->merge([ - 'workdayable_type' => get_class($model), - 'workdayable_id' => $model->id, - ]); - - $workday = Workday::create($request->all()); - - return new WorkdayResource($workday); - } - - private function getEntityFromRequest(StoreWorkdayRequest $request) - { - switch ($request->get('model_type')) { - case 'organisation': - return Organisation::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project-pitch': - return ProjectPitch::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project': - return Project::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project-report': - return ProjectReport::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'site': - return Site::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'site-report': - return SiteReport::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'nursery': - return Nursery::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'nursery-report': - return NurseryReport::isUuid($request->get('model_uuid'))->firstOrFail(); - default: - throw new InvalidMorphableModelException(); - } - - return $request; - } -} diff --git a/app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php b/app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php deleted file mode 100644 index 95e1d3dc0..000000000 --- a/app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php +++ /dev/null @@ -1,20 +0,0 @@ -authorize('read', $workday->workdayable); - $workday->update($request->validated()); - $workday->save(); - - return new WorkdayResource($workday); - } -} diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index b35a07012..f04d4cb6d 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -77,7 +77,8 @@ public function updateFromForm(array $formData): void } else { $property = data_get($relationsConfig, "$question->linked_field_key.property"); if (! empty($property)) { - $this->syncRelation($property, collect(data_get($formData, $question->uuid))); + $inputType = data_get($relationsConfig, "$question->linked_field_key.input_type"); + $this->syncRelation($property, $inputType, collect(data_get($formData, $question->uuid))); } } @@ -242,10 +243,10 @@ private function updateLinkedFieldValue(array $linkedFieldInfo, $answer): void } } - private function syncRelation(string $property, $data): void + private function syncRelation(string $property, string $inputType, $data): void { // This will expand as we complete more tickets in TM-747, until eventually we support all form relations. - if ($property != 'treeSpecies') { + if (! in_array($inputType, ['treeSpecies', 'workdays'])) { return; } diff --git a/openapi-src/V2/definitions/V2WorkdayCreate.yml b/openapi-src/V2/definitions/V2WorkdayCreate.yml deleted file mode 100644 index df1ac1cf8..000000000 --- a/openapi-src/V2/definitions/V2WorkdayCreate.yml +++ /dev/null @@ -1,19 +0,0 @@ -title: V2WorkdayCreate -type: object -properties: - model_type: - type: string - model_uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/V2WorkdayUpdate.yml b/openapi-src/V2/definitions/V2WorkdayUpdate.yml deleted file mode 100644 index 30769e25e..000000000 --- a/openapi-src/V2/definitions/V2WorkdayUpdate.yml +++ /dev/null @@ -1,15 +0,0 @@ -title: V2WorkdayUpdate -type: object -properties: - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index 0ccdfea3b..5ebd90ac2 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -152,10 +152,6 @@ V2SeedingPaginated: $ref: './V2SeedingPaginated.yml' V2WorkdayRead: $ref: './V2WorkdayRead.yml' -V2WorkdayCreate: - $ref: './V2WorkdayCreate.yml' -V2WorkdayUpdate: - $ref: './V2WorkdayUpdate.yml' V2WorkdaysPaginated: $ref: './V2WorkdaysPaginated.yml' V2DisturbanceRead: diff --git a/openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml b/openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml deleted file mode 100644 index e0e866e09..000000000 --- a/openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml +++ /dev/null @@ -1,12 +0,0 @@ -operationId: delete-v2-workday-uuid -summary: Delete a workday -tags: - - V2 Workdays -parameters: - - type: string - name: UUID - in: path - required: true -responses: - '200': - description: OK diff --git a/openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml b/openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml deleted file mode 100644 index b8ce3769b..000000000 --- a/openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml +++ /dev/null @@ -1,14 +0,0 @@ -operationId: patch-v2-workday-uuid -summary: Update a workday -tags: - - V2 Workdays -parameters: - - type: string - name: UUID - in: path - required: true -responses: - '200': - description: OK - schema: - $ref: '../../definitions/_index.yml#/V2WorkdaysPaginated' diff --git a/openapi-src/V2/paths/Workdays/post-v2-workday.yml b/openapi-src/V2/paths/Workdays/post-v2-workday.yml deleted file mode 100644 index ebede9de6..000000000 --- a/openapi-src/V2/paths/Workdays/post-v2-workday.yml +++ /dev/null @@ -1,14 +0,0 @@ -operationId: post-v2-workday -summary: Crates a workday -tags: - - V2 Workdays -responses: - '201': - description: Created - schema: - $ref: '../../definitions/_index.yml#/V2WorkdayRead' -parameters: - - in: body - name: body - schema: - $ref: '../../definitions/_index.yml#/V2WorkdayCreate' diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index d96c9f717..57c46873e 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -104,14 +104,6 @@ /v2/update-requests/{ENTITY}/{UUID}: get: $ref: './UpdateRequests/get-v2-update-requests-entity-uuid.yml' -/v2/workdays: - post: - $ref: './Workdays/post-v2-workday.yml' -/v2/workdays/{UUID}: - patch: - $ref: './Workdays/patch-v2-workday-uuid.yml' - delete: - $ref: './Workdays/delete-v2-workday-uuid.yml' /v2/workdays/{ENTITY}/{UUID}: get: $ref: './Workdays/get-v2-workdays-entity-uuid.yml' diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 77ac99069..99cecc79a 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -9266,42 +9266,6 @@ definitions: type: string indigeneity: type: string - V2WorkdayCreate: - title: V2WorkdayCreate - type: object - properties: - model_type: - type: string - model_uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - V2WorkdayUpdate: - title: V2WorkdayUpdate - type: object - properties: - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string V2WorkdaysPaginated: type: object properties: @@ -57602,130 +57566,6 @@ paths: type: object created_by: type: object - /v2/workdays: - post: - operationId: post-v2-workday - summary: Crates a workday - tags: - - V2 Workdays - responses: - '201': - description: Created - schema: - title: V2WorkdayRead - type: object - properties: - uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - parameters: - - in: body - name: body - schema: - title: V2WorkdayCreate - type: object - properties: - model_type: - type: string - model_uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - '/v2/workdays/{UUID}': - patch: - operationId: patch-v2-workday-uuid - summary: Update a workday - tags: - - V2 Workdays - parameters: - - type: string - name: UUID - in: path - required: true - responses: - '200': - description: OK - schema: - type: object - properties: - data: - type: array - items: - title: V2WorkdayRead - type: object - properties: - uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - links: - type: object - properties: - first: - type: string - last: - type: string - prev: - type: string - next: - type: string - meta: - type: object - properties: - current_page: - type: integer - from: - type: integer - last_page: - type: integer - next: - type: integer - unfiltered_total: - type: integer - delete: - operationId: delete-v2-workday-uuid - summary: Delete a workday - tags: - - V2 Workdays - parameters: - - type: string - name: UUID - in: path - required: true - responses: - '200': - description: OK '/v2/workdays/{ENTITY}/{UUID}': get: operationId: get-v2-workdays-entity-uuid diff --git a/routes/api_v2.php b/routes/api_v2.php index 10445c3a5..631124387 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -184,10 +184,7 @@ use App\Http\Controllers\V2\User\CompleteActionController; use App\Http\Controllers\V2\User\IndexMyActionsController; use App\Http\Controllers\V2\User\UpdateMyBannersController; -use App\Http\Controllers\V2\Workdays\DeleteWorkdayController; use App\Http\Controllers\V2\Workdays\GetWorkdaysForEntityController; -use App\Http\Controllers\V2\Workdays\StoreWorkdayController; -use App\Http\Controllers\V2\Workdays\UpdateWorkdayController; use App\Http\Middleware\ModelInterfaceBindingMiddleware; use Illuminate\Support\Facades\Route; @@ -460,9 +457,6 @@ }); Route::prefix('workdays')->group(function () { - Route::post('/', StoreWorkdayController::class); - Route::patch('/{workday}', UpdateWorkdayController::class); - Route::delete('/{workday}', DeleteWorkdayController::class); Route::get('/{entity}/{uuid}', GetWorkdaysForEntityController::class); }); diff --git a/tests/V2/Workdays/DeleteWorkdayControllerTest.php b/tests/V2/Workdays/DeleteWorkdayControllerTest.php deleted file mode 100644 index a8ee600ed..000000000 --- a/tests/V2/Workdays/DeleteWorkdayControllerTest.php +++ /dev/null @@ -1,54 +0,0 @@ -create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $workday = Workday::factory()->create([ - 'workdayable_type' => Site::class, - 'workdayable_id' => $site->id, - ]); - - $uri = '/api/v2/workdays/' . $workday->uuid; - - $this->actingAs($user) - ->deleteJson($uri) - ->assertStatus(403); - - $this->actingAs($owner) - ->deleteJson($uri) - ->assertSuccessful(); - } -} diff --git a/tests/V2/Workdays/StoreWorkdayControllerTest.php b/tests/V2/Workdays/StoreWorkdayControllerTest.php deleted file mode 100644 index 2702018d7..000000000 --- a/tests/V2/Workdays/StoreWorkdayControllerTest.php +++ /dev/null @@ -1,71 +0,0 @@ -create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $report = SiteReport::factory()->create([ - 'site_id' => $site->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $payload = [ - 'model_type' => 'site-report', - 'model_uuid' => $report->uuid, - 'amount' => 14, - 'gender' => 'male', - 'ethnicity' => 'hispanic', - 'collection' => Workday::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS, - 'age' => 'adult-24-65', - ]; - - $uri = '/api/v2/workdays'; - - $this->actingAs($user) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->postJson($uri, $payload) - ->assertSuccessful() - ->assertJsonPath('data.amount', 14) - ->assertJsonPath('data.gender', 'male') - ->assertJsonPath('data.ethnicity', 'hispanic') - ->assertJsonPath('data.collection', Workday::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS) - ->assertJsonPath('data.age', 'adult-24-65'); - } -} diff --git a/tests/V2/Workdays/UpdateWorkdayControllerTest.php b/tests/V2/Workdays/UpdateWorkdayControllerTest.php deleted file mode 100644 index 2ae663330..000000000 --- a/tests/V2/Workdays/UpdateWorkdayControllerTest.php +++ /dev/null @@ -1,68 +0,0 @@ -create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $report = SiteReport::factory()->create([ - 'site_id' => $site->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $workday = Workday::factory()->create([ - 'workdayable_type' => SiteReport::class, - 'workdayable_id' => $report->id, - ]); - - $payload = [ - 'amount' => 26, - 'gender' => 'female', - ]; - - $uri = '/api/v2/workdays/' . $workday->uuid; - - $this->actingAs($user) - ->patchJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->patchJson($uri, $payload) - ->assertSuccessful() - ->assertJsonPath('data.amount', 26) - ->assertJsonPath('data.gender', 'female'); - } -}