Skip to content

Commit

Permalink
Merge pull request #29 from raftx24/hotfix/fixesQuery
Browse files Browse the repository at this point in the history
fixes query
  • Loading branch information
aocneanu committed Dec 27, 2019
2 parents be9f798 + 54ea500 commit ea7c288
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app/Tables/Builders/DataImportTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LaravelEnso\DataImport\app\Tables\Builders;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use LaravelEnso\DataImport\app\Models\DataImport;
use LaravelEnso\DataImport\app\Models\RejectedImportSummary;
use LaravelEnso\Tables\app\Contracts\Table;
Expand All @@ -13,25 +14,32 @@ class DataImportTable implements Table

public function query(): Builder
{
return DataImport::selectRaw('
return DataImport::selectRaw("
data_imports.id, data_imports.type, data_imports.status, data_imports.status as computedStatus,
files.original_name as name, data_imports.successful, data_imports.failed, data_imports.created_at,
TIME(data_imports.created_at) as time, people.name as createdBy, rejected_imports.id as rejectedId,
sec_to_time(timestampdiff(second, data_imports.created_at, data_imports.updated_at)) as duration
')->join('files', function ($join) {
{$this->rawDuration()} as duration
")->join('files', function ($join) {
$join->on('files.attachable_id', 'data_imports.id')
->where('files.attachable_type', DataImport::class);
})->join('users', 'files.created_by', '=', 'users.id')
->join('people', 'users.person_id', '=', 'people.id')
->leftJoin('rejected_imports', 'data_imports.id', '=', 'rejected_imports.data_import_id')
->leftJoin('files as rejected_files', function ($join) {
$join->on('rejected_files.attachable_id', 'rejected_imports.id')
->where('rejected_files.attachable_type', RejectedImportSummary::class);
->where('rejected_files.attachable_type', RejectedImportSummary::class);
});
}

public function templatePath(): string
{
return static::TemplatePath;
}

private function rawDuration()
{
return DB::getDriverName() === 'sqlite'
? '0'
: 'sec_to_time(timestampdiff(second, data_imports.created_at, data_imports.updated_at))';
}
}

0 comments on commit ea7c288

Please sign in to comment.