This commit is contained in:
Claeb101 2023-03-05 06:21:20 -05:00
parent 2e45af7587
commit 5b327dd4ee
2 changed files with 13 additions and 20 deletions

View File

@ -10,23 +10,16 @@ const app = Router();
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
const b = req.query.open const b = req.query.open
let sessions = []; let sessions = await db.session.findMany({
orderBy: {
startedAt: 'asc'
}
});
if (b == "true") { if (b == "true") {
sessions = await db.session.findMany({ sessions = sessions.filter(session => {
where: { return !session.transferedAt && !session.endedAt
operator: undefined
}
}) })
} else if(b == "false") {
sessions = await db.session.findMany({
where: {
none: {
operator: undefined
}
}
})
} else {
sessions = await db.session.findMany()
} }
return res.status(200).json({ return res.status(200).json({
@ -35,21 +28,21 @@ app.get('/', async (req, res) => {
}) })
app.get("/message", async (req, res) => { app.get("/message", async (req, res) => {
const messages = await getMessagesBySession(req.body.sessionId) const messages = await getMessagesBySession(req.query.sessionId)
return res.status(200).json({ return res.status(200).json({
messages messages
}) })
}) })
app.get("/summary", async (req, res) => { app.get("/summary", async (req, res) => {
const summary = await summarize(req.body.sessionId) const summary = await summarize(req.query.sessionId)
return res.status(200).json({ return res.status(200).json({
summary summary
}) })
}) })
app.get('/transfer', async (req, res) => { app.get('/transfer', async (req, res) => {
const {authorized, webSession} = authorize(req, res) const {authorized, webSession} = await authorize(req, res)
if(!authorized) return res.status(401).send(null) if(!authorized) return res.status(401).send(null)
const operator = await db.operator.findUnique({ const operator = await db.operator.findUnique({
@ -57,7 +50,7 @@ app.get('/transfer', async (req, res) => {
}) })
const session = await db.session.update({ const session = await db.session.update({
where: { where: {
id: req.body.sessionId id: req.query.sessionId
}, },
data: { data: {
operatorPhone: operator.phoneNumber operatorPhone: operator.phoneNumber

View File

@ -16,7 +16,7 @@ export const authorize = async (req, res) => {
}) })
const authorized = webSession != null const authorized = webSession != null
return { return {
authorized, authorized,
webSession webSession