Mager updated

This commit is contained in:
Simon Pocrnjič
2025-09-27 17:45:55 +02:00
parent d17e34941b
commit 7227c888d4
74 changed files with 6339 additions and 342 deletions
+57 -4
View File
@@ -49,10 +49,14 @@ public function createAddress(Person $person, Request $request){
'description' => 'nullable|string|max:125'
]);
$address_id = $person->addresses()->create($attributes)->id;
// Dedup: avoid duplicate address per person by (address, country)
$address = $person->addresses()->firstOrCreate([
'address' => $attributes['address'],
'country' => $attributes['country'] ?? null,
], $attributes);
return response()->json([
'address' => \App\Models\Person\PersonAddress::with(['type'])->findOrFail($address_id)
'address' => \App\Models\Person\PersonAddress::with(['type'])->findOrFail($address->id)
]);
}
@@ -83,10 +87,14 @@ public function createPhone(Person $person, Request $request)
'description' => 'nullable|string|max:125'
]);
$phone_id = $person->phones()->create($attributes)->id;
// Dedup: avoid duplicate phone per person by (nu, country_code)
$phone = $person->phones()->firstOrCreate([
'nu' => $attributes['nu'],
'country_code' => $attributes['country_code'] ?? null,
], $attributes);
return response()->json([
'phone' => \App\Models\Person\PersonPhone::with(['type'])->findOrFail($phone_id)
'phone' => \App\Models\Person\PersonPhone::with(['type'])->findOrFail($phone->id)
]);
}
@@ -107,4 +115,49 @@ public function updatePhone(Person $person, int $phone_id, Request $request)
'phone' => $phone
]);
}
public function createEmail(Person $person, Request $request)
{
$attributes = $request->validate([
'value' => 'required|email:rfc,dns|max:255',
'label' => 'nullable|string|max:50',
'is_primary' => 'boolean',
'is_active' => 'boolean',
'valid' => 'boolean',
'verified_at' => 'nullable|date',
'preferences' => 'nullable|array',
'meta' => 'nullable|array',
]);
// Dedup: avoid duplicate email per person by value
$email = $person->emails()->firstOrCreate([
'value' => $attributes['value'],
], $attributes);
return response()->json([
'email' => \App\Models\Email::findOrFail($email->id)
]);
}
public function updateEmail(Person $person, int $email_id, Request $request)
{
$attributes = $request->validate([
'value' => 'required|email:rfc,dns|max:255',
'label' => 'nullable|string|max:50',
'is_primary' => 'boolean',
'is_active' => 'boolean',
'valid' => 'boolean',
'verified_at' => 'nullable|date',
'preferences' => 'nullable|array',
'meta' => 'nullable|array',
]);
$email = $person->emails()->findOrFail($email_id);
$email->update($attributes);
return response()->json([
'email' => $email
]);
}
}