Skip to content

Commit

Permalink
feat: activity on contact page (monicahq/chandler#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Jun 1, 2022
1 parent 1e20934 commit e2a1780
Show file tree
Hide file tree
Showing 135 changed files with 4,282 additions and 406 deletions.
19 changes: 0 additions & 19 deletions app/Console/Commands/SetupDummyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,8 @@ private function stop(): void
$this->line('-----------------------------');
$this->info('| You can now sign in with one of these two accounts:');
$this->line('| An account with a lot of data:');
$this->line('| First user >>>>>>>>>>>>>>>>>:');
$this->line('| username: admin@admin.com');
$this->line('| password: admin123');
$this->line('| Second user >>>>>>>>>>>>>>>>>:');
$this->line('| username: regis@regis.com');
$this->line('| password: admin123');
$this->line('|------------------------–––-');
$this->line('|A blank account:');
$this->line('| username: blank@blank.com');
Expand All @@ -121,21 +117,6 @@ private function createFirstUsers(): void
]);
$this->firstUser->email_verified_at = Carbon::now();
$this->firstUser->save();

sleep(5);

$this->info('☐ Create second user of the account');

$this->secondUser = (new CreateAccount)->execute([
'email' => 'regis@regis.com',
'password' => 'admin123',
'first_name' => 'Dwight',
'last_name' => 'Schrutt',
]);
$this->secondUser->account_id = $this->firstUser->account_id;
$this->secondUser->email_verified_at = Carbon::now();
$this->secondUser->save();

sleep(5);
}

