Fix attributes parsing for interactions

This commit is contained in:
Hakan Shehu
2024-11-30 22:23:48 +01:00
parent 5342e0e203
commit 7e11694c65
3 changed files with 7 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ interface InteractionTable {
user_id: ColumnType<string, string, never>;
node_id: ColumnType<string, string, never>;
node_type: ColumnType<NodeType, NodeType, never>;
attributes: ColumnType<InteractionAttributes, string, string>;
attributes: ColumnType<string, string, string>;
last_seen_at: ColumnType<string | null, string | null, string | null>;
created_at: ColumnType<string, string, never>;
updated_at: ColumnType<string | null, string | null, string | null>;

View File

@@ -60,8 +60,12 @@ class InteractionService {
.where('node_id', '=', nodeId)
.executeTakeFirst();
const existingAttributes = interaction?.attributes
? JSON.parse(interaction.attributes)
: null;
const attributes = mergeInteractionAttributes(
interaction?.attributes,
existingAttributes,
attribute,
value
);

View File

@@ -217,7 +217,7 @@ export const mapInteraction = (row: SelectInteraction): Interaction => {
return {
nodeId: row.node_id,
userId: row.user_id,
attributes: row.attributes,
attributes: JSON.parse(row.attributes),
createdAt: new Date(row.created_at),
updatedAt: row.updated_at ? new Date(row.updated_at) : null,
serverCreatedAt: row.server_created_at