From c6219e6e6e2512d4dc894c13aea08b96c9ea9da2 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sat, 4 Mar 2023 21:14:01 -0500 Subject: [PATCH] fix: removed testing code in sessionjs --- src/session.js | 67 ++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/src/session.js b/src/session.js index 5fe4256..11c1c61 100644 --- a/src/session.js +++ b/src/session.js @@ -5,71 +5,64 @@ export const createSession = async (callId, callerPhone) => { return await db.session.create({ data: { callId: callId, - callerPhone: callerPhone - } - }) -} + callerPhone: callerPhone, + }, + }); +}; export const findSessionByCallId = async (callId) => { return await db.session.findUnique({ where: { - callId: callId - } - }) -} + callId: callId, + }, + }); +}; export const transferSession = async (callId, operatorPhone) => { return await db.session.update({ where: { - callId: callId + callId: callId, }, data: { transferedAt: new Date(), - operatorPhone: operatorPhone - } - }) -} + operatorPhone: operatorPhone, + }, + }); +}; export const endSession = async (callId) => { return await db.session.update({ where: { - callId: callId + callId: callId, }, data: { - endedAt: new Date() - } - }) -} + endedAt: new Date(), + }, + }); +}; export const addMessage = async (callId, role, content) => { - const session = await findSessionByCallId(callId) + const session = await findSessionByCallId(callId); return await db.message.create({ data: { sessionId: session.id, role: role, - content: content - } - }) -} + content: content, + }, + }); +}; export const getMessages = async (callId) => { return await db.message.findMany({ where: { session: { - callId: callId - } + callId: callId, + }, }, orderBy: [ { - createdAt: 'asc' - } - ] - }) -} - -// const main = async () => { -// // await addMessage("ofijse", Role.USER, "wefoij") -// console.log(await getMessages("ofijse")) -// } - -// main() + createdAt: "asc", + }, + ], + }); +};