From 7b3a5562f23c6b71b2ca95ba9e27a71f0ea3280f Mon Sep 17 00:00:00 2001 From: Ravi Gairola Date: Mon, 4 Dec 2023 17:27:23 -0800 Subject: [PATCH] Clean up & first implementation running with OpenAI --- resolvers.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/resolvers.js b/resolvers.js index e030d3a..b6d1614 100644 --- a/resolvers.js +++ b/resolvers.js @@ -28,10 +28,15 @@ const Query = { }, history: (parent, args, context) => { context.api.log.trace('GraphQL Received Request for History', args) - if (!args.target) return context.api.comms.history.all() - const sourceHistory = context.api.comms.history.bySource(args.source) - const targetHistory = context.api.comms.history.byTarget(args.target) - return [...sourceHistory, ...targetHistory] + let messages + if (!args.source && !args.target) { + messages = context.api.comms.history.all() + } else { + const sourceHistory = context.api.comms.history.bySource(args.source) + const targetHistory = context.api.comms.history.byTarget(args.target) + messages = [...sourceHistory, ...targetHistory] + } + return messages .sort((a, b) => a.timestamp - b.timestamp) .map((msg) => msg.toObject()) }