fix test errors
API CI/CD / Validate (composer + pint) (push) Successful in 2m47s
API CI/CD / Test (PHPUnit) (push) Failing after 3m8s
API CI/CD / Build frontend assets (push) Failing after 5m22s
API CI/CD / Security audit (push) Failing after 34s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 2m47s
API CI/CD / Test (PHPUnit) (push) Failing after 3m8s
API CI/CD / Build frontend assets (push) Failing after 5m22s
API CI/CD / Security audit (push) Failing after 34s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -112,6 +112,17 @@ class ReimbursementController extends BaseApiController
|
||||
$data = array_merge($request->query->all(), $request->all(), $request->json()->all());
|
||||
$validator = Validator::make($data, [
|
||||
'title' => ['nullable', 'string', 'max:255'],
|
||||
'confirm' => ['nullable', 'boolean'],
|
||||
'date' => ['nullable', 'date_format:Y-m-d'],
|
||||
'from' => ['nullable', 'date_format:Y-m-d'],
|
||||
'to' => ['nullable', 'date_format:Y-m-d'],
|
||||
'start_date' => ['nullable', 'date_format:Y-m-d'],
|
||||
'end_date' => ['nullable', 'date_format:Y-m-d'],
|
||||
'amount' => ['nullable', 'numeric', 'gt:0', 'max:999999999999.99'],
|
||||
'paid_amount' => ['nullable', 'numeric', 'gt:0', 'max:999999999999.99'],
|
||||
'total' => ['nullable', 'numeric', 'gt:0', 'max:999999999999.99'],
|
||||
'unit_cost' => ['nullable', 'numeric', 'gt:0', 'max:999999999999.99'],
|
||||
'fee' => ['nullable', 'numeric', 'gt:0', 'max:999999999999.99'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -122,6 +133,15 @@ class ReimbursementController extends BaseApiController
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
if (trim((string) ($payload['title'] ?? '')) === '' && ($payload['confirm'] ?? false) !== true) {
|
||||
return response()->json([
|
||||
'message' => 'Batch creation requires a title or explicit confirmation.',
|
||||
'errors' => [
|
||||
'title' => ['Provide a batch title or set confirm to true.'],
|
||||
],
|
||||
], 422);
|
||||
}
|
||||
|
||||
$schoolYear = $this->context->getSchoolYear();
|
||||
$semester = $this->context->getSemester();
|
||||
|
||||
@@ -130,6 +150,7 @@ class ReimbursementController extends BaseApiController
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'batch' => $batch,
|
||||
'data' => $batch,
|
||||
], 201);
|
||||
}
|
||||
|
||||
@@ -290,7 +311,7 @@ class ReimbursementController extends BaseApiController
|
||||
return response()->json(['ok' => true, 'message' => 'Email sent successfully.']);
|
||||
}
|
||||
|
||||
public function export(ReimbursementExportRequest $request): StreamedResponse
|
||||
public function export(ReimbursementExportRequest $request): JsonResponse|StreamedResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$type = $payload['type'] ?? 'processed';
|
||||
@@ -301,6 +322,14 @@ class ReimbursementController extends BaseApiController
|
||||
$csv = $this->exportService->buildProcessedCsv($payload);
|
||||
}
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'filename' => $csv['filename'],
|
||||
'rows' => $csv['rows'],
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->streamDownload(function () use ($csv) {
|
||||
$out = fopen('php://output', 'w');
|
||||
fprintf($out, chr(0xEF).chr(0xBB).chr(0xBF));
|
||||
|
||||
Reference in New Issue
Block a user