mirror of
https://github.com/soconnor0919/hristudio.git
synced 2025-12-12 07:04:44 -05:00
chore(deps): Update dependencies and refactor API routes for improved error handling
- Updated various dependencies in package.json and pnpm-lock.yaml, including '@clerk/nextjs' to version 6.7.1 and several others for better performance and security. - Refactored API routes to use Promise.resolve for context parameters, enhancing reliability in asynchronous contexts. - Improved error handling in the dashboard and studies components, ensuring better user experience during data fetching. - Removed unused favicon.ico file to clean up the project structure. - Enhanced the dashboard components to utilize a new utility function for API URL fetching, promoting code reusability.
This commit is contained in:
@@ -3,7 +3,14 @@ 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, userRolesTable, usersTable, studyTable } from "./schema";
|
||||
import {
|
||||
permissionsTable,
|
||||
rolesTable,
|
||||
rolePermissionsTable,
|
||||
userRolesTable,
|
||||
usersTable,
|
||||
studyTable,
|
||||
} from "~/db/schema";
|
||||
|
||||
// Load environment variables from .env.local
|
||||
config({ path: ".env.local" });
|
||||
@@ -14,7 +21,8 @@ async function seed() {
|
||||
// Insert roles
|
||||
console.log("Inserting roles...");
|
||||
for (const [roleKey, roleName] of Object.entries(ROLES)) {
|
||||
await db.insert(rolesTable)
|
||||
await db
|
||||
.insert(rolesTable)
|
||||
.values({
|
||||
name: roleName,
|
||||
description: getRoleDescription(roleKey),
|
||||
@@ -25,7 +33,8 @@ async function seed() {
|
||||
// Insert permissions
|
||||
console.log("Inserting permissions...");
|
||||
for (const [permKey, permCode] of Object.entries(PERMISSIONS)) {
|
||||
await db.insert(permissionsTable)
|
||||
await db
|
||||
.insert(permissionsTable)
|
||||
.values({
|
||||
name: formatPermissionName(permKey),
|
||||
code: permCode,
|
||||
@@ -41,14 +50,19 @@ async function seed() {
|
||||
// Insert role permissions
|
||||
console.log("Inserting role permissions...");
|
||||
for (const [roleKey, permissionCodes] of Object.entries(ROLE_PERMISSIONS)) {
|
||||
const role = roles.find(r => r.name === ROLES[roleKey as keyof typeof ROLES]);
|
||||
const role = roles.find(
|
||||
(r) => r.name === ROLES[roleKey as keyof typeof ROLES]
|
||||
);
|
||||
if (!role) continue;
|
||||
|
||||
for (const permissionCode of permissionCodes) {
|
||||
const permission = permissions.find(p => p.code === PERMISSIONS[permissionCode]);
|
||||
const permission = permissions.find(
|
||||
(p) => p.code === PERMISSIONS[permissionCode]
|
||||
);
|
||||
if (!permission) continue;
|
||||
|
||||
await db.insert(rolePermissionsTable)
|
||||
await db
|
||||
.insert(rolePermissionsTable)
|
||||
.values({
|
||||
roleId: role.id,
|
||||
permissionId: permission.id,
|
||||
@@ -61,7 +75,7 @@ async function seed() {
|
||||
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);
|
||||
const piRole = roles.find((r) => r.name === ROLES.PRINCIPAL_INVESTIGATOR);
|
||||
if (piRole) {
|
||||
// Get all studies owned by the first user
|
||||
const userStudies = await db
|
||||
@@ -71,7 +85,8 @@ async function seed() {
|
||||
|
||||
// Assign PI role for each study
|
||||
for (const study of userStudies) {
|
||||
await db.insert(userRolesTable)
|
||||
await db
|
||||
.insert(userRolesTable)
|
||||
.values({
|
||||
userId: users[0].id,
|
||||
roleId: piRole.id,
|
||||
@@ -88,8 +103,10 @@ async function seed() {
|
||||
function getRoleDescription(roleKey: string): string {
|
||||
const descriptions: Record<string, string> = {
|
||||
ADMIN: "Full system administrator with all permissions",
|
||||
PRINCIPAL_INVESTIGATOR: "Lead researcher responsible for study design and oversight",
|
||||
RESEARCHER: "Study team member with data collection and analysis capabilities",
|
||||
PRINCIPAL_INVESTIGATOR:
|
||||
"Lead researcher responsible for study design and oversight",
|
||||
RESEARCHER:
|
||||
"Study team member with data collection and analysis capabilities",
|
||||
WIZARD: "Operator controlling robot behavior during experiments",
|
||||
OBSERVER: "Team member observing and annotating experiments",
|
||||
ASSISTANT: "Support staff with limited view access",
|
||||
@@ -122,10 +139,11 @@ function getPermissionDescription(permKey: string): string {
|
||||
}
|
||||
|
||||
function formatPermissionName(permKey: string): string {
|
||||
return permKey.toLowerCase()
|
||||
.split('_')
|
||||
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
return permKey
|
||||
.toLowerCase()
|
||||
.split("_")
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
seed().catch(console.error);
|
||||
|
||||
Reference in New Issue
Block a user