Update Category model and sync service to include colorValue and iconCodePoint fields
Despliegue Automático / desplegar (push) Successful in 3m37s

This commit is contained in:
2026-05-20 14:43:39 +02:00
parent 73a8932c64
commit a44f7a8253
3 changed files with 25 additions and 3 deletions
+8 -2
View File
@@ -201,9 +201,12 @@ Campos:
```json ```json
{ {
"id": "uuid", "id": "uuid",
"encrypted_name": "texto_cifrado", "name": "texto_cifrado",
"serverVersion": 1, "serverVersion": 1,
"isDeleted": false, "isDeleted": false,
"isDirty": true,
"colorValue": 4281558681,
"iconCodePoint": 58896,
"updatedAt": "2026-05-18T10:05:00.000Z" "updatedAt": "2026-05-18T10:05:00.000Z"
} }
``` ```
@@ -211,9 +214,12 @@ Campos:
Campos: Campos:
- `id`: `UUID`, obligatorio. - `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. - `serverVersion`: `number` entero >= 0, obligatorio. Es la versión base local con la que se hizo el cambio.
- `isDeleted`: `boolean`, opcional, por defecto `false`. - `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). - `updatedAt`: `ISO date string`, opcional (solo informativo para UI).
#### Estructura de nota #### Estructura de nota
+8
View File
@@ -12,6 +12,14 @@ const Category = sequelize.define('Category', {
type: DataTypes.TEXT, type: DataTypes.TEXT,
allowNull: false allowNull: false
}, },
colorValue: {
type: DataTypes.INTEGER,
allowNull: true
},
iconCodePoint: {
type: DataTypes.INTEGER,
allowNull: true
},
serverVersion: { serverVersion: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
defaultValue: 1, defaultValue: 1,
+9 -1
View File
@@ -14,8 +14,11 @@ const isValidDate = (value) => {
const normalizeCategory = (category) => ({ const normalizeCategory = (category) => ({
id: category.id, id: category.id,
encrypted_name: category.encrypted_name, encrypted_name: category.encrypted_name,
colorValue: category.colorValue ?? null,
iconCodePoint: category.iconCodePoint ?? null,
isDeleted: Boolean(category.isDeleted), isDeleted: Boolean(category.isDeleted),
serverVersion: category.serverVersion || 1, serverVersion: category.serverVersion || 1,
isDirty: false,
updatedAt: category.updatedAt instanceof Date ? category.updatedAt.toISOString() : toIso(category.updatedAt) updatedAt: category.updatedAt instanceof Date ? category.updatedAt.toISOString() : toIso(category.updatedAt)
}); });
@@ -72,8 +75,9 @@ class SyncService {
await sequelize.transaction(async (transaction) => { await sequelize.transaction(async (transaction) => {
for (const incomingCategory of incomingCategories) { for (const incomingCategory of incomingCategories) {
if (!incomingCategory.id || !incomingCategory.encrypted_name) { 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); const incomingBaseVersion = getIncomingVersion('categoría', incomingCategory);
@@ -88,6 +92,8 @@ class SyncService {
id: incomingCategory.id, id: incomingCategory.id,
userId, userId,
encrypted_name: incomingCategory.encrypted_name, encrypted_name: incomingCategory.encrypted_name,
colorValue: incomingCategory.colorValue ?? null,
iconCodePoint: incomingCategory.iconCodePoint ?? null,
isDeleted: Boolean(incomingCategory.isDeleted), isDeleted: Boolean(incomingCategory.isDeleted),
serverVersion: 1 serverVersion: 1
}, { transaction }); }, { transaction });
@@ -98,6 +104,8 @@ class SyncService {
if (incomingBaseVersion === serverVersion) { if (incomingBaseVersion === serverVersion) {
await existingCategory.update({ await existingCategory.update({
encrypted_name: incomingCategory.encrypted_name, encrypted_name: incomingCategory.encrypted_name,
colorValue: incomingCategory.colorValue ?? existingCategory.colorValue ?? null,
iconCodePoint: incomingCategory.iconCodePoint ?? existingCategory.iconCodePoint ?? null,
isDeleted: Boolean(incomingCategory.isDeleted), isDeleted: Boolean(incomingCategory.isDeleted),
serverVersion: serverVersion + 1 serverVersion: serverVersion + 1
}, { transaction }); }, { transaction });