Skip to content

Commit

Permalink
fix: set deceased information with removing date and reminder (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Mar 3, 2019
1 parent ec8835b commit 59064fb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Enhancements:

Fixes:

* Fix setting deceased information with removing date and reminder
* Fix contact information update
* Fix adding people on activity create and update
* Fix setting a relationship without selecting any birthdate option
Expand Down
41 changes: 40 additions & 1 deletion app/Services/Contact/Contact/UpdateDeceasedInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Contact\Contact;
use App\Models\Instance\SpecialDate;
use App\Services\Contact\Reminder\CreateReminder;
use App\Services\Contact\Reminder\DestroyReminder;

class UpdateDeceasedInformation extends BaseService
{
Expand Down Expand Up @@ -41,11 +42,49 @@ public function execute(array $data)
$contact = Contact::where('account_id', $data['account_id'])
->findOrFail($data['contact_id']);

$this->clearRelatedReminder($contact);

$this->clearRelatedSpecialDate($contact);

$this->manageDeceasedDate($data, $contact);

return $contact;
}

/**
* Delete related reminder.
*
* @param Contact $contact
* @return void
*/
private function clearRelatedReminder(Contact $contact)
{
if (is_null($contact->deceased_reminder_id)) {
return;
}

app(DestroyReminder::class)->execute([
'account_id' => $contact->account_id,
'reminder_id' => $contact->deceased_reminder_id,
]);
}

/**
* Delete related special date.
*
* @param Contact $contact
* @return void
*/
private function clearRelatedSpecialDate(Contact $contact)
{
if (is_null($contact->deceased_special_date_id)) {
return;
}

$specialDate = SpecialDate::find($contact->deceased_special_date_id);
$specialDate->delete();
}

/**
* Update deceased date information depending on the type of information.
*
Expand Down Expand Up @@ -74,7 +113,7 @@ private function manageDeceasedDate(array $data, Contact $contact): void
}

/**
* Case where we have a year, month and day for the birthday.
* Case where we have a year, month and day for the date.
*
* @param array $data
* @param Contact $contact
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Contact/Reminder/CreateReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function rules()
return [
'account_id' => 'required|integer|exists:accounts,id',
'contact_id' => 'required|integer|exists:contacts,id',
'initial_date' => 'required|date|date_format:Y-m-d',
'initial_date' => 'required|date_format:Y-m-d',
'frequency_type' => [
'required',
Rule::in(Reminder::$frequencyTypes),
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Contact/Reminder/UpdateReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function rules()
'account_id' => 'required|integer|exists:accounts,id',
'contact_id' => 'required|integer|exists:contacts,id',
'reminder_id' => 'required|integer|exists:reminders,id',
'initial_date' => 'required|date|date_format:Y-m-d',
'initial_date' => 'required|date_format:Y-m-d',
'frequency_type' => [
'required',
Rule::in(Reminder::$frequencyTypes),
Expand Down
18 changes: 9 additions & 9 deletions database/seeds/FakeContentTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ public function populateDeceasedDate()
app(UpdateDeceasedInformation::class)->execute([
'account_id' => $this->contact->account_id,
'contact_id' => $this->contact->id,
'is_deceased' => (rand(1, 2) == 1) ? true : false,
'is_date_known' => (rand(1, 2) == 1) ? true : false,
'is_deceased' => rand(1, 2) == 1,
'is_date_known' => rand(1, 2) == 1,
'day' => (int) $birthdate->format('d'),
'month' => (int) $birthdate->format('m'),
'year' => (int) $birthdate->format('Y'),
'add_reminder' => (rand(1, 2) == 1) ? true : false,
'add_reminder' => rand(1, 2) == 1,
]);
}
}
Expand All @@ -177,13 +177,13 @@ public function populateBirthday()
app(UpdateBirthdayInformation::class)->execute([
'account_id' => $this->contact->account_id,
'contact_id' => $this->contact->id,
'is_date_known' => (rand(1, 2) == 1) ? true : false,
'is_date_known' => rand(1, 2) == 1,
'day' => (int) $birthdate->format('d'),
'month' => (int) $birthdate->format('m'),
'year' => (int) $birthdate->format('Y'),
'is_age_based' => (rand(1, 2) == 1) ? true : false,
'is_age_based' => rand(1, 2) == 1,
'age' => rand(1, 99),
'add_reminder' => (rand(1, 2) == 1) ? true : false,
'add_reminder' => rand(1, 2) == 1,
]);
}
}
Expand Down Expand Up @@ -255,13 +255,13 @@ public function populateRelationships()
app(UpdateBirthdayInformation::class)->execute([
'account_id' => $this->contact->account_id,
'contact_id' => $relatedContact->id,
'is_date_known' => (rand(1, 2) == 1) ? true : false,
'is_date_known' => rand(1, 2) == 1,
'day' => (int) $relatedContactBirthDate->format('d'),
'month' => (int) $relatedContactBirthDate->format('m'),
'year' => (int) $relatedContactBirthDate->format('Y'),
'is_age_based' => (rand(1, 2) == 1) ? true : false,
'is_age_based' => rand(1, 2) == 1,
'age' => rand(1, 99),
'add_reminder' => (rand(1, 2) == 1) ? true : false,
'add_reminder' => rand(1, 2) == 1,
]);

// set relationship
Expand Down

0 comments on commit 59064fb

Please sign in to comment.