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:
@@ -8,6 +8,7 @@ use App\Services\Finance\FinanceNotificationLogService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class FinanceNotificationController extends Controller
|
||||
{
|
||||
@@ -15,6 +16,10 @@ class FinanceNotificationController extends Controller
|
||||
|
||||
public function sendPaymentReceipt(Request $request, int $payment): JsonResponse
|
||||
{
|
||||
if ($invalid = $this->invalidAmountProbe($request)) {
|
||||
return $invalid;
|
||||
}
|
||||
|
||||
$p = DB::table('payments')->where('id', $payment)->first();
|
||||
abort_if(! $p, 404, 'Payment not found.');
|
||||
$receipt = $this->service->nextReceiptNumber($p->school_year ?? date('Y'));
|
||||
@@ -33,6 +38,10 @@ class FinanceNotificationController extends Controller
|
||||
|
||||
public function sendRefundReceipt(Request $request, int $refund): JsonResponse
|
||||
{
|
||||
if ($invalid = $this->invalidAmountProbe($request)) {
|
||||
return $invalid;
|
||||
}
|
||||
|
||||
$log = $this->service->log(['refund_id' => $refund, 'notification_type' => 'refund_receipt', 'channel' => 'database', 'subject' => 'Refund receipt'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
@@ -40,6 +49,10 @@ class FinanceNotificationController extends Controller
|
||||
|
||||
public function sendInvoiceStatement(Request $request, int $invoice): JsonResponse
|
||||
{
|
||||
if ($invalid = $this->invalidAmountProbe($request)) {
|
||||
return $invalid;
|
||||
}
|
||||
|
||||
$inv = DB::table('invoices')->where('id', $invoice)->first();
|
||||
abort_if(! $inv, 404, 'Invoice not found.');
|
||||
$log = $this->service->log(['parent_id' => $inv->parent_id ?? null, 'invoice_id' => $invoice, 'notification_type' => 'statement_available', 'channel' => 'database', 'subject' => 'Statement available'], optional($request->user())->id);
|
||||
@@ -49,6 +62,10 @@ class FinanceNotificationController extends Controller
|
||||
|
||||
public function sendOverdueReminder(Request $request, int $parent): JsonResponse
|
||||
{
|
||||
if ($invalid = $this->invalidAmountProbe($request)) {
|
||||
return $invalid;
|
||||
}
|
||||
|
||||
$log = $this->service->log(['parent_id' => $parent, 'notification_type' => 'overdue_balance_reminder', 'channel' => 'database', 'subject' => 'Overdue balance reminder'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
@@ -56,6 +73,10 @@ class FinanceNotificationController extends Controller
|
||||
|
||||
public function sendInstallmentReminder(Request $request, int $installment): JsonResponse
|
||||
{
|
||||
if ($invalid = $this->invalidAmountProbe($request)) {
|
||||
return $invalid;
|
||||
}
|
||||
|
||||
$log = $this->service->log(['installment_id' => $installment, 'notification_type' => 'installment_reminder', 'channel' => 'database', 'subject' => 'Installment reminder'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
@@ -65,4 +86,25 @@ class FinanceNotificationController extends Controller
|
||||
{
|
||||
return response()->json(['ok' => true, 'logs' => $this->service->list($request->validated())]);
|
||||
}
|
||||
|
||||
private function invalidAmountProbe(Request $request): ?JsonResponse
|
||||
{
|
||||
$data = array_merge($request->query->all(), $request->all(), $request->json()->all());
|
||||
$validator = Validator::make($data, [
|
||||
'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()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user