basic stracture and auth
in memory db :)
This commit is contained in:
commit
3a554ba434
71 files changed
+28535
No files matched your search
@@ -0,0 +1,8 @@
|
||||
import Database from 'better-sqlite3'
|
||||
import { drizzle } from 'drizzle-orm/better-sqlite3'
|
||||
import * as schema from './schema'
|
||||
|
||||
const sqlite = new Database('./fitai.db')
|
||||
export const db = drizzle(sqlite, { schema })
|
||||
|
||||
export * from './schema'
|
||||
@@ -0,0 +1,72 @@
|
||||
import { sqliteTable, text, integer, real } from 'drizzle-orm/sqlite-core'
|
||||
|
||||
export const users = sqliteTable('users', {
|
||||
id: text('id').primaryKey(),
|
||||
email: text('email').notNull().unique(),
|
||||
firstName: text('first_name').notNull(),
|
||||
lastName: text('last_name').notNull(),
|
||||
password: text('password').notNull(),
|
||||
role: text('role', { enum: ['admin', 'trainer', 'client'] }).notNull().default('client'),
|
||||
phone: text('phone'),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
})
|
||||
|
||||
export const clients = sqliteTable('clients', {
|
||||
id: text('id').primaryKey(),
|
||||
userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
membershipType: text('membership_type', { enum: ['basic', 'premium', 'vip'] }).notNull().default('basic'),
|
||||
membershipStatus: text('membership_status', { enum: ['active', 'inactive', 'suspended'] }).notNull().default('active'),
|
||||
joinDate: integer('join_date', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
lastVisit: integer('last_visit', { mode: 'timestamp' }),
|
||||
emergencyContactName: text('emergency_contact_name'),
|
||||
emergencyContactPhone: text('emergency_contact_phone'),
|
||||
emergencyContactRelationship: text('emergency_contact_relationship'),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
})
|
||||
|
||||
export const payments = sqliteTable('payments', {
|
||||
id: text('id').primaryKey(),
|
||||
clientId: text('client_id').notNull().references(() => clients.id, { onDelete: 'cascade' }),
|
||||
amount: real('amount').notNull(),
|
||||
currency: text('currency').notNull().default('USD'),
|
||||
status: text('status', { enum: ['pending', 'completed', 'failed', 'refunded'] }).notNull().default('pending'),
|
||||
paymentMethod: text('payment_method', { enum: ['cash', 'card', 'bank_transfer'] }).notNull(),
|
||||
dueDate: integer('due_date', { mode: 'timestamp' }).notNull(),
|
||||
paidAt: integer('paid_at', { mode: 'timestamp' }),
|
||||
description: text('description').notNull(),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
})
|
||||
|
||||
export const attendance = sqliteTable('attendance', {
|
||||
id: text('id').primaryKey(),
|
||||
clientId: text('client_id').notNull().references(() => clients.id, { onDelete: 'cascade' }),
|
||||
checkInTime: integer('check_in_time', { mode: 'timestamp' }).notNull(),
|
||||
checkOutTime: integer('check_out_time', { mode: 'timestamp' }),
|
||||
type: text('type', { enum: ['gym', 'class', 'personal_training'] }).notNull().default('gym'),
|
||||
notes: text('notes'),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
})
|
||||
|
||||
export const notifications = sqliteTable('notifications', {
|
||||
id: text('id').primaryKey(),
|
||||
userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
title: text('title').notNull(),
|
||||
message: text('message').notNull(),
|
||||
type: text('type', { enum: ['payment_reminder', 'attendance', 'promotion', 'system'] }).notNull(),
|
||||
read: integer('read', { mode: 'boolean' }).notNull().default(false),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
||||
})
|
||||
|
||||
export type User = typeof users.$inferSelect
|
||||
export type NewUser = typeof users.$inferInsert
|
||||
export type Client = typeof clients.$inferSelect
|
||||
export type NewClient = typeof clients.$inferInsert
|
||||
export type Payment = typeof payments.$inferSelect
|
||||
export type NewPayment = typeof payments.$inferInsert
|
||||
export type Attendance = typeof attendance.$inferSelect
|
||||
export type NewAttendance = typeof attendance.$inferInsert
|
||||
export type Notification = typeof notifications.$inferSelect
|
||||
export type NewNotification = typeof notifications.$inferInsert
|
||||
Reference in new issue
Block a user