ui and minor changes for payment page
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
import express from 'express';
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import routes from './routes';
|
||||
import { errorHandler } from './middlewares/error.middleware';
|
||||
import { apiLogger } from './middlewares/logger.middleware';
|
||||
import authRoutes from './routes/auth'
|
||||
import { authenticateJWT } from './middlewares/auth.middleware';
|
||||
import dotenv from 'dotenv';
|
||||
import routes from "./routes";
|
||||
import { errorHandler } from "./middlewares/error.middleware";
|
||||
import { apiLogger } from "./middlewares/logger.middleware";
|
||||
import authRoutes from "./routes/auth";
|
||||
import { authenticateJWT } from "./middlewares/auth.middleware";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
const FRONTEND_URL = process.env.FRONTEND_URL;
|
||||
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true })); // For form data
|
||||
app.use(apiLogger);
|
||||
|
||||
app.use(cors({
|
||||
origin: FRONTEND_URL,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
credentials: true,
|
||||
}));
|
||||
app.use(
|
||||
cors({
|
||||
origin: FRONTEND_URL,
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
credentials: true,
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
app.use('/api/auth', authRoutes);
|
||||
app.use('/api', authenticateJWT, routes);
|
||||
app.use("/api/auth", authRoutes);
|
||||
app.use("/api", authenticateJWT, routes);
|
||||
|
||||
app.use(errorHandler);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { forwardToSeleniumClaimAgent } from "../services/seleniumClaimClient";
|
||||
import path from "path";
|
||||
import axios from "axios";
|
||||
import { Prisma } from "@repo/db/generated/prisma";
|
||||
import { Decimal } from "@prisma/client/runtime/library";
|
||||
import { Decimal } from "decimal.js";
|
||||
import {
|
||||
ExtendedClaimSchema,
|
||||
InputServiceLine,
|
||||
@@ -255,8 +255,9 @@ router.post("/", async (req: Request, res: Response): Promise<any> => {
|
||||
(line: InputServiceLine) => ({
|
||||
...line,
|
||||
totalBilled: Number(line.totalBilled),
|
||||
totalAdjusted: Number(line.totalAdjusted),
|
||||
totalPaid: Number(line.totalPaid),
|
||||
totalAdjusted: 0,
|
||||
totalPaid: 0,
|
||||
totalDue: Number(line.totalBilled),
|
||||
})
|
||||
);
|
||||
req.body.serviceLines = { create: req.body.serviceLines };
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "@repo/db/types";
|
||||
import Decimal from "decimal.js";
|
||||
import { prisma } from "@repo/db/client";
|
||||
import { PaymentStatusSchema } from "@repo/db/types";
|
||||
|
||||
const paymentFilterSchema = z.object({
|
||||
from: z.string().datetime(),
|
||||
@@ -74,8 +75,8 @@ router.get(
|
||||
const parsedClaimId = parseIntOrError(req.params.claimId, "Claim ID");
|
||||
|
||||
const payments = await storage.getPaymentsByClaimId(
|
||||
userId,
|
||||
parsedClaimId
|
||||
parsedClaimId,
|
||||
userId
|
||||
);
|
||||
if (!payments)
|
||||
return res.status(404).json({ message: "No payments found for claim" });
|
||||
@@ -102,8 +103,8 @@ router.get(
|
||||
);
|
||||
|
||||
const payments = await storage.getPaymentsByPatientId(
|
||||
userId,
|
||||
parsedPatientId
|
||||
parsedPatientId,
|
||||
userId
|
||||
);
|
||||
|
||||
if (!payments)
|
||||
@@ -152,7 +153,7 @@ router.get("/:id", async (req: Request, res: Response): Promise<any> => {
|
||||
|
||||
const id = parseIntOrError(req.params.id, "Payment ID");
|
||||
|
||||
const payment = await storage.getPaymentById(userId, id);
|
||||
const payment = await storage.getPaymentById(id, userId);
|
||||
if (!payment) return res.status(404).json({ message: "Payment not found" });
|
||||
|
||||
res.status(200).json(payment);
|
||||
@@ -309,6 +310,34 @@ router.put("/:id", async (req: Request, res: Response): Promise<any> => {
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/payments/:id/status
|
||||
router.patch(
|
||||
"/:id/status",
|
||||
async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) {
|
||||
return res.status(401).json({ message: "Unauthorized" });
|
||||
}
|
||||
|
||||
const paymentId = parseIntOrError(req.params.id, "Payment ID");
|
||||
|
||||
const status = PaymentStatusSchema.parse(req.body.data.status);
|
||||
|
||||
const updatedPayment = await prisma.payment.update({
|
||||
where: { id: paymentId },
|
||||
data: { status, updatedById: userId },
|
||||
});
|
||||
|
||||
res.json(updatedPayment);
|
||||
} catch (err: unknown) {
|
||||
const message =
|
||||
err instanceof Error ? err.message : "Failed to update payment status";
|
||||
res.status(500).json({ message });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// DELETE /api/payments/:id
|
||||
router.delete("/:id", async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user