diff --git a/backend/prisma/migrations/20260414074145_doctor_image_field/migration.sql b/backend/prisma/migrations/20260414074145_doctor_image_field/migration.sql new file mode 100644 index 0000000..21ce1fc --- /dev/null +++ b/backend/prisma/migrations/20260414074145_doctor_image_field/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Doctor" ADD COLUMN "image" TEXT; diff --git a/backend/prisma/migrations/20260414102430_department_image/migration.sql b/backend/prisma/migrations/20260414102430_department_image/migration.sql new file mode 100644 index 0000000..a6be709 --- /dev/null +++ b/backend/prisma/migrations/20260414102430_department_image/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Department" ADD COLUMN "image" TEXT; diff --git a/backend/prisma/migrations/20260414105925_news_media/migration.sql b/backend/prisma/migrations/20260414105925_news_media/migration.sql new file mode 100644 index 0000000..f75efe7 --- /dev/null +++ b/backend/prisma/migrations/20260414105925_news_media/migration.sql @@ -0,0 +1,12 @@ +-- CreateTable +CREATE TABLE "NewsImage" ( + "id" SERIAL NOT NULL, + "url" TEXT NOT NULL, + "newsMediaId" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "NewsImage_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "NewsImage" ADD CONSTRAINT "NewsImage_newsMediaId_fkey" FOREIGN KEY ("newsMediaId") REFERENCES "NewsMedia"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 9cc2df9..69d24db 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -21,6 +21,7 @@ model Doctor { id Int @id @default(autoincrement()) doctorId String @unique name String + image String? designation String? workingStatus String? qualification String? @@ -36,6 +37,8 @@ model Department { id Int @id @default(autoincrement()) departmentId String @unique name String + image String? + para1 String? para2 String? @@ -196,9 +199,18 @@ model NewsMedia { secondPara String? author String? date DateTime? + images NewsImage[] - isActive Boolean @default(true) - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + isActive Boolean @default(true) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} + +model NewsImage { + id Int @id @default(autoincrement()) + url String + newsMediaId Int + newsMedia NewsMedia @relation(fields: [newsMediaId], references: [id], onDelete: Cascade) + + createdAt DateTime @default(now()) } diff --git a/backend/src/controllers/department.controller.js b/backend/src/controllers/department.controller.js index 17c199b..4ff80c2 100644 --- a/backend/src/controllers/department.controller.js +++ b/backend/src/controllers/department.controller.js @@ -9,6 +9,7 @@ export const getAllDepartments = async (req, res) => { const response = departments.map((dep) => ({ departmentId: dep.departmentId, name: dep.name, + image: dep.image ?? "", para1: dep.para1 ?? "", para2: dep.para2 ?? "", para3: dep.para3 ?? "", @@ -56,6 +57,7 @@ export const getDepartmentByName = async (req, res) => { const response = { departmentId: department.departmentId, name: department.name, + image: department.image ?? "", para1: department.para1 ?? "", para2: department.para2 ?? "", para3: department.para3 ?? "", @@ -78,8 +80,16 @@ export const getDepartmentByName = async (req, res) => { export async function createDepartment(req, res) { try { - const {departmentId, name, para1, para2, para3, facilities, services} = - req.body; + const { + departmentId, + name, + image, + para1, + para2, + para3, + facilities, + services, + } = req.body; if (!departmentId || !name) { return res @@ -91,6 +101,7 @@ export async function createDepartment(req, res) { data: { departmentId, name, + image, para1, para2, para3, @@ -116,12 +127,13 @@ export const updateDepartment = async (req, res) => { try { const {departmentId} = req.params; - const {name, para1, para2, para3, facilities, services} = req.body; + const {name, image, para1, para2, para3, facilities, services} = req.body; const department = await prisma.department.update({ where: {departmentId}, data: { name, + image, para1, para2, para3, diff --git a/backend/src/controllers/doctor.controller.js b/backend/src/controllers/doctor.controller.js index dde079f..34007ed 100644 --- a/backend/src/controllers/doctor.controller.js +++ b/backend/src/controllers/doctor.controller.js @@ -20,6 +20,7 @@ export const getAllDoctors = async (req, res) => { SL_NO: String(index + 1), doctorId: doc.doctorId, name: doc.name, + image: doc.image ?? "", designation: doc.designation, workingStatus: doc.workingStatus, qualification: doc.qualification, @@ -87,6 +88,7 @@ export const getDoctorByDoctorId = async (req, res) => { const response = { doctorId: doctor.doctorId, name: doctor.name, + image: doctor.image ?? "", designation: doctor.designation, workingStatus: doctor.workingStatus, qualification: doctor.qualification, @@ -143,6 +145,7 @@ export const getDoctorsByDepartmentId = async (req, res) => { const result = doctors.map((d) => ({ GG_ID: d.doctor.doctorId, Name: d.doctor.name, + image: d.doctor.image ?? "", })); res.status(200).json({ @@ -164,6 +167,7 @@ export const createDoctor = async (req, res) => { const { doctorId, name, + image, designation, workingStatus, qualification, @@ -174,6 +178,7 @@ export const createDoctor = async (req, res) => { data: { doctorId, name, + image, designation, workingStatus, qualification, @@ -221,8 +226,14 @@ export const createDoctor = async (req, res) => { export const updateDoctor = async (req, res) => { try { const {doctorId} = req.params; - const {name, designation, workingStatus, qualification, departments} = - req.body; + const { + name, + designation, + image, + workingStatus, + qualification, + departments, + } = req.body; const doctor = await prisma.doctor.findUnique({ where: {doctorId}, @@ -236,7 +247,7 @@ export const updateDoctor = async (req, res) => { await prisma.doctor.update({ where: {id: doctor.id}, - data: {name, designation, workingStatus, qualification}, + data: {name, designation, image, workingStatus, qualification}, }); const oldRelations = await prisma.doctorDepartment.findMany({ diff --git a/backend/src/controllers/inquiry.controller.js b/backend/src/controllers/inquiry.controller.js index 2077400..474de9e 100644 --- a/backend/src/controllers/inquiry.controller.js +++ b/backend/src/controllers/inquiry.controller.js @@ -1,5 +1,8 @@ import prisma from "../prisma/client.js"; +import {sendEmail} from "../utils/sendEmail.js"; +import {getEmailsByType} from "../utils/getEmailByTypes.js"; + /* CREATE INQUIRY */ export const createInquiry = async (req, res) => { try { @@ -21,6 +24,28 @@ export const createInquiry = async (req, res) => { message, }, }); + try { + const emailList = await getEmailsByType("INQUIRY"); + + if (emailList && emailList.length > 0) { + await sendEmail({ + to: emailList, + subject: "New Inquiry Received", + html: ` +

New Inquiry

+ +

Name: ${fullName}

+

Phone: ${number}

+

Email: ${emailId}

+ +

Subject: ${subject}

+

Message: ${message}

+ `, + }); + } + } catch (err) { + console.error("Inquiry email failed:", err); + } res.status(200).json({ success: true, diff --git a/backend/src/controllers/newsMedia.controller.js b/backend/src/controllers/newsMedia.controller.js index 32f8d20..473da8f 100644 --- a/backend/src/controllers/newsMedia.controller.js +++ b/backend/src/controllers/newsMedia.controller.js @@ -7,8 +7,13 @@ export const getAllNews = async (req, res) => { const page = parseInt(req.query.page); const limit = parseInt(req.query.limit); + const includeImages = { + images: true, + }; + if (!page && !limit) { const news = await prisma.newsMedia.findMany({ + include: includeImages, orderBy: { createdAt: "desc" }, }); @@ -20,6 +25,10 @@ export const getAllNews = async (req, res) => { SecondPara: n.secondPara, Date: n.date, Author: n.author, + Images: n.images.map((img) => ({ + id: img.id, + image: img.url, + })), })); return res.status(200).json({ @@ -36,6 +45,7 @@ export const getAllNews = async (req, res) => { const [news, total] = await Promise.all([ prisma.newsMedia.findMany({ + include: includeImages, orderBy: { createdAt: "desc" }, skip, take: currentLimit, @@ -51,6 +61,10 @@ export const getAllNews = async (req, res) => { SecondPara: n.secondPara, Date: n.date, Author: n.author, + Images: n.images.map((img) => ({ + id: img.id, + image: img.url, + })), })); return res.status(200).json({ @@ -80,6 +94,7 @@ export const getNewsById = async (req, res) => { const n = await prisma.newsMedia.findUnique({ where: { id: Number(id) }, + include: { images: true }, }); if (!n) { @@ -97,6 +112,10 @@ export const getNewsById = async (req, res) => { SecondPara: n.secondPara, Date: n.date, Author: n.author, + Images: n.images.map((img) => ({ + id: img.id, + image: img.url, + })), }; return res.status(200).json({ @@ -116,7 +135,15 @@ export const getNewsById = async (req, res) => { export const createNews = async (req, res) => { try { - const { headline, content, firstPara, secondPara, date, author } = req.body; + const { + headline, + content, + firstPara, + secondPara, + date, + author, + imageUrls, + } = req.body; if (!headline) { return res.status(400).json({ @@ -133,7 +160,13 @@ export const createNews = async (req, res) => { secondPara, date: date ? new Date(date) : null, author, + images: imageUrls + ? { + create: imageUrls.map((url) => ({ url })), + } + : undefined, }, + include: { images: true }, }); return res.status(201).json({ @@ -155,13 +188,21 @@ export const createNews = async (req, res) => { export const updateNews = async (req, res) => { try { const { id } = req.params; + const { imageUrls, ...otherData } = req.body; const news = await prisma.newsMedia.update({ where: { id: Number(id) }, data: { - ...req.body, + ...otherData, date: req.body.date ? new Date(req.body.date) : undefined, + images: imageUrls + ? { + deleteMany: {}, + create: imageUrls.map((url) => ({ url })), + } + : undefined, }, + include: { images: true }, }); return res.status(200).json({ diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 46ed472..9e8ff38 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8,6 +8,7 @@ "name": "frontend", "version": "0.0.0", "dependencies": { + "@bytescale/sdk": "^3.53.0", "@editorjs/code": "^2.9.4", "@editorjs/delimiter": "^1.4.2", "@editorjs/editorjs": "^2.31.5", @@ -524,6 +525,12 @@ "node": ">=6.9.0" } }, + "node_modules/@bytescale/sdk": { + "version": "3.53.0", + "resolved": "https://registry.npmjs.org/@bytescale/sdk/-/sdk-3.53.0.tgz", + "integrity": "sha512-qCeNup3pSjaklXuBrO9JeKbozZEs/PjQEvuqCiOAWLBRl6lDjd0V9gRVYqyttPimXYFoV+J/7dmPWtK6RfOABQ==", + "license": "MIT" + }, "node_modules/@codexteam/icons": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@codexteam/icons/-/icons-0.3.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index a97269e..79b6ac9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "@bytescale/sdk": "^3.53.0", "@editorjs/code": "^2.9.4", "@editorjs/delimiter": "^1.4.2", "@editorjs/editorjs": "^2.31.5", diff --git a/frontend/src/api/department.ts b/frontend/src/api/department.ts index 86fc40e..7de2e4c 100644 --- a/frontend/src/api/department.ts +++ b/frontend/src/api/department.ts @@ -3,6 +3,7 @@ import apiClient from "@/api/client"; export interface Department { departmentId: string; name: string; + image?: string; para1: string; para2: string; para3: string; diff --git a/frontend/src/api/doctor.ts b/frontend/src/api/doctor.ts index 18c0014..82d2065 100644 --- a/frontend/src/api/doctor.ts +++ b/frontend/src/api/doctor.ts @@ -3,6 +3,7 @@ import apiClient from "@/api/client"; export interface Doctor { doctorId: string; name: string; + image?: string; designation?: string; workingStatus?: string; qualification?: string; diff --git a/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx b/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx new file mode 100644 index 0000000..7636aa7 --- /dev/null +++ b/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx @@ -0,0 +1,109 @@ +import { useState, useRef } from "react"; +import * as Bytescale from "@bytescale/sdk"; +import { Button } from "@/components/ui/button"; +import { User, X, Loader2 } from "lucide-react"; + +interface BytescaleUploaderProps { + value: string; + onChange: (url: string) => void; + folderPath: "/doctors" | "/departments" | "/news"; +} + +const uploadManager = new Bytescale.UploadManager({ + apiKey: "public_223k2cv3MyaAxBeyALCfJa8EMLek", +}); + +export function BytescaleUploader({ value, onChange }: BytescaleUploaderProps) { + const [isUploading, setIsUploading] = useState(false); + const fileInputRef = useRef(null); + + const onFileSelected = async (event: React.ChangeEvent) => { + const file = event.target.files?.[0]; + if (!file) return; + + setIsUploading(true); + try { + const { fileUrl } = await uploadManager.upload({ + data: file, + path: { + folderPath: "/doctors", + }, + }); + + onChange(fileUrl); + } catch (e: any) { + console.error("Upload Error:", e); + alert(`Error:\n${e.message}`); + } finally { + setIsUploading(false); + if (fileInputRef.current) fileInputRef.current.value = ""; + } + }; + + return ( +
+
+
+ {value ? ( + <> + Doctor Profile + + + ) : ( +
+ {isUploading ? ( + + ) : ( + + )} +
+ )} +
+ + + + +
+ + {value && ( +

+ ⚠️ Make sure to save the changes by clicking the "Save Changes" button + at the bottom. +

+ )} +
+ ); +} diff --git a/frontend/src/pages/Department.tsx b/frontend/src/pages/Department.tsx index e56ac07..2e119b2 100644 --- a/frontend/src/pages/Department.tsx +++ b/frontend/src/pages/Department.tsx @@ -1,5 +1,6 @@ import { useState, useEffect, useCallback } from "react"; import { AxiosError } from "axios"; +import { BytescaleUploader } from "@/components/BytescaleUploader/BytescaleUploader"; import { getDepartmentsApi, @@ -45,6 +46,7 @@ import { interface Department { departmentId: string; name: string; + image?: string; para1: string; para2: string; para3: string; @@ -71,6 +73,7 @@ export default function DepartmentPage() { const [form, setForm] = useState({ departmentId: "", name: "", + image: "", para1: "", para2: "", para3: "", @@ -132,6 +135,7 @@ export default function DepartmentPage() { setForm({ departmentId: "", name: "", + image: "", para1: "", para2: "", para3: "", @@ -393,6 +397,14 @@ export default function DepartmentPage() {
+
+ + setForm({ ...form, image: url })} + /> +
({ doctorId: "", name: "", + image: "", designation: "", workingStatus: "", qualification: "", @@ -161,6 +166,7 @@ export default function DoctorPage() { setForm({ doctorId: "", name: "", + image: "", designation: "", workingStatus: "", qualification: "", @@ -177,6 +183,7 @@ export default function DoctorPage() { setForm({ doctorId: doc.doctorId, name: doc.name, + image: doc.image || "", designation: doc.designation, workingStatus: doc.workingStatus, qualification: doc.qualification, @@ -439,155 +446,172 @@ export default function DoctorPage() { - - + + {editing ? "Edit Doctor" : "Add Doctor"} -
-
-

- Basic Information -

-
-
- - +
+
+
+

+ Basic Information +

+
+
+ + setForm({ ...form, image: url })} + /> +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
-
- - -
-
- - -
-
- - -
-
- - + +
+

Assign Departments

+
+ {departments.map((dep) => { + const isSelected = form.departments.some( + (d: any) => d.departmentId === dep.departmentId, + ); + return ( + + ); + })} +
-
-

Assign Departments

-
- {departments.map((dep) => { - const isSelected = form.departments.some( - (d: any) => d.departmentId === dep.departmentId, - ); - return ( - - ); - })} -
+
+

+ Working Hours / Timing +

+ {form.departments.length === 0 ? ( +
+ Select a department to configure timing slots +
+ ) : ( +
+ {form.departments.map((dep: any) => { + const depName = departments.find( + (d) => d.departmentId === dep.departmentId, + )?.name; + return ( +
+
+

+ {depName} +

+ + Timing Slot + +
+
+ {DAYS.map((day) => ( +
+ + + handleTimingChange( + dep.departmentId, + day, + e.target.value, + ) + } + /> +
+ ))} +
+
+ ); + })} +
+ )}
- -
-

- Working Hours / Timing -

- {form.departments.length === 0 ? ( -
- Select a department to configure timing slots -
- ) : ( -
- {form.departments.map((dep: any) => { - const depName = departments.find( - (d) => d.departmentId === dep.departmentId, - )?.name; - return ( -
-
-

- {depName} -

- - Timing Slot - -
-
- {DAYS.map((day) => ( -
- - - handleTimingChange( - dep.departmentId, - day, - e.target.value, - ) - } - /> -
- ))} -
-
- ); - })} -
- )} -
- + @@ -225,10 +227,12 @@ export default function EmailPage() { name="type" value={form.type} onChange={handleChange} - className="border rounded px-2 py-2 w-full"> + className="border rounded px-2 py-2 w-full" + > + diff --git a/frontend/src/pages/newsMedia.tsx b/frontend/src/pages/newsMedia.tsx index 1c48817..b5a7de9 100644 --- a/frontend/src/pages/newsMedia.tsx +++ b/frontend/src/pages/newsMedia.tsx @@ -1,4 +1,5 @@ import { useState, useEffect, useCallback } from "react"; +import { BytescaleUploader } from "@/components/BytescaleUploader/BytescaleUploader"; import { getNewsApi, @@ -39,6 +40,8 @@ import { ChevronLeft, ChevronRight, Newspaper, + ImageIcon, + X, } from "lucide-react"; export default function NewsPage() { @@ -60,6 +63,7 @@ export default function NewsPage() { const [form, setForm] = useState({ headline: "", content: "", + imageUrls: [] as string[], firstPara: "", secondPara: "", date: "", @@ -96,11 +100,19 @@ export default function NewsPage() { setForm({ ...form, [e.target.name]: e.target.value }); } + function removeImageUrl(index: number) { + setForm((prev) => ({ + ...prev, + imageUrls: prev.imageUrls.filter((_, i) => i !== index), + })); + } + function openAdd() { setEditing(null); setForm({ headline: "", content: "", + imageUrls: [], firstPara: "", secondPara: "", date: "", @@ -114,6 +126,7 @@ export default function NewsPage() { setForm({ headline: item.Headline || "", content: item.Content || "", + imageUrls: item.Images ? item.Images.map((img: any) => img.image) : [], firstPara: item.FirstPara || "", secondPara: item.SecondPara || "", date: item.Date ? item.Date.split("T")[0] : "", @@ -205,6 +218,9 @@ export default function NewsPage() { ID + + Cover + Headline @@ -226,14 +242,14 @@ export default function NewsPage() { {loading ? ( - + ) : filteredNews.length === 0 ? ( No news articles found @@ -245,6 +261,19 @@ export default function NewsPage() { {item.Id} + + {item.Images?.[0] ? ( + cover + ) : ( +
+ +
+ )} +
- + {editing ? "Edit News Article" : "Add New News Article"} -
-
+
+

Article Information

-
-
+
+
-
+