From 098fe12fd7d3227d2abb6d6a65d1fb2f0c3c3823 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Mon, 18 May 2026 11:55:55 +0530 Subject: [PATCH] feat: add image upload for health package --- .../migration.sql | 2 + backend/prisma/schema.prisma | 1 + .../src/controllers/healthCheck.controller.js | 2 + frontend/src/api/healthCheck.ts | 1 + .../BytescaleUploader/BytescaleUploader.tsx | 15 ++-- frontend/src/pages/HealthPackagePage.tsx | 80 +++++++++++++------ 6 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 backend/prisma/migrations/20260518055117_health_checkup_optional_image_field/migration.sql diff --git a/backend/prisma/migrations/20260518055117_health_checkup_optional_image_field/migration.sql b/backend/prisma/migrations/20260518055117_health_checkup_optional_image_field/migration.sql new file mode 100644 index 0000000..f6b74f9 --- /dev/null +++ b/backend/prisma/migrations/20260518055117_health_checkup_optional_image_field/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "HealthPackage" ADD COLUMN "image" TEXT; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 482000e..f31c375 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -241,6 +241,7 @@ model HealthPackage { slug String @unique description String? price Decimal? @db.Decimal(10, 2) + image String? discountedPrice Decimal? @db.Decimal(10, 2) inclusions Json @default("{}") diff --git a/backend/src/controllers/healthCheck.controller.js b/backend/src/controllers/healthCheck.controller.js index b039d80..7ee86bb 100644 --- a/backend/src/controllers/healthCheck.controller.js +++ b/backend/src/controllers/healthCheck.controller.js @@ -141,6 +141,7 @@ export const createPackage = async (req, res) => { slug, description, price, + image, discountedPrice, inclusions, categoryId, @@ -155,6 +156,7 @@ export const createPackage = async (req, res) => { slug, description, price, + image, discountedPrice, inclusions, categoryId: Number(categoryId), diff --git a/frontend/src/api/healthCheck.ts b/frontend/src/api/healthCheck.ts index 6de0d50..ae5430e 100644 --- a/frontend/src/api/healthCheck.ts +++ b/frontend/src/api/healthCheck.ts @@ -7,6 +7,7 @@ export interface HealthPackage { slug: string; description?: string; price: number; + image?: string; discountedPrice?: number; inclusions: Record; categoryId: number; diff --git a/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx b/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx index e4e1646..cc412f3 100644 --- a/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx +++ b/frontend/src/components/BytescaleUploader/BytescaleUploader.tsx @@ -1,12 +1,17 @@ -import {useState, useRef} from "react"; -import {Button} from "@/components/ui/button"; -import {User, X, Loader2} from "lucide-react"; +import { useState, useRef } from "react"; +import { Button } from "@/components/ui/button"; +import { User, X, Loader2 } from "lucide-react"; import axios from "axios"; interface BytescaleUploaderProps { value: string; onChange: (url: string) => void; - folderPath: "/doctors" | "/departments" | "/news" | "/blog"; + folderPath: + | "/doctors" + | "/departments" + | "/news" + | "/blog" + | "/health-packages"; } export function BytescaleUploader({ @@ -40,7 +45,7 @@ export function BytescaleUploader({ }, }); - const {fileUrl} = response.data; + const { fileUrl } = response.data; onChange(fileUrl); } catch (e: any) { console.error("Upload Error:", e); diff --git a/frontend/src/pages/HealthPackagePage.tsx b/frontend/src/pages/HealthPackagePage.tsx index d436269..02b793b 100644 --- a/frontend/src/pages/HealthPackagePage.tsx +++ b/frontend/src/pages/HealthPackagePage.tsx @@ -1,5 +1,6 @@ import { useState, useEffect, useCallback, useMemo } from "react"; import { AxiosError } from "axios"; +import { BytescaleUploader } from "@/components/BytescaleUploader/BytescaleUploader"; import { getHealthPackagesApi, @@ -91,6 +92,7 @@ export default function HealthPackagePage() { name: "", slug: "", description: "", + image: "", price: 0, discountedPrice: 0, categoryId: 0, @@ -190,6 +192,7 @@ export default function HealthPackagePage() { name: "", slug: "", description: "", + image: "", price: 0, discountedPrice: 0, categoryId: categories[0]?.id || 0, @@ -355,7 +358,8 @@ export default function HealthPackagePage() {