Skip to content

Commit

Permalink
change document links attribute to text
Browse files Browse the repository at this point in the history
  • Loading branch information
mblajek committed Oct 8, 2024
1 parent 91e989e commit 75b9d1b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
21 changes: 21 additions & 0 deletions app/Http/Controllers/Admin/DeveloperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
use App\Http\Permissions\Permission;
use App\Models\Enums\AttributeTable;
use App\Models\Member;
use App\Models\StaffMember;
use App\Rules\Valid;
use App\Utils\Date\DateHelper;
use App\Utils\Nullable;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Artisan;
Expand Down Expand Up @@ -65,4 +67,23 @@ public function overwriteMetadata(): JsonResponse
$updated = DB::table($model->value)->where('id', $id)->update($updateData);
return new JsonResponse(data: ['data' => (bool)$updated], status: 200);
}

public function patchStaff(): JsonResponse
{
$data = $this->validate([
'id' => Valid::uuid(),
'facility_id' => Valid::uuid([Rule::exists('facilities', 'id')]),
'deactivated_at' => Valid::datetime(nullable: true),
]);

$id = Member::query()->where('user_id', $data['id'])
->where('facility_id', $data['facility_id'])->firstOrFail()
->offsetGet('staff_member_id');

$updated = StaffMember::query()->where('id', $id)->update([
'deactivated_at' => Nullable::call($data['deactivated_at'], DateHelper::zuluToDbString(...))
]);

return new JsonResponse(data: ['data' => (bool)$updated], status: 200);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#[OA\Info(version: ApiController::VERSION, title: 'Memo API')]
abstract class ApiController extends Controller
{
protected const string VERSION = '0.14.0';
protected const string VERSION = '0.14.1';
private readonly array $requestIn;

public function __construct(private readonly Request $request)
Expand Down
21 changes: 21 additions & 0 deletions app/Utils/Nullable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Utils;

class Nullable
{
public static function call(mixed $value, callable $callable): mixed
{
return ($value !== null) ? $callable($value) : null;
}

/**
* @template TValue
* @param TValue $first
* @param TValue $other
*/
public static function equals(mixed $first, mixed $other): bool
{
return ($first === null) ? ($other === null) : ($other && $first->equals($other));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/** @noinspection PhpUnusedAliasInspection */

use App\Utils\DatabaseMigrationHelper\DatabaseMigrationHelper as DMH;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {

public function up(): void
{
// documents links
DB::table('attributes')->where('id', 'e1c14100-070d-4213-8927-6b7aed9617a4')
->update(['type' => 'text']);
}

public function down(): void
{
}
};
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Route::prefix('/developer')->group(function () {
Route::get('/migrate/{hash?}', [DeveloperController::class, 'migrate']);
Route::post('/overwrite-metadata', [DeveloperController::class, 'overwriteMetadata']);
Route::post('/patch-staff', [DeveloperController::class, 'patchStaff']);
});
Route::prefix('/user')->group(function () {
Route::get('/list', [AdminUserController::class, 'list']);
Expand Down

0 comments on commit 75b9d1b

Please sign in to comment.