diff --git a/src/controllers/transferController.ts b/src/controllers/transferController.ts index 05b0ca3..efaaef2 100644 --- a/src/controllers/transferController.ts +++ b/src/controllers/transferController.ts @@ -441,12 +441,9 @@ export async function MidsuitPaymentV2(req: Request, res: Response) { export async function paymentStatus(req: Request, res: Response) { try { - const { c_invoice_id, startdate, enddate } = req.query as any; - if (!c_invoice_id) { - return res.status(400).json({ error: "c_invoice_id is required" }); - } + const { c_invoice_id, startdate, enddate } = req.body as any; - const where: any = { c_invoice_id: Number(c_invoice_id) }; + const where: any = {}; if (startdate || enddate) { where.created_at = {} as any; if (startdate) { @@ -462,17 +459,38 @@ export async function paymentStatus(req: Request, res: Response) { where.created_at.lte = e; } } + if (c_invoice_id) { + where.c_invoice_id = Number(c_invoice_id); + } + console.log({ + ...where, + and: { + NOT: { + c_invoice_id: null, + }, + }, + }); const rows = await db.transactions_lines.findMany({ where: { ...where, - not: { - c_invoice_id: null, - }, + AND: [ + { + NOT: { + c_invoice_id: null, + }, + }, + { + transactions: { + status: "COMPLETED", + }, + }, + ], }, include: { transactions: true }, orderBy: { created_at: "desc" }, }); + return res.json({ count: rows.length, data: rows }); const result = rows.map((r: any) => ({ id: r.id, diff --git a/src/routes/index.ts b/src/routes/index.ts index 1c6306b..295e2e7 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -76,7 +76,7 @@ export const setRoutes = () => { transferController.MidsuitPayment(req, res) ); // Payment status lookup by c_invoice_id (optionally limit by startdate/enddate) - router.get("/api/va/status", authMiddleware, async (req, res) => + router.post("/api/va/status", authMiddleware, async (req, res) => transferController.paymentStatus(req, res) ); // Signature generation for testing (uses PRIVATE_KEY_PATH file)