feat: add status, lastActivityAt column to session

This commit is contained in:
wancat committed 2023-08-23 11:50:49 +08:00
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,
+6
View File
@@ -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,
+11
View File
@@ -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],