mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +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)
|
const session = await Session.findById(sessionId)
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
res.status(401).json({ message: 'session not found' })
|
res.status(404).json({ message: 'session not found' })
|
||||||
return
|
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({
|
const c = new Command({
|
||||||
session,
|
session,
|
||||||
command,
|
command,
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ async function commandHandler(session, commandInput, additionalData) {
|
|||||||
session.progress = stage.next
|
session.progress = stage.next
|
||||||
await session.save()
|
await session.save()
|
||||||
|
|
||||||
|
if (stage.next === 'END') {
|
||||||
|
session.status = 'finished'
|
||||||
|
session.finishedAt = new Date()
|
||||||
|
await session.save()
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
responses: stage.responses,
|
responses: stage.responses,
|
||||||
hints: stage.hints,
|
hints: stage.hints,
|
||||||
|
|||||||
@@ -13,7 +13,18 @@ const Session = model(
|
|||||||
ref: 'Quest',
|
ref: 'Quest',
|
||||||
},
|
},
|
||||||
containerId: String,
|
containerId: String,
|
||||||
|
status: {
|
||||||
|
type: String,
|
||||||
|
enum: ['active', 'finished', 'deactive'],
|
||||||
|
required: true,
|
||||||
|
default: 'active',
|
||||||
|
},
|
||||||
finishedAt: Date,
|
finishedAt: Date,
|
||||||
|
lastActivityAt: {
|
||||||
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
progress: String,
|
progress: String,
|
||||||
completion: [String],
|
completion: [String],
|
||||||
hints: [String],
|
hints: [String],
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ paths:
|
|||||||
description: find sessions by quest id
|
description: find sessions by quest id
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
|
- in: query
|
||||||
|
name: status
|
||||||
|
description: find sessions by status
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
enum: [active, finished, deactive]
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: list of existing session
|
description: list of existing session
|
||||||
|
|||||||
Reference in new issue
Block a user