feat : add appointment apis
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Appointment" (
|
||||||
|
"id" SERIAL NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"mobileNumber" TEXT NOT NULL,
|
||||||
|
"email" TEXT,
|
||||||
|
"message" TEXT,
|
||||||
|
"date" TIMESTAMP(3) NOT NULL,
|
||||||
|
"doctorId" INTEGER NOT NULL,
|
||||||
|
"departmentId" INTEGER NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "Appointment_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_doctorId_fkey" FOREIGN KEY ("doctorId") REFERENCES "Doctor"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_departmentId_fkey" FOREIGN KEY ("departmentId") REFERENCES "Department"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Appointment" DROP CONSTRAINT "Appointment_departmentId_fkey";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Appointment" DROP CONSTRAINT "Appointment_doctorId_fkey";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Appointment" ALTER COLUMN "doctorId" SET DATA TYPE TEXT,
|
||||||
|
ALTER COLUMN "departmentId" SET DATA TYPE TEXT;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_doctorId_fkey" FOREIGN KEY ("doctorId") REFERENCES "Doctor"("doctorId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_departmentId_fkey" FOREIGN KEY ("departmentId") REFERENCES "Department"("departmentId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
@@ -9,144 +8,142 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
username String @unique
|
username String @unique
|
||||||
password String
|
password String
|
||||||
role String? @default("admin")
|
role String? @default("admin")
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model Doctor {
|
model Doctor {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
doctorId String @unique
|
doctorId String @unique
|
||||||
name String
|
name String
|
||||||
designation String?
|
designation String?
|
||||||
workingStatus String?
|
workingStatus String?
|
||||||
qualification String?
|
qualification String?
|
||||||
|
|
||||||
departments DoctorDepartment[]
|
departments DoctorDepartment[]
|
||||||
appointments Appointment[]
|
appointments Appointment[]
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
model Department {
|
model Department {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
departmentId String @unique
|
departmentId String @unique
|
||||||
name String
|
name String
|
||||||
|
|
||||||
para1 String?
|
para1 String?
|
||||||
para2 String?
|
para2 String?
|
||||||
para3 String?
|
para3 String?
|
||||||
facilities String?
|
facilities String?
|
||||||
services String?
|
services String?
|
||||||
|
|
||||||
doctors DoctorDepartment[]
|
doctors DoctorDepartment[]
|
||||||
appointments Appointment[]
|
appointments Appointment[]
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model DoctorDepartment {
|
model DoctorDepartment {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
|
|
||||||
doctorId Int
|
doctorId Int
|
||||||
departmentId Int
|
departmentId Int
|
||||||
|
|
||||||
doctor Doctor @relation(fields: [doctorId], references: [id])
|
doctor Doctor @relation(fields: [doctorId], references: [id])
|
||||||
department Department @relation(fields: [departmentId], references: [id])
|
department Department @relation(fields: [departmentId], references: [id])
|
||||||
|
|
||||||
timing DoctorTiming?
|
timing DoctorTiming?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
@@unique([doctorId, departmentId])
|
@@unique([doctorId, departmentId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model DoctorTiming {
|
model DoctorTiming {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
|
|
||||||
doctorDepartmentId Int @unique
|
doctorDepartmentId Int @unique
|
||||||
doctorDepartment DoctorDepartment @relation(fields: [doctorDepartmentId], references: [id])
|
doctorDepartment DoctorDepartment @relation(fields: [doctorDepartmentId], references: [id])
|
||||||
|
|
||||||
monday String?
|
monday String?
|
||||||
tuesday String?
|
tuesday String?
|
||||||
wednesday String?
|
wednesday String?
|
||||||
thursday String?
|
thursday String?
|
||||||
friday String?
|
friday String?
|
||||||
saturday String?
|
saturday String?
|
||||||
sunday String?
|
sunday String?
|
||||||
additional String?
|
additional String?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
model Blog {
|
model Blog {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
title String
|
title String
|
||||||
writer String?
|
writer String?
|
||||||
image String?
|
image String?
|
||||||
content Json
|
content Json
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model Career {
|
model Career {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
post String
|
post String
|
||||||
designation String?
|
designation String?
|
||||||
qualification String?
|
qualification String?
|
||||||
experienceNeed String?
|
experienceNeed String?
|
||||||
email String?
|
email String?
|
||||||
number String?
|
number String?
|
||||||
status String @default("new")
|
status String @default("new")
|
||||||
|
|
||||||
candidates Candidate[]
|
candidates Candidate[]
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model Candidate {
|
model Candidate {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
fullName String
|
fullName String
|
||||||
mobile String
|
mobile String
|
||||||
email String
|
email String
|
||||||
subject String
|
subject String
|
||||||
coverLetter String
|
coverLetter String
|
||||||
careerId Int
|
careerId Int
|
||||||
|
|
||||||
career Career @relation(fields: [careerId], references: [id])
|
career Career @relation(fields: [careerId], references: [id])
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model Appointment {
|
model Appointment {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
|
|
||||||
name String
|
name String
|
||||||
mobileNumber String
|
mobileNumber String
|
||||||
email String?
|
email String?
|
||||||
message String?
|
message String?
|
||||||
date DateTime
|
date DateTime
|
||||||
|
|
||||||
doctorId Int
|
doctorId String
|
||||||
departmentId Int
|
departmentId String
|
||||||
|
|
||||||
doctor Doctor @relation(fields: [doctorId], references: [id])
|
doctor Doctor @relation(fields: [doctorId], references: [doctorId])
|
||||||
department Department @relation(fields: [departmentId], references: [id])
|
department Department @relation(fields: [departmentId], references: [departmentId])
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
224
backend/src/controllers/appointment.controller.js
Normal file
224
backend/src/controllers/appointment.controller.js
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
import prisma from "../prisma/client.js";
|
||||||
|
//CREATE APPOINTMENT
|
||||||
|
|
||||||
|
export const createAppointment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {name, mobileNumber, email, message, date, doctorId, departmentId} =
|
||||||
|
req.body;
|
||||||
|
|
||||||
|
if (!name || !mobileNumber || !doctorId || !departmentId || !date) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: "Required fields missing",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const appointment = await prisma.appointment.create({
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
mobileNumber,
|
||||||
|
email,
|
||||||
|
message,
|
||||||
|
date: new Date(date),
|
||||||
|
doctorId,
|
||||||
|
departmentId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
message: "Appointment booked successfully",
|
||||||
|
data: appointment,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to create appointment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET ALL APPOINTMENTS
|
||||||
|
|
||||||
|
export const getAppointments = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const appointments = await prisma.appointment.findMany({
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: appointments,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to fetch appointments",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET SINGLE APPOINTMENT
|
||||||
|
|
||||||
|
export const getAppointment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {id} = req.params;
|
||||||
|
|
||||||
|
const appointment = await prisma.appointment.findUnique({
|
||||||
|
where: {
|
||||||
|
id: Number(id),
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!appointment) {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
message: "Appointment not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: appointment,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to fetch appointment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET APPOINTMENTS BY DOCTOR
|
||||||
|
|
||||||
|
export const getAppointmentsByDoctor = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {doctorId} = req.params;
|
||||||
|
|
||||||
|
const appointments = await prisma.appointment.findMany({
|
||||||
|
where: {
|
||||||
|
doctorId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
date: "asc",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: appointments,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to fetch doctor appointments",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET APPOINTMENTS BY DEPARTMENT
|
||||||
|
|
||||||
|
export const getAppointmentsByDepartment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {departmentId} = req.params;
|
||||||
|
|
||||||
|
const appointments = await prisma.appointment.findMany({
|
||||||
|
where: {
|
||||||
|
departmentId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: appointments,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to fetch department appointments",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE APPOINTMENT
|
||||||
|
|
||||||
|
export const updateAppointment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {id} = req.params;
|
||||||
|
|
||||||
|
const appointment = await prisma.appointment.update({
|
||||||
|
where: {
|
||||||
|
id: Number(id),
|
||||||
|
},
|
||||||
|
data: req.body,
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: "Appointment updated successfully",
|
||||||
|
data: appointment,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to update appointment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//DELETE APPOINTMENT
|
||||||
|
|
||||||
|
export const deleteAppointment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {id} = req.params;
|
||||||
|
|
||||||
|
await prisma.appointment.delete({
|
||||||
|
where: {
|
||||||
|
id: Number(id),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: "Appointment deleted successfully",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to delete appointment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
23
backend/src/routes/appointment.routes.js
Normal file
23
backend/src/routes/appointment.routes.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import express from "express";
|
||||||
|
import {
|
||||||
|
createAppointment,
|
||||||
|
getAppointments,
|
||||||
|
getAppointment,
|
||||||
|
updateAppointment,
|
||||||
|
deleteAppointment,
|
||||||
|
} from "../controllers/appointment.controller.js";
|
||||||
|
|
||||||
|
import jwtAuthMiddleware from "../middleware/auth.js";
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
/* PUBLIC */
|
||||||
|
|
||||||
|
router.get("/getall", getAppointments);
|
||||||
|
router.post("/", createAppointment);
|
||||||
|
|
||||||
|
router.get("/:id", getAppointment);
|
||||||
|
router.patch("/:id", updateAppointment);
|
||||||
|
router.delete("/:id", jwtAuthMiddleware, deleteAppointment);
|
||||||
|
|
||||||
|
export default router;
|
||||||
Reference in New Issue
Block a user