fix: Fix API Responses and logic
This commit is contained in:
parent
122151da28
commit
d4c72ed804
6 changed files with 18 additions and 16 deletions
|
|
@ -26,7 +26,7 @@ class AsInput implements CastsAttributes
|
|||
// phpcs:enable
|
||||
/** @var array<string, integer|string|boolean> $inputData */
|
||||
$inputData = \json_decode($value, true);
|
||||
$inputClass = InputTypeEnum::make($inputData['type'])->inputTypes();
|
||||
$inputClass = InputTypeEnum::make($inputData['type'])->getInputClass();
|
||||
return $inputClass::from(InputData::make(...\array_values($inputData)), $inputData['required'] ?? false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ enum InputTypeEnum: int
|
|||
];
|
||||
|
||||
/**
|
||||
* Get translation key.
|
||||
* Get InputType class based on the enum value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function inputTypes(): string
|
||||
public function getInputClass(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::text => InputText::class,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class AppController extends Controller
|
|||
$response = [];
|
||||
$settings = Setting::query()
|
||||
->where('tenant_id', $tenantKey)
|
||||
->where('key', 'Button1')
|
||||
->orWhere('key', 'Button1')
|
||||
->orWhere('key', 'Button2')
|
||||
->orWhere('key', 'Button3')
|
||||
->get();
|
||||
|
|
|
|||
|
|
@ -32,14 +32,13 @@ use Illuminate\Support\Facades\URL;
|
|||
class SyncController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return \App\Http\Resources\ApiResponseResource
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
*/
|
||||
public function getUsers(): \App\Http\Resources\ApiResponseResource
|
||||
public function getUsers(): \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
{
|
||||
$users = AppUserResource::collection(
|
||||
return AppUserResource::collection(
|
||||
AppUser::query()->where('tenant_id', \tenant()->getKey())->where('status', 1)->get()
|
||||
)->toArray(request());
|
||||
return new ApiResponseResource("OK", $users);
|
||||
);
|
||||
}
|
||||
|
||||
// *** --- START CONTACTS ---
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Enums\Formularies\InputTypeEnum;
|
|||
use App\Lib\Inputs\Definition\InputData;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class UpsertContactsRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -68,10 +69,7 @@ class UpsertContactsRequest extends FormRequest
|
|||
'contacts.*.data.*' => 'array',
|
||||
'contacts.*.data.*.title' => 'present|string|min:1|max:255',
|
||||
'contacts.*.data.*.formSlug' => 'present|string|min:1|max:255',
|
||||
'contacts.*.data.*.type' => 'present|in:' . implode(
|
||||
',',
|
||||
array_column(InputTypeEnum::cases(), 'name')
|
||||
),
|
||||
'contacts.*.data.*.type' => ['present', new Enum(InputTypeEnum::class)],
|
||||
'contacts.*.data.*.value' => 'present',
|
||||
'contacts.*.data.*.required' => 'present|boolean',
|
||||
'contacts.*.data.*.send_to_app_user_id' => 'nullable|numeric',
|
||||
|
|
@ -108,10 +106,15 @@ class UpsertContactsRequest extends FormRequest
|
|||
'error' => "wrong formSlug on data index '{$index}'"
|
||||
]);
|
||||
}
|
||||
$type = InputTypeEnum::make($data->get('type') ? $data->get('type') : null, 'name');
|
||||
$type = InputTypeEnum::make($data->get('type') ? $data->get('type') : null);
|
||||
if (\is_null($type)) {
|
||||
throw ValidationException::withMessages([
|
||||
'error' => "wrong inputType on data index '{$index}'"
|
||||
]);
|
||||
}
|
||||
$value = $data['value'] ?? null;
|
||||
$required = $data->get('required') ? true : false;
|
||||
$inputClass = $type->inputTypes();
|
||||
$inputClass = $type->getInputClass();
|
||||
return $inputClass::from(InputData::make(
|
||||
$title,
|
||||
$formSlug,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class DocumentResource extends JsonResource
|
|||
'type' => $document->type,
|
||||
'directory' => $document->directory_id,
|
||||
'path' => $document->path,
|
||||
'lang' => $document->lang->value,
|
||||
'lang' => $document->lang->name,
|
||||
'published' => ($document->status) ? 1 : 0,
|
||||
'parent' => $document->document_id,
|
||||
'created_at' => $document->created_at,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue