mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
Fix saving session finished time, display session locale (#213)
- Show session locale - Remove command counts on session list for performance
This commit is contained in:
5 files changed
+35
-30
No files matched your search
@@ -97,6 +97,7 @@ export async function finishSession(
|
||||
session: HydratedDocument<ISession>
|
||||
): Promise<void> {
|
||||
session.status = 'finished'
|
||||
session.finishedAt = new Date()
|
||||
await session.save()
|
||||
|
||||
const userProfile = await UserProfile.findOne({ user: session.user })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Types } from 'mongoose'
|
||||
|
||||
export interface User {
|
||||
_id: string
|
||||
username: string
|
||||
}
|
||||
export interface SessionDocument {
|
||||
@@ -8,8 +9,10 @@ export interface SessionDocument {
|
||||
user: User
|
||||
quest: string
|
||||
status: string
|
||||
locale: string
|
||||
createdAt: Date
|
||||
finishedAt: Date
|
||||
lastActivityAt: Date
|
||||
}
|
||||
export interface CommandObject {
|
||||
command: string
|
||||
@@ -21,24 +24,17 @@ export interface CommandObject {
|
||||
}
|
||||
export interface SessionObject {
|
||||
_id: Types.ObjectId
|
||||
user: string
|
||||
user: User
|
||||
quest: string
|
||||
locale: string
|
||||
status: string
|
||||
createdAt: string
|
||||
finishedAt: string
|
||||
lastActivityAt: string
|
||||
usedTime: string
|
||||
commandCount: number
|
||||
commands: CommandObject[]
|
||||
}
|
||||
export interface SessionDetail {
|
||||
_id: Types.ObjectId
|
||||
user: string
|
||||
quest: string
|
||||
status: string
|
||||
createdAt: string
|
||||
finishedAt: string
|
||||
usedTime: string
|
||||
export interface SessionDetail extends SessionObject {
|
||||
commands: CommandObject[]
|
||||
}
|
||||
export interface IUser extends Document {
|
||||
|
||||
@@ -28,14 +28,6 @@ export async function sessionList(
|
||||
},
|
||||
},
|
||||
{ $unwind: '$user' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'commands',
|
||||
localField: '_id',
|
||||
foreignField: 'session',
|
||||
as: 'commands',
|
||||
},
|
||||
},
|
||||
pagination.sort('_id'),
|
||||
pagination.limit(),
|
||||
])
|
||||
@@ -45,16 +37,17 @@ export async function sessionList(
|
||||
_id,
|
||||
user,
|
||||
quest,
|
||||
locale,
|
||||
status,
|
||||
createdAt,
|
||||
finishedAt,
|
||||
commands,
|
||||
lastActivityAt,
|
||||
} = session
|
||||
return {
|
||||
_id,
|
||||
user: user.username, // Assuming `user` is always populated.
|
||||
user: { _id: user._id, username: user.username },
|
||||
quest,
|
||||
locale: locale ?? 'zh-TW',
|
||||
status,
|
||||
createdAt: createdAt?.toLocaleString(),
|
||||
finishedAt: finishedAt?.toLocaleString(),
|
||||
@@ -63,8 +56,7 @@ export async function sessionList(
|
||||
lastActivityAt && createdAt
|
||||
? formatTime(lastActivityAt.getTime() - createdAt.getTime())
|
||||
: 'N/A', // Ensure both dates are present
|
||||
commandCount: commands?.length || 0,
|
||||
commands,
|
||||
commandCount: 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -83,14 +75,26 @@ export async function sessionDetail(id: string): Promise<SessionDetail> {
|
||||
createdAt: createdAt?.toLocaleString(),
|
||||
})
|
||||
)
|
||||
const { _id, user, quest, status, createdAt, finishedAt } = session
|
||||
const {
|
||||
_id,
|
||||
user,
|
||||
quest,
|
||||
locale,
|
||||
status,
|
||||
createdAt,
|
||||
finishedAt,
|
||||
lastActivityAt,
|
||||
} = session
|
||||
return {
|
||||
_id,
|
||||
user: user.username,
|
||||
user: { _id: user._id, username: user.username },
|
||||
quest,
|
||||
locale: locale ?? 'zh-TW',
|
||||
status,
|
||||
createdAt: createdAt?.toLocaleString(),
|
||||
finishedAt: finishedAt?.toLocaleString(),
|
||||
lastActivityAt: lastActivityAt?.toLocaleDateString(),
|
||||
commandCount: commands.length,
|
||||
usedTime: finishedAt
|
||||
? formatTime(finishedAt.getTime() - createdAt.getTime())
|
||||
: '',
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
<th>Quest</th>
|
||||
<td>{{quest}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Locale</th>
|
||||
<td>{{locale}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<td>{{user}}</td>
|
||||
<td><a href="/users/{{user._id}}">{{user.username}}</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
@@ -55,4 +59,4 @@
|
||||
{{/each}}
|
||||
</table>
|
||||
|
||||
</div>{{/with}}
|
||||
</div>{{/with}}
|
||||
@@ -12,22 +12,22 @@
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Quest</th>
|
||||
<th>Locale</th>
|
||||
<th>Status</th>
|
||||
<th>Created At</th>
|
||||
<th>Finished At</th>
|
||||
<th>Used Time</th>
|
||||
<th>Command Count</th>
|
||||
<th>Session</th>
|
||||
</tr>
|
||||
{{#each sessions}}
|
||||
<tr>
|
||||
<td>{{user}}</td>
|
||||
<td><a href="/users/{{user._id}}">{{user.username}}</a></td>
|
||||
<td>{{quest}}</td>
|
||||
<td>{{locale}}</td>
|
||||
<td>{{status}}</td>
|
||||
<td>{{createdAt}}</td>
|
||||
<td>{{finishedAt}}</td>
|
||||
<td>{{usedTime}}</td>
|
||||
<td>{{commandCount}}</td>
|
||||
<td><a href='/sessions/{{_id}}'>Detail</a></td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
@@ -37,4 +37,4 @@
|
||||
<a href='/sessions?nextKey={{nextKey}}&order={{order}}'><div class='btn'>
|
||||
<h3>Next</h3>
|
||||
</div></a>
|
||||
</div>
|
||||
</div>
|
||||
Reference in new issue
Block a user