Skip to content

Commit

Permalink
fix: send emails only to verified users
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Dec 16, 2023
1 parent 540767e commit 6a385bf
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions app/Jobs/SendWeeklyMapsSummaryToUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ public function __construct()
public function handle()
{
// Get all the maps that have a user and markers
$maps = \App\Models\Map::where('user_id', '!=', null)->whereHas('markers', function ($q) {
// And where the markers were created in the last week
$q->withoutGlobalScopes()
->where('created_at', '>=', \Carbon\Carbon::now()->subWeek()->toDateTimeString())
->where('created_at', '<=', \Carbon\Carbon::now()->toDateTimeString())
// where the markers were not cretaed by the map owner or the markers dont have a user
->where(function ($q) {
$q->whereRaw('markers.user_id != maps.user_id')
->orWhereNull('markers.user_id');
});
})->get();
$maps = \App\Models\Map::where('user_id', '!=', null)
// The user must have their email validated
->whereHas('user', function ($q) {
$q->whereNotNull('email_verified_at');
})
->whereHas('markers', function ($q) {
// And where the markers were created in the last week
$q->withoutGlobalScopes()
->where('created_at', '>=', \Carbon\Carbon::now()->subWeek()->toDateTimeString())
->where('created_at', '<=', \Carbon\Carbon::now()->toDateTimeString())
// where the markers were not cretaed by the map owner or the markers dont have a user
->where(function ($q) {
$q->whereRaw('markers.user_id != maps.user_id')
->orWhereNull('markers.user_id');
});
})->get();

// Group the maps by user
$mapsByUser = $maps->groupBy('user_id');
Expand Down

0 comments on commit 6a385bf

Please sign in to comment.