|
@@ -49,26 +49,29 @@ class ClientService
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
- $user = User::when($data['email'], function ($q) use ($data) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $user = User::when(!empty($data['email']), function ($q) use ($data) {
|
|
|
$q->where('email', $data['email']);
|
|
$q->where('email', $data['email']);
|
|
|
})
|
|
})
|
|
|
- ->when($data['phone'], function ($q) use ($data) {
|
|
|
|
|
|
|
+ ->when(!empty($data['phone']), function ($q) use ($data) {
|
|
|
$q->where('phone', $data['phone']);
|
|
$q->where('phone', $data['phone']);
|
|
|
})
|
|
})
|
|
|
->where('type', 'CLIENT')
|
|
->where('type', 'CLIENT')
|
|
|
->where('code', $data['code'])
|
|
->where('code', $data['code'])
|
|
|
- ->where('validated_code', false)
|
|
|
|
|
->first();
|
|
->first();
|
|
|
|
|
|
|
|
- if(!$user) {
|
|
|
|
|
|
|
+ if (!$user) {
|
|
|
throw new \Exception(__('messages.user_not_found_or_code_not_validated'));
|
|
throw new \Exception(__('messages.user_not_found_or_code_not_validated'));
|
|
|
}
|
|
}
|
|
|
- $user->name = $data['name'];
|
|
|
|
|
- $user->save();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($data['name'])) {
|
|
|
|
|
+ $user->name = $data['name'];
|
|
|
|
|
+ $user->save();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$client = new Client();
|
|
$client = new Client();
|
|
|
$client->user_id = $user->id;
|
|
$client->user_id = $user->id;
|
|
|
- $client->document = $data['document'];
|
|
|
|
|
|
|
+ $client->document = $data['document'] ?? null;
|
|
|
$client->save();
|
|
$client->save();
|
|
|
$client->refresh();
|
|
$client->refresh();
|
|
|
|
|
|
|
@@ -77,17 +80,25 @@ class ClientService
|
|
|
$address->source_id = $client->id;
|
|
$address->source_id = $client->id;
|
|
|
$address->zip_code = $data['zip_code'] ?? null;
|
|
$address->zip_code = $data['zip_code'] ?? null;
|
|
|
$address->address = $data['address'] ?? null;
|
|
$address->address = $data['address'] ?? null;
|
|
|
- $address->has_complement = $data['has_complement'] ?? null;
|
|
|
|
|
|
|
+ $address->number = $data['number'] ?? null;
|
|
|
|
|
+ $address->district = $data['district'] ?? null;
|
|
|
|
|
+ $address->has_complement = $data['has_complement'] ?? false;
|
|
|
|
|
+ $address->complement = $data['complement'] ?? null;
|
|
|
$address->nickname = $data['nickname'] ?? null;
|
|
$address->nickname = $data['nickname'] ?? null;
|
|
|
$address->instructions = $data['instructions'] ?? null;
|
|
$address->instructions = $data['instructions'] ?? null;
|
|
|
- $address->address_type = $data['address_type'] ?? null;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- $state = State::where('code', $data['state'])->first();
|
|
|
|
|
- $city = City::where('name', $data['city'])->where('state_id', $state->id)->first();
|
|
|
|
|
|
|
+ $address->address_type = $data['address_type'] ?? 'home';
|
|
|
|
|
+ $address->latitude = $data['latitude'] ?? null;
|
|
|
|
|
+ $address->longitude = $data['longitude'] ?? null;
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($data['state']) && !empty($data['city'])) {
|
|
|
|
|
+ $state = State::where('code', $data['state'])->first();
|
|
|
|
|
+ if ($state) {
|
|
|
|
|
+ $city = City::where('name', $data['city'])->where('state_id', $state->id)->first();
|
|
|
|
|
+ $address->state_id = $state->id;
|
|
|
|
|
+ $address->city_id = $city?->id;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $address->state_id = $state->id;
|
|
|
|
|
- $address->city_id = $city->id;
|
|
|
|
|
$address->save();
|
|
$address->save();
|
|
|
|
|
|
|
|
$result = $this->authService->loginWithEmail(
|
|
$result = $this->authService->loginWithEmail(
|