mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add status, lastActivityAt column to session
This commit is contained in:
1 parent
bdb979e608
commit
2c866d2e83
4 files changed
+32
-1
No files matched your search
@@ -26,10 +26,18 @@ export async function newCommand(req, res) {
|
||||
const session = await Session.findById(sessionId)
|
||||
|
||||
if (!session) {
|
||||
res.status(401).json({ message: 'session not found' })
|
||||
res.status(404).json({ message: 'session not found' })
|
||||
return
|
||||
}
|
||||
|
||||
if (session.status !== 'active') {
|
||||
res.status(400).json({ message: 'session is not active' })
|
||||
return
|
||||
}
|
||||
|
||||
session.lastActivityAt = new Date()
|
||||
await session.save()
|
||||
|
||||
const c = new Command({
|
||||
session,
|
||||
command,
|
||||
|
||||
@@ -42,6 +42,12 @@ async function commandHandler(session, commandInput, additionalData) {
|
||||
session.progress = stage.next
|
||||
await session.save()
|
||||
|
||||
if (stage.next === 'END') {
|
||||
session.status = 'finished'
|
||||
session.finishedAt = new Date()
|
||||
await session.save()
|
||||
}
|
||||
|
||||
return {
|
||||
responses: stage.responses,
|
||||
hints: stage.hints,
|
||||
|
||||
@@ -13,7 +13,18 @@ const Session = model(
|
||||
ref: 'Quest',
|
||||
},
|
||||
containerId: String,
|
||||
status: {
|
||||
type: String,
|
||||
enum: ['active', 'finished', 'deactive'],
|
||||
required: true,
|
||||
default: 'active',
|
||||
},
|
||||
finishedAt: Date,
|
||||
lastActivityAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
required: true,
|
||||
},
|
||||
progress: String,
|
||||
completion: [String],
|
||||
hints: [String],
|
||||
|
||||
@@ -31,6 +31,12 @@ paths:
|
||||
description: find sessions by quest id
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: status
|
||||
description: find sessions by status
|
||||
schema:
|
||||
type: string
|
||||
enum: [active, finished, deactive]
|
||||
responses:
|
||||
'200':
|
||||
description: list of existing session
|
||||
|
||||
Reference in new issue
Block a user