Add lessons Phase 3: enrollments with capacity and time conflict checks
Links members to schedule slots via enrollments. Enforces max_students capacity on slots and prevents members from double-booking the same day/time. Supports status transitions and filtering. 11 new tests (51 total lessons tests).
This commit is contained in:
@@ -4,12 +4,15 @@ import {
|
||||
varchar,
|
||||
text,
|
||||
time,
|
||||
date,
|
||||
numeric,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
pgEnum,
|
||||
} from 'drizzle-orm/pg-core'
|
||||
import { users } from './users.js'
|
||||
import { accounts, members } from './accounts.js'
|
||||
|
||||
// --- Enums ---
|
||||
|
||||
@@ -57,6 +60,37 @@ export const scheduleSlots = pgTable('schedule_slot', {
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
export const enrollmentStatusEnum = pgEnum('enrollment_status', [
|
||||
'active',
|
||||
'paused',
|
||||
'cancelled',
|
||||
'completed',
|
||||
])
|
||||
|
||||
export const enrollments = pgTable('enrollment', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
memberId: uuid('member_id')
|
||||
.notNull()
|
||||
.references(() => members.id),
|
||||
accountId: uuid('account_id')
|
||||
.notNull()
|
||||
.references(() => accounts.id),
|
||||
scheduleSlotId: uuid('schedule_slot_id')
|
||||
.notNull()
|
||||
.references(() => scheduleSlots.id),
|
||||
instructorId: uuid('instructor_id')
|
||||
.notNull()
|
||||
.references(() => instructors.id),
|
||||
status: enrollmentStatusEnum('status').notNull().default('active'),
|
||||
startDate: date('start_date').notNull(),
|
||||
endDate: date('end_date'),
|
||||
monthlyRate: numeric('monthly_rate', { precision: 10, scale: 2 }),
|
||||
makeupCredits: integer('makeup_credits').notNull().default(0),
|
||||
notes: text('notes'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
// --- Type exports ---
|
||||
|
||||
export type Instructor = typeof instructors.$inferSelect
|
||||
@@ -65,3 +99,5 @@ export type LessonType = typeof lessonTypes.$inferSelect
|
||||
export type LessonTypeInsert = typeof lessonTypes.$inferInsert
|
||||
export type ScheduleSlot = typeof scheduleSlots.$inferSelect
|
||||
export type ScheduleSlotInsert = typeof scheduleSlots.$inferInsert
|
||||
export type Enrollment = typeof enrollments.$inferSelect
|
||||
export type EnrollmentInsert = typeof enrollments.$inferInsert
|
||||
|
||||
Reference in New Issue
Block a user