Overview
EntityManager provides universal create, read, update, and delete operations for all entity types in the SGD-MCS system. It handles automatic ID generation, Drive folder creation, and audit logging. Source:~/workspace/source/Backend/core/EntityManager.js
createItem
Creates a new entity record and optionally its Drive folder.Entity type:
estudiante, docente, externo, evento, or tesisEntity data object with fields matching the Google Sheet columns
Common Fields by Entity Type
Common Fields by Entity Type
Estudiante (Student)
Nombre1,Nombre2: First and middle namesApellido1,Apellido2: Last namesCedula: ID numberEmail: Email addressCohorte_Ingreso: Cohort (e.g., “2024-1”)Estado: Status
Nombre1,Apellido1: NameCedula: ID numberEmail: Email addressEspecialidad: Specialty area
Titulo_Investigacion: Research titleAño: YearID_Estudiante: Associated student IDCalificacion: Grade
Nombre_Evento: Event nameFecha: DateTipo: Event type
Nombre1,Apellido1: NameEmail: Email addressInstitucion: Institution
Set to
false to skip automatic Drive folder creationWhether the operation succeeded
Result message (“Creado correctamente” or error)
Auto-generated entity ID (e.g., “EST0001”)
Example
Automatic Features:
- ID generation using prefix + counter (EST0001, DOC0042, etc.)
- Drive folder created at:
Root/[EntityType]/[Year or Cohort]/[ID - Name] - Audit fields populated:
Fecha_Registro,Usuario_Registro - All actions logged to audit trail
updateItem
Updates an existing entity record.Entity type:
estudiante, docente, externo, evento, or tesisEntity ID to update (e.g., “EST0001”)
Object containing only the fields to update
Whether the operation succeeded
Result message (“Actualizado correctamente” or error)
Example
Automatic Updates:
Ultima_Actualizaciontimestamp updated automaticallyUltimo_Usuarioset to current user’s email- If entity has no Drive folder,
syncEntityFolder()is called automatically - All updates logged to audit trail
deleteItem
Deletes an entity record and moves its Drive folder to trash.Entity type:
estudiante, docente, externo, evento, or tesisEntity ID to delete (e.g., “EST0001”)
Whether the operation succeeded
Result message (“Eliminado correctamente” or “ID no encontrado”)
Example
bulkUpdateItems
Updates multiple entities at once with the same data.Entity type:
estudiante, docente, externo, evento, or tesisArray of entity IDs to update
Object containing fields to update on all entities
Always returns
trueCount of successfully updated records
Example
bulkDeleteItems
Deletes multiple entities at once.Entity type:
estudiante, docente, externo, evento, or tesisArray of entity IDs to delete
Always returns
trueCount of successfully deleted records
Example
Implementation Details
ID Generation
FromEntityManager.js:26-34:
- IDs use 3-letter prefix + zero-padded counter
- Counter stored in Config sheet:
Siguiente_ID_[EntityType] - Format:
EST0001,DOC0042,TES0123, etc. - IDs are unique per entity type
Drive Folder Naming
FromEntityManager.js:114-118:
- Format:
[ID] - [Name](e.g., “EST0001 - Juan Pérez”) - Truncated to 100 characters maximum
- Uses
Titulo_Investigacionfor thesis,Nombre_Eventofor events
Data Normalization
ThenormalizeData() function ensures consistent data formats before saving to Sheets.
Error Handling
All functions are wrapped in try-catch blocks. Common errors:- “Tipo no válido”: Invalid entity type parameter
- “Hoja [name] no encontrada”: Sheet not found in database
- “ID no encontrado”: Entity ID doesn’t exist
- Error string: Other exceptions (permissions, Drive errors, etc.)