Implement node reactions sync

This commit is contained in:
Hakan Shehu
2024-09-26 09:34:27 +02:00
parent 16cc7bd9a9
commit 38bbc9707b
4 changed files with 57 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
import { NeuronRequest, NeuronResponse } from '@/types/api';
import { database } from '@/data/database';
import { Router } from 'express';
import { ServerNode } from '@/types/nodes';
import { ServerNode, ServerNodeReaction } from '@/types/nodes';
export const syncRouter = Router();
@@ -15,6 +15,12 @@ syncRouter.get(
.where('workspace_id', '=', workspaceId)
.execute();
const nodeReactionRows = await database
.selectFrom('node_reactions')
.selectAll()
.where('workspace_id', '=', workspaceId)
.execute();
const nodes: ServerNode[] = nodeRows.map((node) => {
return {
id: node.id,
@@ -34,8 +40,22 @@ syncRouter.get(
};
});
const nodeReactions: ServerNodeReaction[] = nodeReactionRows.map(
(nodeReaction) => {
return {
nodeId: nodeReaction.node_id,
reactorId: nodeReaction.reactor_id,
reaction: nodeReaction.reaction,
workspaceId: nodeReaction.workspace_id,
createdAt: nodeReaction.created_at.toISOString(),
serverCreatedAt: nodeReaction.server_created_at.toISOString(),
};
},
);
res.status(200).json({
nodes,
nodeReactions,
});
},
);