Refactor: Centralize Prisma schema and restrict DB access

This commit refactors the project to use a shared Prisma schema and restricts direct database access to the API service.

Key changes:

- Created a new shared package `core/prisma` containing the Prisma schema, generated client, and types.
- Configured the monorepo to use NPM workspaces, including `core/prisma` and all services.
- Updated all services (`api`, `ui`, `mcp`, `agent`, and the background processing service) to depend on `@empresa/prisma-schema`.
- The API service now imports `PrismaClient` from `@empresa/prisma-schema/client`.
- Other services import only types from `@empresa/prisma-schema`.
- Removed redundant Prisma configurations from `api` and the background processing service.
- Updated the background processing service's `sync-empleados.js` to fetch data via an API call instead of direct database access.
- Updated TypeScript configurations (`tsconfig.base.json` and service-specific ones) to support the new structure and path aliases.
- Updated `README.md` to reflect the new architecture and added convenience scripts for Prisma operations.

This change promotes a single source of truth for data models, reduces code duplication, and improves the overall architecture by centralizing database operations within the API service.
This commit is contained in:
google-labs-jules[bot]
2025-05-30 23:40:00 +00:00
parent 4f1ec58a99
commit 242dc66983
26 changed files with 381 additions and 243 deletions

View File

@@ -13,7 +13,8 @@
"axios": "^1.9.0",
"pinia": "^3.0.2",
"vue": "^3.5.13",
"vue-router": "^4.5.1"
"vue-router": "^4.5.1",
"@empresa/prisma-schema": "1.0.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.2",

View File

@@ -43,20 +43,7 @@
<script setup lang="ts">
import { PropType } from 'vue'
import { useRouter } from 'vue-router'
// Define the structure of the employee object based on the Prisma schema
interface Employee {
id: string | number // Changed from BigInt to string | number for easier handling in frontend
name: string
cedula: number // Changed from BigInt
avatar_url?: string
telefono?: string
ubicacion: string
idciat?: string
grupo_estudio?: string
// created_at and updated_at are usually not displayed directly in a summary card
// empleado: boolean // This is implicit as it's an employee card
}
import type { Employee } from '@empresa/prisma-schema'
const props = defineProps({
employee: {

23
ui/tsconfig.json Normal file
View File

@@ -0,0 +1,23 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"jsx": "preserve",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true, // Vite handles emission
// Add Vue-specific options if not in base
"allowJs": true, // If you have JS files too
// Vite projects often use this for path aliases like @/
// The base already has baseUrl: "."
// Paths for @empresa/prisma-schema are inherited from tsconfig.base.json
"paths": {
"@/*": ["src/*"] // Local alias for UI project
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }] // Common for Vite projects
}

12
ui/tsconfig.node.json Normal file
View File

@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node",
"target": "esnext",
// Specific overrides for Node context if needed
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.js"] // Or .ts if you use TypeScript for Vite config
}