Skip to content

Commit

Permalink
complete create schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
alifhaider committed Sep 11, 2024
1 parent 0d4debb commit fe721ae
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
14 changes: 13 additions & 1 deletion app/routes/add.schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,19 @@ export async function action({ request }: ActionFunctionArgs) {
return z.NEVER
}

const schedule = { id: 1 } // perform schedule create here
const schedule = await prisma.schedule.createMany({
data: scheduleDates.map(date => ({
doctorId: data.userId,
locationId,
date: new Date(date),
startTime,
endTime,
maxAppointments: data.maxAppointment,
visitFee: data.visitingFee,
serialFee: data.serialFee,
discountFee: data.discount,
})),
})

if (!schedule) {
ctx.addIssue({
Expand Down
38 changes: 14 additions & 24 deletions app/routes/profile.$username._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
schedules: {
// where: { startTime: { gte: today } },
include: {
fees: {
select: { id: true, serial: true, visit: true, discount: true },
},
location: {
select: {
id: true,
Expand Down Expand Up @@ -291,12 +288,9 @@ type ScheduleProp = {
state: string | null
zip: string | null
}
fees: {
id: string
serial: number | null
visit: number | null
discount: number | null
}[]
serialFee: number | null
discountFee: number | null
visitFee: number | null
}

type ScheduleProps = {
Expand Down Expand Up @@ -384,21 +378,17 @@ const Schedules = ({
</div>
</div>
</div>
<ul>
{schedule.fees.map(fee => (
<li key={fee.id}>
<div className="text-xl font-bold text-accent-foreground">
Visiting Fee: {fee.visit}tk
</div>
<div className="text-secondary-foreground">
Serial Fee: {fee.serial}tk
</div>
<div className="text-sm text-secondary-foreground">
Discount: {fee.discount}tk
</div>
</li>
))}
</ul>
<div>
<div className="text-xl font-bold text-accent-foreground">
Visit Fee: {schedule.visitFee}tk
</div>
<div className="text-secondary-foreground">
Serial Fee: {schedule.serialFee}tk
</div>
<div className="text-sm text-secondary-foreground">
Discount: {schedule.discountFee}tk
</div>
</div>
</div>
</div>
</li>
Expand Down
Binary file modified prisma/dev.db
Binary file not shown.
15 changes: 15 additions & 0 deletions prisma/migrations/20240910235829_fees/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Warnings:
- You are about to drop the `Fee` table. If the table is not empty, all the data it contains will be lost.
*/
-- AlterTable
ALTER TABLE "Schedule" ADD COLUMN "discountFee" INTEGER;
ALTER TABLE "Schedule" ADD COLUMN "serialFee" INTEGER;
ALTER TABLE "Schedule" ADD COLUMN "visitFee" INTEGER;

-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "Fee";
PRAGMA foreign_keys=on;
18 changes: 3 additions & 15 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ model Schedule {
location ScheduleLocation @relation(fields: [locationId], references: [id])
locationId String
fees Fee[]
serialFee Int?
discountFee Int?
visitFee Int?
date DateTime
startTime String
Expand Down Expand Up @@ -142,20 +144,6 @@ model DoctorSpecialty {
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model Fee {
id String @id @default(cuid())
schedule Schedule @relation(fields: [scheduleId], references: [id])
scheduleId String
serial Int?
discount Int?
visit Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
11 changes: 3 additions & 8 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ async function seed() {

console.time('🧹 Clean up database...')
await prisma.booking.deleteMany()
await prisma.fee.deleteMany()
await prisma.schedule.deleteMany()
await prisma.doctorSpecialty.deleteMany()
await prisma.scheduleLocation.deleteMany()
Expand Down Expand Up @@ -213,13 +212,9 @@ async function seed() {
endTime: `${endTimeHours}:${faker.date.anytime().getMinutes()}`,
locationId: scheduleLocations[index % totalScheduleLocations].id,
maxAppointments: Math.floor(Math.random() * 10),
fees: {
create: {
serial: Math.floor(Math.random() * 100),
visit: Math.floor(Math.random() * 1000),
discount: Math.floor(Math.random() * 100),
},
},
serialFee: Math.floor(Math.random() * 1000),
discountFee: Math.floor(Math.random() * 1000),
visitFee: Math.floor(Math.random() * 1000),
},
})
return schedule
Expand Down

0 comments on commit fe721ae

Please sign in to comment.