Expand Down
371 changes: 371 additions & 0 deletions app/Jobs/SetupAccount.php

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function users()
*
* @return HasMany
*/
public function templates()
public function templates(): HasMany
{
return $this->hasMany(Template::class);
}
Expand All @@ -36,7 +36,7 @@ public function templates()
*
* @return HasMany
*/
public function modules()
public function modules(): HasMany
{
return $this->hasMany(Module::class);
}
Expand All @@ -46,7 +46,7 @@ public function modules()
*
* @return HasMany
*/
public function groupTypes()
public function groupTypes(): HasMany
{
return $this->hasMany(GroupType::class);
}
Expand All @@ -56,7 +56,7 @@ public function groupTypes()
*
* @return HasMany
*/
public function relationshipGroupTypes()
public function relationshipGroupTypes(): HasMany
{
return $this->hasMany(RelationshipGroupType::class);
}
Expand All @@ -66,7 +66,7 @@ public function relationshipGroupTypes()
*
* @return HasMany
*/
public function genders()
public function genders(): HasMany
{
return $this->hasMany(Gender::class);
}
Expand All @@ -76,7 +76,7 @@ public function genders()
*
* @return HasMany
*/
public function pronouns()
public function pronouns(): HasMany
{
return $this->hasMany(Pronoun::class);
}
Expand All @@ -86,7 +86,7 @@ public function pronouns()
*
* @return HasMany
*/
public function contactInformationTypes()
public function contactInformationTypes(): HasMany
{
return $this->hasMany(ContactInformationType::class);
}
Expand All @@ -96,7 +96,7 @@ public function contactInformationTypes()
*
* @return HasMany
*/
public function addressTypes()
public function addressTypes(): HasMany
{
return $this->hasMany(AddressType::class);
}
Expand All @@ -106,7 +106,7 @@ public function addressTypes()
*
* @return HasMany
*/
public function petCategories()
public function petCategories(): HasMany
{
return $this->hasMany(PetCategory::class);
}
Expand All @@ -116,7 +116,7 @@ public function petCategories()
*
* @return HasMany
*/
public function emotions()
public function emotions(): HasMany
{
return $this->hasMany(Emotion::class);
}
Expand All @@ -126,7 +126,7 @@ public function emotions()
*
* @return BelongsToMany
*/
public function currencies()
public function currencies(): BelongsToMany
{
return $this->belongsToMany(Currency::class, 'account_currencies', 'account_id', 'currency_id')
->withPivot('active')
Expand All @@ -138,7 +138,7 @@ public function currencies()
*
* @return HasMany
*/
public function callReasonTypes()
public function callReasonTypes(): HasMany
{
return $this->hasMany(CallReasonType::class);
}
Expand All @@ -148,8 +148,18 @@ public function callReasonTypes()
*
* @return HasMany
*/
public function activityTypes()
public function activityTypes(): HasMany
{
return $this->hasMany(ActivityType::class);
}

/**
* Get the life event categories associated with the account.
*
* @return HasMany
*/
public function lifeEventCategories(): HasMany
{
return $this->hasMany(LifeEventCategory::class);
}
}
2 changes: 1 addition & 1 deletion app/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Activity extends Model
*
* @return BelongsTo
*/
public function activityType()
public function activityType(): BelongsTo
{
return $this->belongsTo(ActivityType::class);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/ActivityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ActivityType extends Model
*
* @return BelongsTo
*/
public function account()
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
Expand All @@ -38,7 +38,7 @@ public function account()
*
* @return HasMany
*/
public function activities()
public function activities(): HasMany
{
return $this->hasMany(Activity::class, 'activity_type_id');
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Address extends Model
*
* @return BelongsTo
*/
public function contact()
public function contact(): BelongsTo
{
return $this->belongsTo(Contact::class);
}
Expand All @@ -56,7 +56,7 @@ public function contact()
*
* @return BelongsTo
*/
public function addressType()
public function addressType(): BelongsTo
{
return $this->belongsTo(AddressType::class);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AddressType extends Model
*
* @return BelongsTo
*/
public function account()
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Models/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AuditLog extends Model
*
* @return BelongsTo
*/
public function account()
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
Expand All @@ -40,7 +40,7 @@ public function account()
*
* @return BelongsTo
*/
public function author()
public function author(): BelongsTo
{
return $this->BelongsTo(User::class);
}
Expand All @@ -51,7 +51,7 @@ public function author()
* @param mixed $value
* @return mixed
*/
public function getObjectAttribute($value)
public function getObjectAttribute($value): mixed
{
return json_decode($this->objects);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Avatar extends Model
*
* @return BelongsTo
*/
public function contact()
public function contact(): BelongsTo
{
return $this->belongsTo(Contact::class);
}
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Call extends Model
*
* @return BelongsTo
*/
public function contact()
public function contact(): BelongsTo
{
return $this->belongsTo(Contact::class);
}
Expand All @@ -72,7 +72,7 @@ public function contact()
*
* @return BelongsTo
*/
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class);
}
Expand All @@ -82,7 +82,7 @@ public function author()
*
* @return BelongsTo
*/
public function callReason()
public function callReason(): BelongsTo
{
return $this->belongsTo(CallReason::class, 'call_reason_id');
}
Expand All @@ -92,7 +92,7 @@ public function callReason()
*
* @return BelongsTo
*/
public function emotion()
public function emotion(): BelongsTo
{
return $this->belongsTo(Emotion::class);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/CallReason.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CallReason extends Model
*
* @return BelongsTo
*/
public function callReasonType()
public function callReasonType(): BelongsTo
{
return $this->belongsTo(CallReasonType::class);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/CallReasonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CallReasonType extends Model
*
* @return BelongsTo
*/
public function account()
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
Expand All @@ -38,7 +38,7 @@ public function account()
*
* @return HasMany
*/
public function callReasons()
public function callReasons(): HasMany
{
return $this->hasMany(CallReason::class);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Company extends Model
*
* @return BelongsTo
*/
public function vault()
public function vault(): BelongsTo
{
return $this->belongsTo(Vault::class);
}
Expand Down
36 changes: 4 additions & 32 deletions app/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function avatar(): BelongsTo
*
* @return HasMany
*/
public function avatars()
public function avatars(): HasMany
{
return $this->hasMany(Avatar::class);
}
Expand All @@ -266,7 +266,7 @@ public function avatars()
*
* @return HasMany
*/
public function tasks()
public function tasks(): HasMany
{
return $this->hasMany(ContactTask::class);
}
Expand All @@ -276,7 +276,7 @@ public function tasks()
*
* @return HasMany
*/
public function calls()
public function calls(): HasMany
{
return $this->hasMany(Call::class);
}
Expand All @@ -286,7 +286,7 @@ public function calls()
*
* @return HasMany
*/
public function pets()
public function pets(): HasMany
{
return $this->hasMany(Pet::class);
}
Expand Down Expand Up @@ -340,32 +340,4 @@ protected function age(): Attribute
}
);
}

/**
* Get the age of the contact.
* The birthdate is stored in a ContactImportantDate object, of the
* TYPE_BIRTHDATE type. So we need to find if a date of this type exists.
*
* @return null|int
*/
public function getAge(): ?int
{
$type = ContactImportantDateType::where('vault_id', $this->vault_id)
->where('internal_type', ContactImportantDate::TYPE_BIRTHDATE)
->first();

if (! $type) {
return null;
}

$birthdate = $this->dates()
->where('contact_important_date_type_id', $type->id)
->first();

if (! $birthdate) {
return null;
}

return ImportantDateHelper::getAge($birthdate);
}
}
Loading

0 comments on commit e2a1780

Please sign in to comment.