Update Category model and sync service to include colorValue and iconCodePoint fields
Despliegue Automático / desplegar (push) Successful in 3m37s
Despliegue Automático / desplegar (push) Successful in 3m37s
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user