feat: enhance notification handling and improve code structure across multiple components
This commit is contained in:
@@ -57,7 +57,9 @@ router.post('/values', async (req: Request, res: Response) => {
|
||||
if (listId) {
|
||||
await enqueueNotification(dbAdapter, (req as any).deviceId, 'listContentUpdated', 'value', id, listId, Date.now());
|
||||
}
|
||||
} catch {}
|
||||
} catch (notificationError) {
|
||||
void notificationError;
|
||||
}
|
||||
res.json(itemValue);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to save item value' });
|
||||
@@ -101,7 +103,9 @@ router.delete('/:id', async (req: Request, res: Response) => {
|
||||
const item = await dbAdapter.queryOne('SELECT * FROM items WHERE id = ?', [req.params.id]);
|
||||
const listId = item ? ((item as any).listId ?? (item as any).listid) : undefined;
|
||||
await enqueueNotification(dbAdapter, (req as any).deviceId, 'deleted', 'item', req.params.id, listId, updatedAt);
|
||||
} catch {}
|
||||
} catch (notificationError) {
|
||||
void notificationError;
|
||||
}
|
||||
res.json({ message: 'Item deleted successfully' });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete item' });
|
||||
|
||||
@@ -167,7 +167,9 @@ router.post('/sync', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const ev = list.isDeleted ? 'deleted' : (safeLastSyncTimestamp === 0 ? 'created' : 'updated');
|
||||
await enqueueNotification(tx, deviceId, ev, 'list', list.id, list.id, listTs.updatedAt);
|
||||
} catch {}
|
||||
} catch (notificationError) {
|
||||
void notificationError;
|
||||
}
|
||||
// If a list was deleted, cascade the deletion to child records on server
|
||||
// - mark fields and items as deleted (tombstones) so other clients learn about them
|
||||
// - remove item_values belonging to items under this list (no tombstone support for values)
|
||||
@@ -201,7 +203,9 @@ router.post('/sync', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const ev = field.isDeleted ? 'deleted' : (safeLastSyncTimestamp === 0 ? 'created' : 'updated');
|
||||
await enqueueNotification(tx, deviceId, ev, 'field', field.id, field.listId, fieldTs.updatedAt);
|
||||
} catch {}
|
||||
} catch (notificationError) {
|
||||
void notificationError;
|
||||
}
|
||||
if (field.isDeleted) {
|
||||
// Remove item_values for this field
|
||||
try {
|
||||
@@ -239,7 +243,9 @@ router.post('/sync', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const ev = item.isDeleted ? 'deleted' : (safeLastSyncTimestamp === 0 ? 'created' : 'updated');
|
||||
await enqueueNotification(tx, deviceId, ev, 'item', item.id, item.listId, itemTs.updatedAt);
|
||||
} catch {}
|
||||
} catch (notificationError) {
|
||||
void notificationError;
|
||||
}
|
||||
// If an item was deleted, remove its values (no tombstone support for values)
|
||||
if (item.isDeleted) {
|
||||
try {
|
||||
@@ -324,7 +330,9 @@ router.post('/sync', async (req: Request, res: Response) => {
|
||||
if (lId) {
|
||||
await enqueueNotification(tx, deviceId, 'listContentUpdated', 'value', value.id, lId, valueUpdatedAt);
|
||||
}
|
||||
} catch {}
|
||||
} catch (notificationError) {
|
||||
void notificationError;
|
||||
}
|
||||
} catch (err: any) {
|
||||
// Catch FK violation just in case race or deletion happened inside same sync
|
||||
if (err && err.code === '23503') {
|
||||
|
||||
Reference in New Issue
Block a user