From a44f7a8253b60d0b8560b013e076e1ff10dd7423 Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 20 May 2026 14:43:39 +0200 Subject: [PATCH] Update Category model and sync service to include colorValue and iconCodePoint fields --- docs/API.md | 10 ++++++++-- src/models/Category.js | 8 ++++++++ src/services/syncService.js | 10 +++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/API.md b/docs/API.md index f8aef51..0152a36 100644 --- a/docs/API.md +++ b/docs/API.md @@ -201,9 +201,12 @@ Campos: ```json { "id": "uuid", - "encrypted_name": "texto_cifrado", + "name": "texto_cifrado", "serverVersion": 1, "isDeleted": false, + "isDirty": true, + "colorValue": 4281558681, + "iconCodePoint": 58896, "updatedAt": "2026-05-18T10:05:00.000Z" } ``` @@ -211,9 +214,12 @@ Campos: Campos: - `id`: `UUID`, obligatorio. -- `encrypted_name`: `string`, obligatorio. + - `name`: `string` (cifrado), obligatorio. Equivale a `encrypted_name`; ambos contienen el nombre encriptado. - `serverVersion`: `number` entero >= 0, obligatorio. Es la versión base local con la que se hizo el cambio. - `isDeleted`: `boolean`, opcional, por defecto `false`. +- `isDirty`: `boolean`, opcional. El servidor lo ignora en la escritura y devuelve `false` en la respuesta de sync. +- `colorValue`: `number`, opcional. +- `iconCodePoint`: `number`, opcional. - `updatedAt`: `ISO date string`, opcional (solo informativo para UI). #### Estructura de nota diff --git a/src/models/Category.js b/src/models/Category.js index eefb23b..265409f 100644 --- a/src/models/Category.js +++ b/src/models/Category.js @@ -12,6 +12,14 @@ const Category = sequelize.define('Category', { type: DataTypes.TEXT, allowNull: false }, + colorValue: { + type: DataTypes.INTEGER, + allowNull: true + }, + iconCodePoint: { + type: DataTypes.INTEGER, + allowNull: true + }, serverVersion: { type: DataTypes.INTEGER, defaultValue: 1, diff --git a/src/services/syncService.js b/src/services/syncService.js index 0c9872e..b8a0489 100644 --- a/src/services/syncService.js +++ b/src/services/syncService.js @@ -14,8 +14,11 @@ const isValidDate = (value) => { const normalizeCategory = (category) => ({ id: category.id, encrypted_name: category.encrypted_name, + colorValue: category.colorValue ?? null, + iconCodePoint: category.iconCodePoint ?? null, isDeleted: Boolean(category.isDeleted), serverVersion: category.serverVersion || 1, + isDirty: false, updatedAt: category.updatedAt instanceof Date ? category.updatedAt.toISOString() : toIso(category.updatedAt) }); @@ -72,8 +75,9 @@ class SyncService { await sequelize.transaction(async (transaction) => { for (const incomingCategory of incomingCategories) { + if (!incomingCategory.id || !incomingCategory.encrypted_name) { - throw new Error('Cada categoría debe incluir id y encrypted_name'); + throw new Error('Cada categoría debe incluir id y encrypted_name (encriptado)'); } const incomingBaseVersion = getIncomingVersion('categoría', incomingCategory); @@ -88,6 +92,8 @@ class SyncService { id: incomingCategory.id, userId, encrypted_name: incomingCategory.encrypted_name, + colorValue: incomingCategory.colorValue ?? null, + iconCodePoint: incomingCategory.iconCodePoint ?? null, isDeleted: Boolean(incomingCategory.isDeleted), serverVersion: 1 }, { transaction }); @@ -98,6 +104,8 @@ class SyncService { if (incomingBaseVersion === serverVersion) { await existingCategory.update({ encrypted_name: incomingCategory.encrypted_name, + colorValue: incomingCategory.colorValue ?? existingCategory.colorValue ?? null, + iconCodePoint: incomingCategory.iconCodePoint ?? existingCategory.iconCodePoint ?? null, isDeleted: Boolean(incomingCategory.isDeleted), serverVersion: serverVersion + 1 }, { transaction });