77 lines
3.4 KiB
TypeScript
77 lines
3.4 KiB
TypeScript
import { pgTable, uuid, varchar, text, boolean, integer, decimal, time, date, timestamp, pgEnum } from 'drizzle-orm/pg-core';
|
|
|
|
export const roleEnum = pgEnum('role', ['mitarbeiter', 'admin']);
|
|
export const absenceTypeEnum = pgEnum('absence_type', ['urlaub', 'krank', 'sonderurlaub']);
|
|
|
|
export const users = pgTable('users', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
firstName: varchar('first_name', { length: 100 }).notNull(),
|
|
lastName: varchar('last_name', { length: 100 }).notNull(),
|
|
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
passwordHash: text('password_hash'),
|
|
role: roleEnum('role').notNull().default('mitarbeiter'),
|
|
bundesland: varchar('bundesland', { length: 2 }).notNull().default('MV'),
|
|
standardStart: time('standard_start').notNull().default('08:00'),
|
|
standardEnd: time('standard_end').notNull().default('17:00'),
|
|
breakMinutesDefault: integer('break_minutes_default').notNull().default(30),
|
|
weeklyHours: decimal('weekly_hours', { precision: 4, scale: 1 }).notNull().default('40.0'),
|
|
vacationDaysPerYear: integer('vacation_days_per_year').notNull().default(30),
|
|
active: boolean('active').notNull().default(true),
|
|
inviteToken: text('invite_token'),
|
|
createdAt: timestamp('created_at').notNull().defaultNow()
|
|
});
|
|
|
|
export const sessions = pgTable('sessions', {
|
|
id: text('id').primaryKey(),
|
|
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
expiresAt: timestamp('expires_at').notNull(),
|
|
createdAt: timestamp('created_at').notNull().defaultNow()
|
|
});
|
|
|
|
export const timeEntries = pgTable('time_entries', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
date: date('date').notNull(),
|
|
startTime: time('start_time'),
|
|
endTime: time('end_time'),
|
|
breakMinutes: integer('break_minutes').notNull().default(30),
|
|
isAutoFilled: boolean('is_auto_filled').notNull().default(false),
|
|
isCorrected: boolean('is_corrected').notNull().default(false),
|
|
confirmedAt: timestamp('confirmed_at'),
|
|
createdAt: timestamp('created_at').notNull().defaultNow(),
|
|
updatedAt: timestamp('updated_at').notNull().defaultNow()
|
|
});
|
|
|
|
export const absences = pgTable('absences', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
dateFrom: date('date_from').notNull(),
|
|
dateTo: date('date_to').notNull(),
|
|
type: absenceTypeEnum('type').notNull(),
|
|
notes: text('notes'),
|
|
createdAt: timestamp('created_at').notNull().defaultNow()
|
|
});
|
|
|
|
export const holidays = pgTable('holidays', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
bundesland: varchar('bundesland', { length: 2 }).notNull(),
|
|
date: date('date').notNull(),
|
|
name: varchar('name', { length: 200 }).notNull(),
|
|
year: integer('year').notNull()
|
|
});
|
|
|
|
export const vacationBalances = pgTable('vacation_balances', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
|
year: integer('year').notNull(),
|
|
totalDays: integer('total_days').notNull(),
|
|
carriedOverDays: integer('carried_over_days').notNull().default(0)
|
|
});
|
|
|
|
export type User = typeof users.$inferSelect;
|
|
export type NewUser = typeof users.$inferInsert;
|
|
export type TimeEntry = typeof timeEntries.$inferSelect;
|
|
export type Absence = typeof absences.$inferSelect;
|
|
export type Holiday = typeof holidays.$inferSelect;
|
|
export type VacationBalance = typeof vacationBalances.$inferSelect;
|