| name | sync-types |
| description | Sincronización de tipos entre backend y frontend. Mapeo de modelos a interfaces. Trigger: Cuando se modifica un modelo del backend o se necesita sincronizar tipos con la app.
|
| license | MIT |
| metadata | {"author":"myquota","version":"1.0","auto_invoke":["Modifying backend models","Syncing types with frontend","Adding fields to entities"]} |
Propósito
Mantener sincronizados los tipos entre myquota-backend y myquota-app cuando se modifican entidades.
Mapeo de Tipos
Modelo Backend (src/modules/*/model.ts) | Tipo Frontend (myquota-app/src/shared/types/) |
|---|
CreditCard | creditCard.ts → CreditCard |
Transaction | transaction.ts → Transaction |
Quota | quota.ts → Quota |
BillingPeriod | billingPeriod.ts → BillingPeriod |
User | user.ts → UserInfo |
Category | category.ts → Category |
Regla Principal
Cuando se agrega, renombra o elimina un campo en una entidad del backend,
TAMBIÉN se debe actualizar la interface correspondiente en myquota-app/src/shared/types/.
Ejemplo: Agregar Campo
1. Backend: Modificar modelo
export class CreditCard implements IBaseEntity {
id!: string;
createdAt!: Date;
updatedAt!: Date;
deletedAt?: Date | null;
name!: string;
lastFourDigits!: string;
color!: string;
newField!: string;
}
2. Frontend: Actualizar interface
export interface CreditCard {
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
name: string;
lastFourDigits: string;
color: string;
newField: string;
}
Diferencias Backend ↔ Frontend
| Aspecto | Backend | Frontend |
|---|
| Sintaxis | class con !: | interface |
| Fechas | Date | string (ISO 8601) |
| IBaseEntity | implements IBaseEntity | Copiar campos directamente |
| Campos opcionales | ?: Type | null | ?: Type | null |
Conversión de Fechas
createdAt!: Date;
createdAt: string;
La API serializa Date a ISO strings, por lo que el frontend siempre recibe strings.
Checklist al Modificar Modelos
Estructura IBaseEntity
Todos los modelos del backend implementan IBaseEntity:
export interface IBaseEntity {
id: string;
createdAt: Date;
updatedAt: Date;
deletedAt?: Date | null;
}
En frontend, estos campos se incluyen directamente:
export interface SomeEntity {
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
}
Anti-patterns
createdAt: Date;
Rutas de Archivos
Backend
myquota-backend/src/modules/
├── creditCard/creditCard.model.ts
├── transaction/transaction.model.ts
├── quota/quota.model.ts
├── billingPeriod/billingPeriod.model.ts
├── user/user.model.ts
└── category/category.model.ts
Frontend
myquota-app/src/shared/types/
├── creditCard.ts
├── transaction.ts
├── quota.ts
├── billingPeriod.ts
├── user.ts
└── category.ts