Add created_at column in participants table
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
a1b0f6496c
commit
58feb20545
|
@ -25,7 +25,7 @@ class FormUpdateMetaAction
|
|||
'sorting.0' => 'required|string',
|
||||
'sorting.1' => 'required|string|in:asc,desc',
|
||||
'active_columns' => 'array',
|
||||
'active_columns.*' => ['string', Rule::in($form->getFields()->pluck('key')->toArray())]
|
||||
'active_columns.*' => ['string', Rule::in([...$form->getFields()->pluck('key')->toArray(), 'created_at'])]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ class Form extends Model implements HasMedia
|
|||
if (is_array(data_get($model->meta, 'active_columns'))) {
|
||||
$model->setAttribute('meta', [
|
||||
...$model->meta,
|
||||
'active_columns' => array_values(array_intersect($model->getFields()->pluck('key')->toArray(), $model->meta['active_columns'])),
|
||||
'active_columns' => array_values(array_intersect([...$model->getFields()->pluck('key')->toArray(), 'created_at'], $model->meta['active_columns'])),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -19,7 +19,11 @@ class ParticipantResource extends JsonResource
|
|||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return $this->getModel()->getFields()->present();
|
||||
return [
|
||||
...$this->getModel()->getFields()->present(),
|
||||
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
'created_at_display' => $this->created_at->format('d.m.Y'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,6 +43,11 @@ class ParticipantResource extends JsonResource
|
|||
'id' => $field->key,
|
||||
'display_attribute' => $field->getDisplayAttribute(),
|
||||
])
|
||||
->push([
|
||||
'name' => 'Registriert am',
|
||||
'id' => 'created_at',
|
||||
'display_attribute' => 'created_at_display'
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,4 +30,19 @@ class FormUpdateMetaActionTest extends FormTestCase
|
|||
$this->assertEquals(['textone', 'desc'], $form->meta['sorting']);
|
||||
$this->assertEquals(['textone'], $form->meta['active_columns']);
|
||||
}
|
||||
|
||||
public function testItCanSetCreatedAtMeta(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
|
||||
$this->patchJson(route('form.update-meta', ['form' => $form]), [
|
||||
'active_columns' => ['created_at'],
|
||||
'sorting' => ['created_at', 'desc'],
|
||||
])->assertOk();
|
||||
|
||||
$form = Form::latest()->first();
|
||||
$this->assertEquals(['created_at', 'desc'], $form->fresh()->meta['sorting']);
|
||||
$this->assertEquals(['created_at'], $form->fresh()->meta['active_columns']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Form\Fields\TextField;
|
|||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use App\Group;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ParticipantIndexActionTest extends FormTestCase
|
||||
|
@ -95,4 +96,27 @@ class ParticipantIndexActionTest extends FormTestCase
|
|||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertJsonPath('data.0.mitglieder_display', '393, 394');
|
||||
}
|
||||
|
||||
public function testItShowsRegisteredAtColumnAndAttribute(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2023-03-05 06:00:00'));
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->data(['vorname' => 'Max']))
|
||||
->sections([
|
||||
FormtemplateSectionRequest::new()->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
]),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertJsonPath('data.0.vorname', 'Max')
|
||||
->assertJsonPath('data.0.vorname_display', 'Max')
|
||||
->assertJsonPath('data.0.created_at', '2023-03-05 06:00:00')
|
||||
->assertJsonPath('data.0.created_at_display', '05.03.2023')
|
||||
->assertJsonPath('meta.columns.1.name', 'Registriert am')
|
||||
->assertJsonPath('meta.columns.1.id', 'created_at')
|
||||
->assertJsonPath('meta.columns.1.display_attribute', 'created_at_display');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue