diff --git a/app/Domains/Metadata/Concerns/HasCustomFields.php b/app/Domains/Metadata/Concerns/HasCustomFields.php deleted file mode 100644 index 72f5b785..00000000 --- a/app/Domains/Metadata/Concerns/HasCustomFields.php +++ /dev/null @@ -1,43 +0,0 @@ -morphMany(CustomFieldValue::class, 'custom_field_valuable'); - } - - protected static function booted() - { - static::deleting(function ($data) { - if ($data->fields()->exists()) { - $data->fields()->delete(); - } - }); - } - - public function getCustomFieldBySlug($slug) - { - return $this->fields() - ->with('customField') - ->whereHas('customField', function ($query) use ($slug) { - $query->where('slug', $slug); - })->first(); - } - - public function getCustomFieldValueBySlug($slug) - { - $value = $this->getCustomFieldBySlug($slug); - - if ($value) { - return $value->defaultAnswer; - } - - return null; - } -} diff --git a/app/Domains/Metadata/Http/Controllers/CustomFieldsController.php b/app/Domains/Metadata/Http/Controllers/CustomFieldsController.php deleted file mode 100644 index 8b406fed..00000000 --- a/app/Domains/Metadata/Http/Controllers/CustomFieldsController.php +++ /dev/null @@ -1,110 +0,0 @@ -authorize('viewAny', CustomField::class); - - $limit = $request->has('limit') ? $request->limit : 5; - - $customFields = CustomField::applyFilters($request->all()) - ->whereCompany() - ->latest() - ->paginateData($limit); - - return CustomFieldResource::collection($customFields); - } - - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\CustomFieldRequest $request - * @return Response - */ - public function store(CustomFieldRequest $request) - { - $this->authorize('create', CustomField::class); - - $customField = $this->customFieldService->create( - $request->validated(), - $request->input('default_answer'), - (int) $request->header('company'), - ); - - return new CustomFieldResource($customField); - } - - /** - * Display the specified resource. - * - * @param int $id - * @return Response - */ - public function show(CustomField $customField) - { - $this->authorize('view', $customField); - - return new CustomFieldResource($customField); - } - - /** - * Update the specified resource in storage. - * - * @param Request $request - * @param int $id - * @return Response - */ - public function update(CustomFieldRequest $request, CustomField $customField) - { - $this->authorize('update', $customField); - - $this->customFieldService->update( - $customField, - $request->validated(), - $request->input('default_answer'), - ); - - return new CustomFieldResource($customField); - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return Response - */ - public function destroy(CustomField $customField) - { - $this->authorize('delete', $customField); - - if ($customField->customFieldValues()->exists()) { - $customField->customFieldValues()->delete(); - } - - $customField->forceDelete(); - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Domains/Metadata/Http/Controllers/NotesController.php b/app/Domains/Metadata/Http/Controllers/NotesController.php deleted file mode 100644 index 19ac37a5..00000000 --- a/app/Domains/Metadata/Http/Controllers/NotesController.php +++ /dev/null @@ -1,108 +0,0 @@ -authorize('view notes'); - - $limit = $request->limit ?? 10; - - $notes = Note::latest() - ->whereCompany() - ->applyFilters($request->all()) - ->paginate($limit); - - return NoteResource::collection($notes); - } - - /** - * Store a newly created resource in storage. - * - * @param Request $request - * @return Response - */ - public function store(NotesRequest $request) - { - $this->authorize('manage notes'); - - $note = Note::create($request->getNotesPayload()); - - if ($note->is_default) { - Note::where('id', '!=', $note->id) - ->where('type', $note->type) - ->where('is_default', true) - ->update([ - 'is_default' => false, - ]); - } - - return new NoteResource($note); - } - - /** - * Display the specified resource. - * - * @return Response - */ - public function show(Note $note) - { - $this->authorize('view notes', $note); - - return new NoteResource($note); - } - - /** - * Update the specified resource in storage. - * - * @param Request $request - * @return Response - */ - public function update(NotesRequest $request, Note $note) - { - $this->authorize('manage notes', $note); - - $note->update($request->getNotesPayload()); - - if ($note->is_default) { - Note::where('id', '!=', $note->id) - ->where('type', $note->type) - ->where('is_default', true) - ->update([ - 'is_default' => false, - ]); - } - - return new NoteResource($note); - } - - /** - * Remove the specified resource from storage. - * - * @return Response - */ - public function destroy(Note $note) - { - $this->authorize('manage notes', $note); - - $note->delete(); - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Domains/Metadata/Http/Requests/CustomFieldRequest.php b/app/Domains/Metadata/Http/Requests/CustomFieldRequest.php deleted file mode 100644 index c0eb3d56..00000000 --- a/app/Domains/Metadata/Http/Requests/CustomFieldRequest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'required', - 'label' => 'required', - 'model_type' => 'required', - 'order' => 'required', - 'type' => 'required', - 'is_required' => 'required|boolean', - 'options' => 'array', - 'placeholder' => 'string|nullable', - ]; - } -} diff --git a/app/Domains/Metadata/Http/Requests/NotesRequest.php b/app/Domains/Metadata/Http/Requests/NotesRequest.php deleted file mode 100644 index 9ff0a8c9..00000000 --- a/app/Domains/Metadata/Http/Requests/NotesRequest.php +++ /dev/null @@ -1,62 +0,0 @@ - [ - 'required', - ], - 'name' => [ - 'required', - Rule::unique('notes') - ->where('company_id', $this->header('company')) - ->where('type', $this->type), - ], - 'notes' => [ - 'required', - ], - 'is_default' => [ - 'required', - ], - ]; - - if ($this->isMethod('PUT')) { - $rules['name'] = [ - 'required', - Rule::unique('notes') - ->ignore($this->route('note')->id) - ->where('type', $this->type) - ->where('company_id', $this->header('company')), - ]; - } - - return $rules; - } - - public function getNotesPayload() - { - return collect($this->validated()) - ->merge([ - 'company_id' => $this->header('company'), - ]) - ->toArray(); - } -} diff --git a/app/Domains/Metadata/Http/Resources/CustomFieldResource.php b/app/Domains/Metadata/Http/Resources/CustomFieldResource.php deleted file mode 100644 index 6a5306c4..00000000 --- a/app/Domains/Metadata/Http/Resources/CustomFieldResource.php +++ /dev/null @@ -1,43 +0,0 @@ - $this->id, - 'name' => $this->name, - 'slug' => $this->slug, - 'label' => $this->label, - 'model_type' => $this->model_type, - 'type' => $this->type, - 'placeholder' => $this->placeholder, - 'options' => $this->options, - 'boolean_answer' => $this->boolean_answer, - 'date_answer' => $this->date_answer, - 'time_answer' => $this->time_answer, - 'string_answer' => $this->string_answer, - 'number_answer' => $this->number_answer, - 'date_time_answer' => $this->date_time_answer, - 'is_required' => $this->is_required, - 'in_use' => $this->in_use, - 'order' => $this->order, - 'company_id' => $this->company_id, - 'default_answer' => $this->default_answer, - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } -} diff --git a/app/Domains/Metadata/Http/Resources/CustomFieldValueResource.php b/app/Domains/Metadata/Http/Resources/CustomFieldValueResource.php deleted file mode 100644 index e37f0e91..00000000 --- a/app/Domains/Metadata/Http/Resources/CustomFieldValueResource.php +++ /dev/null @@ -1,64 +0,0 @@ - $this->id, - 'custom_field_valuable_type' => ModelIdentityMap::publicType($this->custom_field_valuable_type), - 'custom_field_valuable_id' => $this->custom_field_valuable_id, - 'type' => $this->type, - 'boolean_answer' => $this->boolean_answer, - 'date_answer' => $this->date_answer, - 'time_answer' => $this->time_answer, - 'string_answer' => $this->string_answer, - 'number_answer' => $this->number_answer, - 'date_time_answer' => $this->date_time_answer, - 'custom_field_id' => $this->custom_field_id, - 'company_id' => $this->company_id, - 'default_answer' => $this->defaultAnswer, - 'default_formatted_answer' => $this->dateTimeFormat(), - 'custom_field' => $this->when($this->customField()->exists(), function () { - return new CustomFieldResource($this->customField); - }), - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } - - public function dateTimeFormat() - { - $key = getCustomFieldValueKey($this->type); - - $answer = $this->default_answer; - if (! $answer) { - return null; - } - - if ($key == 'date_time_answer') { - return Carbon::parse($answer)->format('Y-m-d H:i'); - } - - if ($key == 'date_answer') { - return Carbon::parse($answer)->format(CompanySetting::getSetting('carbon_date_format', $this->company_id)); - } - - return $answer; - } -} diff --git a/app/Domains/Metadata/Http/Resources/CustomerPortal/CustomFieldResource.php b/app/Domains/Metadata/Http/Resources/CustomerPortal/CustomFieldResource.php deleted file mode 100644 index 859a8b5d..00000000 --- a/app/Domains/Metadata/Http/Resources/CustomerPortal/CustomFieldResource.php +++ /dev/null @@ -1,43 +0,0 @@ - $this->id, - 'name' => $this->name, - 'slug' => $this->slug, - 'label' => $this->label, - 'model_type' => $this->model_type, - 'type' => $this->type, - 'placeholder' => $this->placeholder, - 'options' => $this->options, - 'boolean_answer' => $this->boolean_answer, - 'date_answer' => $this->date_answer, - 'time_answer' => $this->time_answer, - 'string_answer' => $this->string_answer, - 'number_answer' => $this->number_answer, - 'date_time_answer' => $this->date_time_answer, - 'is_required' => $this->is_required, - 'in_use' => $this->in_use, - 'order' => $this->order, - 'company_id' => $this->company_id, - 'default_answer' => $this->default_answer, - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } -} diff --git a/app/Domains/Metadata/Http/Resources/CustomerPortal/CustomFieldValueResource.php b/app/Domains/Metadata/Http/Resources/CustomerPortal/CustomFieldValueResource.php deleted file mode 100644 index efcb4e69..00000000 --- a/app/Domains/Metadata/Http/Resources/CustomerPortal/CustomFieldValueResource.php +++ /dev/null @@ -1,41 +0,0 @@ - $this->id, - 'custom_field_valuable_type' => ModelIdentityMap::publicType($this->custom_field_valuable_type), - 'custom_field_valuable_id' => $this->custom_field_valuable_id, - 'type' => $this->type, - 'boolean_answer' => $this->boolean_answer, - 'date_answer' => $this->date_answer, - 'time_answer' => $this->time_answer, - 'string_answer' => $this->string_answer, - 'number_answer' => $this->number_answer, - 'date_time_answer' => $this->date_time_answer, - 'custom_field_id' => $this->custom_field_id, - 'company_id' => $this->company_id, - 'default_answer' => $this->defaultAnswer, - 'custom_field' => $this->when($this->customField()->exists(), function () { - return new CustomFieldResource($this->customField); - }), - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } -} diff --git a/app/Domains/Metadata/Http/Resources/NoteResource.php b/app/Domains/Metadata/Http/Resources/NoteResource.php deleted file mode 100644 index f1aa32bc..00000000 --- a/app/Domains/Metadata/Http/Resources/NoteResource.php +++ /dev/null @@ -1,29 +0,0 @@ - $this->id, - 'type' => $this->type, - 'name' => $this->name, - 'notes' => $this->notes, - 'is_default' => $this->is_default, - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } -} diff --git a/app/Domains/Metadata/Models/CustomField.php b/app/Domains/Metadata/Models/CustomField.php deleted file mode 100644 index 3707e3ff..00000000 --- a/app/Domains/Metadata/Models/CustomField.php +++ /dev/null @@ -1,110 +0,0 @@ - 'array', - ]; - } - - public function setTimeAnswerAttribute(mixed $value): void - { - if ($value && $value != null) { - $this->attributes['time_answer'] = date('H:i:s', strtotime($value)); - } - } - - public function setOptionsAttribute(mixed $value): void - { - $this->attributes['options'] = json_encode($value); - } - - public function getDefaultAnswerAttribute() - { - $value_type = getCustomFieldValueKey($this->type); - - return $this->$value_type; - } - - public function getInUseAttribute() - { - return $this->customFieldValues()->exists(); - } - - public function company(): BelongsTo - { - return $this->belongsTo(Company::class); - } - - public function customFieldValues(): HasMany - { - return $this->hasMany(CustomFieldValue::class); - } - - public function scopeWhereCompany($query) - { - return $query->where('custom_fields.company_id', request()->header('company')); - } - - public function scopeWhereSearch($query, $search) - { - $query->where(function ($query) use ($search) { - $query->where('label', 'LIKE', '%'.$search.'%') - ->orWhere('name', 'LIKE', '%'.$search.'%'); - }); - } - - public function scopePaginateData($query, $limit) - { - if ($limit == 'all') { - return $query->get(); - } - - return $query->paginate($limit); - } - - public function scopeApplyFilters($query, array $filters) - { - $filters = collect($filters); - - if ($filters->get('type')) { - $query->whereType($filters->get('type')); - } - - if ($filters->get('search')) { - $query->whereSearch($filters->get('search')); - } - } - - public function scopeWhereType($query, $type) - { - $query->where('custom_fields.model_type', $type); - } -} diff --git a/app/Domains/Metadata/Models/CustomFieldValue.php b/app/Domains/Metadata/Models/CustomFieldValue.php deleted file mode 100644 index 8c3b9601..00000000 --- a/app/Domains/Metadata/Models/CustomFieldValue.php +++ /dev/null @@ -1,60 +0,0 @@ -attributes['time_answer'] = date('H:i:s', strtotime($value)); - } else { - $this->attributes['time_answer'] = null; - } - } - - public function getDefaultAnswerAttribute() - { - $value_type = getCustomFieldValueKey($this->type); - - return $this->$value_type; - } - - public function company(): BelongsTo - { - return $this->belongsTo(Company::class); - } - - public function customField(): BelongsTo - { - return $this->belongsTo(CustomField::class); - } - - public function customFieldValuable(): MorphTo - { - return $this->morphTo(); - } -} diff --git a/app/Domains/Metadata/Models/Note.php b/app/Domains/Metadata/Models/Note.php deleted file mode 100644 index 1e94fa2e..00000000 --- a/app/Domains/Metadata/Models/Note.php +++ /dev/null @@ -1,51 +0,0 @@ -belongsTo(Company::class); - } - - public function scopeApplyFilters(Builder $query, array $filters): void - { - $filters = collect($filters); - - if ($filters->get('type')) { - $query->whereType($filters->get('type')); - } - - if ($filters->get('search')) { - $query->whereSearch($filters->get('search')); - } - } - - public function scopeWhereSearch(Builder $query, string $search): void - { - $query->where('name', 'LIKE', '%'.$search.'%'); - } - - public function scopeWhereType(Builder $query, string $type): Builder - { - return $query->where('type', $type); - } - - public function scopeWhereCompany(Builder $query): void - { - $query->where('notes.company_id', request()->header('company')); - } -} diff --git a/app/Domains/Metadata/Policies/CustomFieldPolicy.php b/app/Domains/Metadata/Policies/CustomFieldPolicy.php deleted file mode 100644 index ea3da97c..00000000 --- a/app/Domains/Metadata/Policies/CustomFieldPolicy.php +++ /dev/null @@ -1,111 +0,0 @@ -hasCompany($customField->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can create models. - * - * @return mixed - */ - public function create(User $user): bool - { - if (BouncerFacade::can('create-custom-field', CustomField::class)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can update the model. - * - * @return mixed - */ - public function update(User $user, CustomField $customField): bool - { - if (BouncerFacade::can('edit-custom-field', $customField) && $user->hasCompany($customField->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can delete the model. - * - * @return mixed - */ - public function delete(User $user, CustomField $customField): bool - { - if (BouncerFacade::can('delete-custom-field', $customField) && $user->hasCompany($customField->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can restore the model. - * - * @return mixed - */ - public function restore(User $user, CustomField $customField): bool - { - if (BouncerFacade::can('delete-custom-field', $customField) && $user->hasCompany($customField->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can permanently delete the model. - * - * @return mixed - */ - public function forceDelete(User $user, CustomField $customField): bool - { - if (BouncerFacade::can('delete-custom-field', $customField) && $user->hasCompany($customField->company_id)) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Metadata/Policies/NotePolicy.php b/app/Domains/Metadata/Policies/NotePolicy.php deleted file mode 100644 index 85d439b1..00000000 --- a/app/Domains/Metadata/Policies/NotePolicy.php +++ /dev/null @@ -1,33 +0,0 @@ -hasCompany($note->company_id); - } - - public function viewNotes(User $user, ?Note $note = null) - { - if (! BouncerFacade::can('view-all-notes', $note ?? Note::class)) { - return false; - } - - return $note === null || $user->hasCompany($note->company_id); - } -}