Compare commits
1 Commits
88487f0d39
...
8f3e2e8aca
| Author | SHA1 | Date |
|---|---|---|
|
|
8f3e2e8aca |
|
|
@ -23,7 +23,7 @@ class GenerateAction
|
||||||
public function asController(GenerateRequest $request): BaseCompiler|JsonResponse
|
public function asController(GenerateRequest $request): BaseCompiler|JsonResponse
|
||||||
{
|
{
|
||||||
app(ContributionFactory::class)->validateType($request);
|
app(ContributionFactory::class)->validateType($request);
|
||||||
$request->validateContribution();
|
app(ContributionFactory::class)->validatePayload($request);
|
||||||
|
|
||||||
return $request->input('validate')
|
return $request->input('validate')
|
||||||
? response()->json([])
|
? response()->json([])
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,5 @@ interface HasContributionData {
|
||||||
|
|
||||||
public function country(): ?Country;
|
public function country(): ?Country;
|
||||||
|
|
||||||
public function validateContribution(): void;
|
public function payload(): array;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,12 @@ class ContributionFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateType(HasContributionData $request) {
|
public function validateType(HasContributionData $request) {
|
||||||
|
// @todo remove payload from hasContributionData and move the entire validation logic to the action
|
||||||
Validator::make(['type' => $request->type()], $this->typeRule())->validate();
|
Validator::make(['type' => $request->type()], $this->typeRule())->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validatePayload(HasContributionData $request) {
|
||||||
|
// @todo remove payload from hasContributionData and move the entire validation logic to the action
|
||||||
|
Validator::make($request->payload(), $this->rules($request->type()))->validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class MemberData extends Data
|
||||||
return collect($data)->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
|
return collect($data)->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
|
||||||
...$member,
|
...$member,
|
||||||
'birthday' => Carbon::parse($member['birthday'])->toAtomString(),
|
'birthday' => Carbon::parse($member['birthday'])->toAtomString(),
|
||||||
'gender' => $member['gender'] ? Gender::fromString($member['gender']) : null,
|
'gender' => Gender::fromString($member['gender']),
|
||||||
'isLeader' => $member['is_leader'],
|
'isLeader' => $member['is_leader'],
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Contribution\Data\MemberData;
|
use App\Contribution\Data\MemberData;
|
||||||
use App\Contribution\Traits\HasPdfBackground;
|
use App\Contribution\Traits\HasPdfBackground;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|
@ -117,15 +116,4 @@ class BdkjHesse extends ContributionDocument
|
||||||
'zipLocation' => 'required|string',
|
'zipLocation' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function requiredFormSpecialTypes(): array {
|
|
||||||
return [
|
|
||||||
SpecialType::FIRSTNAME,
|
|
||||||
SpecialType::LASTNAME,
|
|
||||||
SpecialType::BIRTHDAY,
|
|
||||||
SpecialType::ZIP,
|
|
||||||
SpecialType::LOCATION,
|
|
||||||
SpecialType::GENDER,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Contribution\Data\MemberData;
|
||||||
use App\Contribution\Traits\FormatsDates;
|
use App\Contribution\Traits\FormatsDates;
|
||||||
use App\Contribution\Traits\HasPdfBackground;
|
use App\Contribution\Traits\HasPdfBackground;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use App\Invoice\InvoiceSettings;
|
use App\Invoice\InvoiceSettings;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
@ -75,15 +74,4 @@ class CityFrankfurtMainDocument extends ContributionDocument
|
||||||
'zipLocation' => 'required|string',
|
'zipLocation' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function requiredFormSpecialTypes(): array {
|
|
||||||
return [
|
|
||||||
SpecialType::FIRSTNAME,
|
|
||||||
SpecialType::LASTNAME,
|
|
||||||
SpecialType::BIRTHDAY,
|
|
||||||
SpecialType::ZIP,
|
|
||||||
SpecialType::LOCATION,
|
|
||||||
SpecialType::ADDRESS,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Contribution\Traits\FormatsDates;
|
use App\Contribution\Traits\FormatsDates;
|
||||||
use App\Contribution\Traits\HasPdfBackground;
|
use App\Contribution\Traits\HasPdfBackground;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
@ -66,16 +65,4 @@ class CityRemscheidDocument extends ContributionDocument
|
||||||
'country' => 'required|integer|exists:countries,id',
|
'country' => 'required|integer|exists:countries,id',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function requiredFormSpecialTypes(): array {
|
|
||||||
return [
|
|
||||||
SpecialType::FIRSTNAME,
|
|
||||||
SpecialType::LASTNAME,
|
|
||||||
SpecialType::ADDRESS,
|
|
||||||
SpecialType::BIRTHDAY,
|
|
||||||
SpecialType::ZIP,
|
|
||||||
SpecialType::LOCATION,
|
|
||||||
SpecialType::LEADER
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ namespace App\Contribution\Documents;
|
||||||
|
|
||||||
use App\Contribution\Contracts\HasContributionData;
|
use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Contribution\Data\MemberData;
|
use App\Contribution\Data\MemberData;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use App\Invoice\InvoiceSettings;
|
use App\Invoice\InvoiceSettings;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
@ -95,15 +94,4 @@ class CitySolingenDocument extends ContributionDocument
|
||||||
'zipLocation' => 'required|string',
|
'zipLocation' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function requiredFormSpecialTypes(): array {
|
|
||||||
return [
|
|
||||||
SpecialType::FIRSTNAME,
|
|
||||||
SpecialType::LASTNAME,
|
|
||||||
SpecialType::BIRTHDAY,
|
|
||||||
SpecialType::ZIP,
|
|
||||||
SpecialType::LOCATION,
|
|
||||||
SpecialType::ADDRESS,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace App\Contribution\Documents;
|
namespace App\Contribution\Documents;
|
||||||
|
|
||||||
use App\Contribution\Contracts\HasContributionData;
|
use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use Zoomyboy\Tex\Document;
|
use Zoomyboy\Tex\Document;
|
||||||
use Zoomyboy\Tex\Template;
|
use Zoomyboy\Tex\Template;
|
||||||
|
|
||||||
|
|
@ -15,11 +14,6 @@ abstract class ContributionDocument extends Document
|
||||||
|
|
||||||
abstract public static function fromPayload(HasContributionData $request): self;
|
abstract public static function fromPayload(HasContributionData $request): self;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<int, SpecialType>
|
|
||||||
*/
|
|
||||||
abstract public static function requiredFormSpecialTypes(): array;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Contribution\Data\MemberData;
|
||||||
use App\Contribution\Traits\FormatsDates;
|
use App\Contribution\Traits\FormatsDates;
|
||||||
use App\Contribution\Traits\HasPdfBackground;
|
use App\Contribution\Traits\HasPdfBackground;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
|
@ -66,15 +65,4 @@ class RdpNrwDocument extends ContributionDocument
|
||||||
'zipLocation' => 'required|string',
|
'zipLocation' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function requiredFormSpecialTypes(): array {
|
|
||||||
return [
|
|
||||||
SpecialType::FIRSTNAME,
|
|
||||||
SpecialType::LASTNAME,
|
|
||||||
SpecialType::BIRTHDAY,
|
|
||||||
SpecialType::ZIP,
|
|
||||||
SpecialType::LOCATION,
|
|
||||||
SpecialType::GENDER,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Contribution\Data\MemberData;
|
||||||
use App\Contribution\Traits\FormatsDates;
|
use App\Contribution\Traits\FormatsDates;
|
||||||
use App\Contribution\Traits\HasPdfBackground;
|
use App\Contribution\Traits\HasPdfBackground;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
|
@ -61,17 +60,4 @@ class WuppertalDocument extends ContributionDocument
|
||||||
'zipLocation' => 'required|string',
|
'zipLocation' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function requiredFormSpecialTypes(): array {
|
|
||||||
return [
|
|
||||||
SpecialType::FIRSTNAME,
|
|
||||||
SpecialType::LASTNAME,
|
|
||||||
SpecialType::ADDRESS,
|
|
||||||
SpecialType::BIRTHDAY,
|
|
||||||
SpecialType::ZIP,
|
|
||||||
SpecialType::LOCATION,
|
|
||||||
SpecialType::GENDER,
|
|
||||||
SpecialType::LEADER,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,17 @@
|
||||||
|
|
||||||
namespace App\Contribution\Requests;
|
namespace App\Contribution\Requests;
|
||||||
|
|
||||||
|
use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Contribution\Data\MemberData;
|
use App\Contribution\Data\MemberData;
|
||||||
|
use App\Contribution\Documents\ContributionDocument;
|
||||||
|
use App\Country;
|
||||||
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
class GenerateApiRequest extends GenerateRequest {
|
class GenerateApiRequest extends ActionRequest implements HasContributionData {
|
||||||
/**
|
/**
|
||||||
* @return array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
|
|
@ -14,11 +21,47 @@ class GenerateApiRequest extends GenerateRequest {
|
||||||
return $this->input();
|
return $this->input();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateContribution(): void {
|
/**
|
||||||
|
* @return string|array<array-key, mixed>
|
||||||
|
*/
|
||||||
|
public function value(string $key): string|array
|
||||||
|
{
|
||||||
|
if (!Arr::has($this->payload(), $key)) {
|
||||||
|
throw new RuntimeException('Wert für '.$key.' nicht gefunden.');
|
||||||
|
}
|
||||||
|
return data_get($this->payload(), $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return class-string<ContributionDocument>
|
||||||
|
*/
|
||||||
|
public function type(): string
|
||||||
|
{
|
||||||
|
return $this->value('type');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dateFrom(): Carbon {
|
||||||
|
return Carbon::parse($this->value('dateFrom'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dateUntil(): Carbon {
|
||||||
|
return Carbon::parse($this->value('dateUntil'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function zipLocation(): string {
|
||||||
|
return $this->value('zipLocation');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function eventName(): string {
|
||||||
|
return $this->value('eventName');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function members(): Collection {
|
public function members(): Collection {
|
||||||
return MemberData::fromApi($this->value('members'));
|
return MemberData::fromApi($this->value('member_data'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function country(): ?Country {
|
||||||
|
return Country::where('id', $this->value('country'))->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@
|
||||||
namespace App\Contribution\Requests;
|
namespace App\Contribution\Requests;
|
||||||
|
|
||||||
use App\Contribution\Contracts\HasContributionData;
|
use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Contribution\ContributionFactory;
|
|
||||||
use App\Contribution\Data\MemberData;
|
use App\Contribution\Data\MemberData;
|
||||||
use App\Contribution\Documents\ContributionDocument;
|
use App\Contribution\Documents\ContributionDocument;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use Lorisleiva\Actions\ActionRequest;
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
|
|
||||||
class GenerateRequest extends ActionRequest implements HasContributionData {
|
class GenerateRequest extends ActionRequest implements HasContributionData {
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,10 +19,6 @@ class GenerateRequest extends ActionRequest implements HasContributionData {
|
||||||
return json_decode(rawurldecode(base64_decode($this->input('payload', ''))), true);
|
return json_decode(rawurldecode(base64_decode($this->input('payload', ''))), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateContribution(): void {
|
|
||||||
Validator::make($this->payload(), app(ContributionFactory::class)->rules($this->type()))->validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|array<array-key, mixed>
|
* @return string|array<array-key, mixed>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Contribution\ContributionFactory;
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Rules\JsonBase64Rule;
|
use App\Rules\JsonBase64Rule;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Lorisleiva\Actions\ActionRequest;
|
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
use Zoomyboy\Tex\BaseCompiler;
|
use Zoomyboy\Tex\BaseCompiler;
|
||||||
use Zoomyboy\Tex\Tex;
|
use Zoomyboy\Tex\Tex;
|
||||||
|
|
@ -21,14 +20,15 @@ class GenerateContributionAction
|
||||||
return Tex::compile($request->type()::fromPayload($request));
|
return Tex::compile($request->type()::fromPayload($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asController(ActionRequest $request, Form $form): BaseCompiler|JsonResponse
|
public function asController(Form $form): BaseCompiler|JsonResponse
|
||||||
{
|
{
|
||||||
app(ContributionFactory::class)->validateType($form);
|
app(ContributionFactory::class)->validateType($form);
|
||||||
$form->validateContribution();
|
app(ContributionFactory::class)->validatePayload($form);
|
||||||
|
dd('I');
|
||||||
|
|
||||||
return $request->input('validate')
|
return $request->input('validate')
|
||||||
? response()->json([])
|
? response()->json([])
|
||||||
: $this->handle($form);
|
: $this->handle($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -114,12 +114,7 @@ class FieldCollection extends Collection
|
||||||
return $this->map(fn ($field) => $field->presentRaw())->toArray();
|
return $this->map(fn ($field) => $field->presentRaw())->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasSpecialType(SpecialType $specialType): bool
|
private function findBySpecialType(SpecialType $specialType): ?Field
|
||||||
{
|
|
||||||
return $this->findBySpecialType($specialType) !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findBySpecialType(SpecialType $specialType): ?Field
|
|
||||||
{
|
{
|
||||||
return $this->first(fn ($field) => $field->specialType === $specialType);
|
return $this->first(fn ($field) => $field->specialType === $specialType);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ enum SpecialType: string
|
||||||
case FIRSTNAME = 'Vorname';
|
case FIRSTNAME = 'Vorname';
|
||||||
case LASTNAME = 'Nachname';
|
case LASTNAME = 'Nachname';
|
||||||
case EMAIL = 'E-Mail-Adresse';
|
case EMAIL = 'E-Mail-Adresse';
|
||||||
case BIRTHDAY = 'Geburtsdatum';
|
|
||||||
case ZIP = 'PLZ';
|
|
||||||
case LOCATION = 'Ort';
|
|
||||||
case ADDRESS = 'Adresse';
|
|
||||||
case GENDER = 'Geschlecht';
|
|
||||||
case LEADER = 'LeiterIn';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, array{name: string, id: string}>
|
* @return array<int, array{name: string, id: string}>
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,15 @@
|
||||||
namespace App\Form\Models;
|
namespace App\Form\Models;
|
||||||
|
|
||||||
use App\Contribution\Contracts\HasContributionData;
|
use App\Contribution\Contracts\HasContributionData;
|
||||||
use App\Contribution\Data\MemberData;
|
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||||
use App\Form\Data\ExportData;
|
use App\Form\Data\ExportData;
|
||||||
use App\Form\Data\FieldCollection;
|
use App\Form\Data\FieldCollection;
|
||||||
use App\Form\Data\FormConfigData;
|
use App\Form\Data\FormConfigData;
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use App\Lib\Editor\Condition;
|
use App\Lib\Editor\Condition;
|
||||||
use App\Lib\Editor\EditorData;
|
use App\Lib\Editor\EditorData;
|
||||||
use App\Lib\Sorting;
|
use App\Lib\Sorting;
|
||||||
|
use App\Member\Data\MemberData;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Cviebrock\EloquentSluggable\Sluggable;
|
use Cviebrock\EloquentSluggable\Sluggable;
|
||||||
use Database\Factories\Form\Models\FormFactory;
|
use Database\Factories\Form\Models\FormFactory;
|
||||||
|
|
@ -20,7 +19,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
use Laravel\Scout\Searchable;
|
use Laravel\Scout\Searchable;
|
||||||
use Spatie\Image\Enums\Fit;
|
use Spatie\Image\Enums\Fit;
|
||||||
use Spatie\MediaLibrary\HasMedia;
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
|
|
@ -226,73 +224,27 @@ class Form extends Model implements HasMedia, HasContributionData
|
||||||
return request()->input('type');
|
return request()->input('type');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dateFrom(): Carbon
|
public function dateFrom(): Carbon {
|
||||||
{
|
|
||||||
return now();
|
return now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dateUntil(): Carbon
|
public function dateUntil(): Carbon {
|
||||||
{
|
|
||||||
return now();
|
return now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function zipLocation(): string
|
public function zipLocation(): string {
|
||||||
{
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function eventName(): string
|
public function eventName(): string {
|
||||||
{
|
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function members(): Collection
|
public function members(): Collection {
|
||||||
{
|
return MemberData::fromApi([]);
|
||||||
$members = [];
|
|
||||||
$fields = [
|
|
||||||
[SpecialType::FIRSTNAME, 'firstname'],
|
|
||||||
[SpecialType::LASTNAME, 'lastname'],
|
|
||||||
[SpecialType::BIRTHDAY, 'birthday'],
|
|
||||||
[SpecialType::ADDRESS, 'address'],
|
|
||||||
[SpecialType::ZIP, 'zip'],
|
|
||||||
[SpecialType::LOCATION, 'location']
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($this->participants as $participant) {
|
|
||||||
$member = [];
|
|
||||||
foreach ($fields as [$type, $name]) {
|
|
||||||
$f = $this->getFields()->findBySpecialType($type);
|
|
||||||
$member[$name] = $participant->getFields()->find($f)->value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$members[] = [
|
public function country(): ?Country {
|
||||||
'is_leader' => false,
|
|
||||||
'gender' => null,
|
|
||||||
...$member,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return MemberData::fromApi($members);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function country(): ?Country
|
|
||||||
{
|
|
||||||
return Country::first();
|
return Country::first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateContribution(): void
|
|
||||||
{
|
|
||||||
$messages = [];
|
|
||||||
foreach ($this->type()::requiredFormSpecialTypes() as $type) {
|
|
||||||
if (!$this->getFields()->hasSpecialType($type)) {
|
|
||||||
$messages[$type->name] = 'Kein Feld für ' . $type->value . ' vorhanden.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->participants->count() === 0) {
|
|
||||||
$messages['participants'] = 'Veranstaltung besitzt noch keine Teilnehmer*innen.';
|
|
||||||
}
|
|
||||||
|
|
||||||
throw_unless(empty($messages), ValidationException::withMessages($messages));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,3 @@ dataset('contribution-assertions', fn () => [
|
||||||
[BdkjHesse::class, ["Max", "Muster", "Jane"]],
|
[BdkjHesse::class, ["Max", "Muster", "Jane"]],
|
||||||
[WuppertalDocument::class, ["Max", "Muster", "Jane", "42777 SG", "15.06.1991", "16.06.1991"]],
|
[WuppertalDocument::class, ["Max", "Muster", "Jane", "42777 SG", "15.06.1991", "16.06.1991"]],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dataset('contribution-documents', fn () => [
|
|
||||||
CitySolingenDocument::class,
|
|
||||||
RdpNrwDocument::class,
|
|
||||||
CityRemscheidDocument::class,
|
|
||||||
CityFrankfurtMainDocument::class,
|
|
||||||
BdkjHesse::class,
|
|
||||||
WuppertalDocument::class,
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ it('testItCompilesContributionDocumentsViaApi', function (string $type, array $b
|
||||||
'eventName' => 'Super tolles Lager',
|
'eventName' => 'Super tolles Lager',
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'zipLocation' => '42777 SG',
|
'zipLocation' => '42777 SG',
|
||||||
'members' => [
|
'member_data' => [
|
||||||
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']),
|
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']),
|
||||||
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']),
|
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']),
|
||||||
],
|
],
|
||||||
|
|
@ -100,28 +100,6 @@ it('testItCompilesContributionDocumentsViaApi', function (string $type, array $b
|
||||||
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
||||||
})->with('contribution-assertions');
|
})->with('contribution-assertions');
|
||||||
|
|
||||||
it('compiles when gender is null', function () {
|
|
||||||
$this->withoutExceptionHandling();
|
|
||||||
Tex::spy();
|
|
||||||
Passport::actingAsClient(Client::factory()->create(), ['contribution-generate']);
|
|
||||||
|
|
||||||
$response = $this->postJson('/api/contribution-generate', [
|
|
||||||
'country' => Country::factory()->create()->id,
|
|
||||||
'dateFrom' => '1991-06-15',
|
|
||||||
'dateUntil' => '1991-06-16',
|
|
||||||
'eventName' => 'Super tolles Lager',
|
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'zipLocation' => '42777 SG',
|
|
||||||
'members' => [
|
|
||||||
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster', 'gender' => null]),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionDoesntHaveErrors();
|
|
||||||
$response->assertOk();
|
|
||||||
Tex::assertCompiled(CitySolingenDocument::class, fn () => true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('testInputShouldBeBase64EncodedJson', function (string $payload) {
|
it('testInputShouldBeBase64EncodedJson', function (string $payload) {
|
||||||
$this->login()->loginNami();
|
$this->login()->loginNami();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,114 +3,114 @@
|
||||||
namespace Tests\Feature\Form;
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
use App\Contribution\Documents\CitySolingenDocument;
|
use App\Contribution\Documents\CitySolingenDocument;
|
||||||
use App\Contribution\Documents\RdpNrwDocument;
|
|
||||||
use App\Form\Enums\SpecialType;
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Tests\Lib\CreatesFormFields;
|
|
||||||
use Zoomyboy\Tex\Tex;
|
use Zoomyboy\Tex\Tex;
|
||||||
|
|
||||||
uses(DatabaseTransactions::class);
|
uses(DatabaseTransactions::class);
|
||||||
uses(CreatesFormFields::class);
|
|
||||||
|
|
||||||
/**
|
it('doesnt create document when no firstname field given', function () {
|
||||||
* @param array<int, FormtemplateFieldRequest> $fields
|
|
||||||
*/
|
|
||||||
it('doesnt create document when no special fields given', function (array $fields, string $field, string $message, string $type) {
|
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$form = Form::factory()
|
|
||||||
->fields($fields)
|
|
||||||
->has(Participant::factory())
|
|
||||||
->create();
|
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
|
||||||
'type' => $type,
|
|
||||||
'form' => $form,
|
|
||||||
'validate' => '1',
|
|
||||||
]))->assertJsonValidationErrors([$field => $message]);
|
|
||||||
})
|
|
||||||
->with([
|
|
||||||
[fn () => [], 'FIRSTNAME', 'Kein Feld für Vorname vorhanden.'],
|
|
||||||
[fn () => [test()->textField('f')->specialType(SpecialType::FIRSTNAME)], 'LASTNAME', 'Kein Feld für Nachname vorhanden.'],
|
|
||||||
[fn () => [test()->textField('f')->specialType(SpecialType::FIRSTNAME), test()->textField('l')->specialType(SpecialType::LASTNAME)], 'BIRTHDAY', 'Kein Feld für Geburtsdatum vorhanden.'],
|
|
||||||
[fn () => [test()->textField('f')->specialType(SpecialType::FIRSTNAME), test()->textField('l')->specialType(SpecialType::LASTNAME), test()->dateField('b')->specialType(SpecialType::BIRTHDAY)], 'ZIP', 'Kein Feld für PLZ vorhanden.'],
|
|
||||||
[fn () => [test()->textField('f')->specialType(SpecialType::FIRSTNAME), test()->textField('l')->specialType(SpecialType::LASTNAME), test()->dateField('b')->specialType(SpecialType::BIRTHDAY), test()->dateField('p')->specialType(SpecialType::ZIP)], 'LOCATION', 'Kein Feld für Ort vorhanden.'],
|
|
||||||
])->with('contribution-documents');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, FormtemplateFieldRequest> $fields
|
|
||||||
*/
|
|
||||||
it('validates special types of each document', function (string $type, array $fields, string $field, string $message) {
|
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$form = Form::factory()->fields([
|
|
||||||
test()->textField('f')->specialType(SpecialType::FIRSTNAME),
|
|
||||||
test()->textField('l')->specialType(SpecialType::LASTNAME),
|
|
||||||
test()->dateField('b')->specialType(SpecialType::BIRTHDAY),
|
|
||||||
test()->dateField('p')->specialType(SpecialType::ZIP),
|
|
||||||
test()->dateField('l')->specialType(SpecialType::LOCATION),
|
|
||||||
...$fields,
|
|
||||||
])
|
|
||||||
->has(Participant::factory())
|
|
||||||
->create();
|
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
|
||||||
'type' => $type,
|
|
||||||
'form' => $form,
|
|
||||||
'validate' => '1',
|
|
||||||
]))->assertJsonValidationErrors([$field => $message]);
|
|
||||||
})
|
|
||||||
->with([
|
|
||||||
[CitySolingenDocument::class, [], 'ADDRESS', 'Kein Feld für Adresse vorhanden.'],
|
|
||||||
[RdpNrwDocument::class, [], 'GENDER', 'Kein Feld für Geschlecht vorhanden.'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
it('throws error when not validating but fields are not present', function () {
|
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$form = Form::factory()->fields([])
|
|
||||||
->has(Participant::factory())
|
|
||||||
->create();
|
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
]))->assertStatus(422);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('throws error when form doesnt have participants', function () {
|
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$form = Form::factory()->fields([])->create();
|
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
'validate' => '1',
|
|
||||||
]))->assertJsonValidationErrors(['participants' => 'Veranstaltung besitzt noch keine Teilnehmer*innen.']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('creates document when fields are present', function () {
|
|
||||||
Tex::spy();
|
Tex::spy();
|
||||||
$this->login()->loginNami();
|
$this->login()->loginNami();
|
||||||
|
|
||||||
$form = Form::factory()->fields([
|
$form = Form::factory()
|
||||||
test()->textField('fn')->specialType(SpecialType::FIRSTNAME),
|
->fields([])
|
||||||
test()->textField('ln')->specialType(SpecialType::LASTNAME),
|
->has(Participant::factory())
|
||||||
test()->dateField('bd')->specialType(SpecialType::BIRTHDAY),
|
|
||||||
test()->dateField('zip')->specialType(SpecialType::ZIP),
|
|
||||||
test()->dateField('loc')->specialType(SpecialType::LOCATION),
|
|
||||||
test()->dateField('add')->specialType(SpecialType::ADDRESS),
|
|
||||||
])
|
|
||||||
->has(Participant::factory()->data(['fn' => 'Baum', 'ln' => 'Muster', 'bd' => '1991-05-06', 'zip' => '33333', 'loc' => 'Musterstadt', 'add' => 'Laastr 4']))
|
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
$this->json('GET', route('form.contribution', [
|
||||||
'type' => CitySolingenDocument::class,
|
'type' => CitySolingenDocument::class,
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
]))->assertOk();
|
'validate' => '1',
|
||||||
Tex::assertCompiled(CitySolingenDocument::class, fn ($document) => $document->hasAllContent(['Baum', 'Muster', '1991', 'Musterstadt', 'Laastr 4', '33333']));
|
]))->assertJsonValidationErrors(['firstname' => 'Kein Feld für Vorname vorhanden']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// it('compiles documents via base64 param', function (string $type, array $bodyChecks) {
|
||||||
|
// $this->withoutExceptionHandling();
|
||||||
|
// Tex::spy();
|
||||||
|
// $this->login()->loginNami();
|
||||||
|
// $member1 = Member::factory()->defaults()->male()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']);
|
||||||
|
// $member2 = Member::factory()->defaults()->female()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']);
|
||||||
|
//
|
||||||
|
// $response = $this->call('GET', '/contribution-generate', [
|
||||||
|
// 'payload' => ContributionRequestFactory::new()->type($type)->state([
|
||||||
|
// 'dateFrom' => '1991-06-15',
|
||||||
|
// 'dateUntil' => '1991-06-16',
|
||||||
|
// 'eventName' => 'Super tolles Lager',
|
||||||
|
// 'members' => [$member1->id, $member2->id],
|
||||||
|
// 'type' => $type,
|
||||||
|
// 'zipLocation' => '42777 SG',
|
||||||
|
// ])->toBase64(),
|
||||||
|
// ]);
|
||||||
|
//
|
||||||
|
// $response->assertSessionDoesntHaveErrors();
|
||||||
|
// $response->assertOk();
|
||||||
|
// Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
||||||
|
// })->with('contribution-assertions');
|
||||||
|
//
|
||||||
|
// it('testItCompilesGroupNameInSolingenDocument', function () {
|
||||||
|
// $this->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
// Tex::spy();
|
||||||
|
// InvoiceSettings::fake(['from_long' => 'Stamm BiPi']);
|
||||||
|
//
|
||||||
|
// $this->call('GET', '/contribution-generate', [
|
||||||
|
// 'payload' => ContributionRequestFactory::new()->type(CitySolingenDocument::class)->toBase64(),
|
||||||
|
// ]);
|
||||||
|
//
|
||||||
|
// Tex::assertCompiled(CitySolingenDocument::class, fn ($document) => $document->hasAllContent(['Stamm BiPi']));
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// it('testItCompilesContributionDocumentsViaApi', function (string $type, array $bodyChecks) {
|
||||||
|
// $this->withoutExceptionHandling();
|
||||||
|
// Tex::spy();
|
||||||
|
// Gender::factory()->female()->create();
|
||||||
|
// Gender::factory()->male()->create();
|
||||||
|
// Passport::actingAsClient(Client::factory()->create(), ['contribution-generate']);
|
||||||
|
//
|
||||||
|
// $response = $this->postJson('/api/contribution-generate', [
|
||||||
|
// 'country' => Country::factory()->create()->id,
|
||||||
|
// 'dateFrom' => '1991-06-15',
|
||||||
|
// 'dateUntil' => '1991-06-16',
|
||||||
|
// 'eventName' => 'Super tolles Lager',
|
||||||
|
// 'type' => $type,
|
||||||
|
// 'zipLocation' => '42777 SG',
|
||||||
|
// 'member_data' => [
|
||||||
|
// ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']),
|
||||||
|
// ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']),
|
||||||
|
// ],
|
||||||
|
// ]);
|
||||||
|
//
|
||||||
|
// $response->assertSessionDoesntHaveErrors();
|
||||||
|
// $response->assertOk();
|
||||||
|
// Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
||||||
|
// })->with('contribution-assertions');
|
||||||
|
//
|
||||||
|
// it('testInputShouldBeBase64EncodedJson', function (string $payload) {
|
||||||
|
// $this->login()->loginNami();
|
||||||
|
//
|
||||||
|
// $this->call('GET', '/contribution-generate', ['payload' => $payload])->assertSessionHasErrors('payload');
|
||||||
|
// })->with([
|
||||||
|
// [""],
|
||||||
|
// ["aaaa"],
|
||||||
|
// ["YWFhCg=="],
|
||||||
|
// ]);
|
||||||
|
//
|
||||||
|
// it('testItValidatesInput', function (array $input, string $documentClass, string $errorField) {
|
||||||
|
// $this->login()->loginNami();
|
||||||
|
// Country::factory()->create();
|
||||||
|
// Member::factory()->defaults()->create();
|
||||||
|
//
|
||||||
|
// $this->postJson('/contribution-validate', ContributionRequestFactory::new()->type($documentClass)->state($input)->create())
|
||||||
|
// ->assertJsonValidationErrors($errorField);
|
||||||
|
// })->with('contribution-validation');
|
||||||
|
//
|
||||||
|
// it('testItValidatesInputBeforeGeneration', function (array $input, string $documentClass, string $errorField) {
|
||||||
|
// $this->login()->loginNami();
|
||||||
|
// Country::factory()->create();
|
||||||
|
// Member::factory()->defaults()->create();
|
||||||
|
//
|
||||||
|
// $this->call('GET', '/contribution-generate', [
|
||||||
|
// 'payload' => ContributionRequestFactory::new()->type($documentClass)->state($input)->toBase64(),
|
||||||
|
// ])->assertSessionHasErrors($errorField);
|
||||||
|
// })->with('contribution-validation');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue