Skip to content

Commit

Permalink
added conversation ID in get history
Browse files Browse the repository at this point in the history
  • Loading branch information
TottySnowman committed Oct 28, 2023
1 parent c4cf1ed commit 2b80180
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions backend/src/controllers/index.ts
Expand Up @@ -75,23 +75,26 @@ app.post("/history", async (req: Request, res: Response) => {
const driver = await createDriver();

const session = driver.session();

const createdUserHistoryRel = await session.run(
"MATCH (u:User {surname : 'Doe'}) CREATE (h:History {createdAt: localdatetime()}) SET h += $history CREATE (u)-[:HAS_HISTORY]->(h)",
{ history: data }
);

return res.json(createdUserHistoryRel)
try {
const createdUserHistoryRel = await session.run(
"MATCH (u:User where ID(u) = $userID) CREATE (h:History {createdAt: localdatetime()}) SET h += $history CREATE (u)-[:HAS_HISTORY]->(h)",
{ history: data, userID: Number(userID) }
);
return res.status(200).json({
response: "Inserted into history",
});
} catch (error) {
return res.status(500).json({ response: "Failed to insert into history!" });
}
});

app.get("/history", async (req: Request, res: Response) => {
const { userID } = req.query;
const driver = await createDriver();
const session = driver.session();
console.log(userID);

const { records } = await session.run(
"MATCH (p:User where ID(p) = $userIDDB)-[r:HAS_HISTORY]->(h:History) return h",
"MATCH (p:User where ID(p) = $userIDDB)-[r:HAS_HISTORY]->(h:History) return h, ID(h) as conversationID",
{ userIDDB: Number(userID) }
);

Expand All @@ -101,9 +104,10 @@ app.get("/history", async (req: Request, res: Response) => {

const attributes = records.map((record) => {
const data = record.get("h");

return {
conversation_id: record.get("conversationID").toInt(),
title: data.properties.title,
description_uri: data.properties.description_uri,
language: data.properties.language,
};
});
Expand Down

0 comments on commit 2b80180

Please sign in to comment.