fix: removed testing code in sessionjs

This commit is contained in:
Rushil Umaretiya 2023-03-04 21:14:01 -05:00
parent 2476824c33
commit c6219e6e6e

View File

@ -5,71 +5,64 @@ export const createSession = async (callId, callerPhone) => {
return await db.session.create({ return await db.session.create({
data: { data: {
callId: callId, callId: callId,
callerPhone: callerPhone callerPhone: callerPhone,
} },
}) });
} };
export const findSessionByCallId = async (callId) => { export const findSessionByCallId = async (callId) => {
return await db.session.findUnique({ return await db.session.findUnique({
where: { where: {
callId: callId callId: callId,
} },
}) });
} };
export const transferSession = async (callId, operatorPhone) => { export const transferSession = async (callId, operatorPhone) => {
return await db.session.update({ return await db.session.update({
where: { where: {
callId: callId callId: callId,
}, },
data: { data: {
transferedAt: new Date(), transferedAt: new Date(),
operatorPhone: operatorPhone operatorPhone: operatorPhone,
} },
}) });
} };
export const endSession = async (callId) => { export const endSession = async (callId) => {
return await db.session.update({ return await db.session.update({
where: { where: {
callId: callId callId: callId,
}, },
data: { data: {
endedAt: new Date() endedAt: new Date(),
} },
}) });
} };
export const addMessage = async (callId, role, content) => { export const addMessage = async (callId, role, content) => {
const session = await findSessionByCallId(callId) const session = await findSessionByCallId(callId);
return await db.message.create({ return await db.message.create({
data: { data: {
sessionId: session.id, sessionId: session.id,
role: role, role: role,
content: content content: content,
} },
}) });
} };
export const getMessages = async (callId) => { export const getMessages = async (callId) => {
return await db.message.findMany({ return await db.message.findMany({
where: { where: {
session: { session: {
callId: callId callId: callId,
} },
}, },
orderBy: [ orderBy: [
{ {
createdAt: 'asc' createdAt: "asc",
} },
] ],
}) });
} };
// const main = async () => {
// // await addMessage("ofijse", Role.USER, "wefoij")
// console.log(await getMessages("ofijse"))
// }
// main()