mirror of
https://github.com/soconnor0919/hristudio.git
synced 2025-12-12 07:04:44 -05:00
feat(env): Update environment configuration and enhance email functionality
- Renamed DATABASE_URL to POSTGRES_URL in .env.example for clarity. - Added SMTP configuration for email sending, including host, port, user, password, and from address. - Updated package.json to include new dependencies for email handling and UI components. - Modified middleware to handle public and protected routes more effectively. - Enhanced API routes for studies to support user roles and permissions. - Updated database schema to include invitations and user roles related to studies. - Improved user permissions handling in the permissions module. - Added new utility functions for managing user roles and study access.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { config } from "dotenv";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "./index";
|
||||
import { PERMISSIONS } from "~/lib/permissions";
|
||||
import { ROLES, ROLE_PERMISSIONS } from "~/lib/roles";
|
||||
import { permissionsTable, rolesTable, rolePermissionsTable } from "./schema";
|
||||
import { permissionsTable, rolesTable, rolePermissionsTable, userRolesTable, usersTable, studyTable } from "./schema";
|
||||
|
||||
// Load environment variables from .env.local
|
||||
config({ path: ".env.local" });
|
||||
@@ -56,6 +57,31 @@ async function seed() {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the first user and assign them as a Principal Investigator for their studies
|
||||
console.log("Setting up initial user roles...");
|
||||
const users = await db.select().from(usersTable);
|
||||
if (users.length > 0) {
|
||||
const piRole = roles.find(r => r.name === ROLES.PRINCIPAL_INVESTIGATOR);
|
||||
if (piRole) {
|
||||
// Get all studies owned by the first user
|
||||
const userStudies = await db
|
||||
.select()
|
||||
.from(studyTable)
|
||||
.where(eq(studyTable.userId, users[0].id));
|
||||
|
||||
// Assign PI role for each study
|
||||
for (const study of userStudies) {
|
||||
await db.insert(userRolesTable)
|
||||
.values({
|
||||
userId: users[0].id,
|
||||
roleId: piRole.id,
|
||||
studyId: study.id,
|
||||
})
|
||||
.onConflictDoNothing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("✅ Seeding complete!");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user