mirror of
https://github.com/vitalityAI/therapist.git
synced 2025-04-08 05:40:17 -04:00
Merge branch 'main' of https://github.com/vitalityAI/therapist
This commit is contained in:
commit
70b9f22063
|
@ -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
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const authorize = async (req, res) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const authorized = webSession != null
|
const authorized = webSession != null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authorized,
|
authorized,
|
||||||
webSession
|
webSession
|
||||||
|
|
Loading…
Reference in New Issue
Block a user