|
|
@@ -327,10 +327,11 @@ export function createUserRoutes(withAuth: WithAuth) {
|
|
|
}
|
|
|
|
|
|
const apiClient = c.get('apiClient')
|
|
|
- const body = await c.req.json()
|
|
|
+ const body = await c.req.json().catch(() => {});
|
|
|
|
|
|
// 验证必填字段
|
|
|
const { expiresAt } = body
|
|
|
+
|
|
|
if (!expiresAt) {
|
|
|
return c.json({ error: '缺少有效期参数' }, 400)
|
|
|
}
|
|
|
@@ -353,14 +354,14 @@ export function createUserRoutes(withAuth: WithAuth) {
|
|
|
.where('id', id)
|
|
|
.update({
|
|
|
role: 'student',
|
|
|
- student_expires_at: expiresAt,
|
|
|
- updated_at: new Date()
|
|
|
+ valid_until: expiresAt,
|
|
|
+ updated_at: apiClient.database.fn.now()
|
|
|
})
|
|
|
|
|
|
const updatedUser = await apiClient.database.table('users')
|
|
|
.where('id', id)
|
|
|
- .select('id', 'username', 'nickname', 'role', 'student_expires_at')
|
|
|
- .first()
|
|
|
+ .select('id', 'username', 'nickname', 'role', 'valid_until')
|
|
|
+ .first()
|
|
|
|
|
|
return c.json({
|
|
|
data: updatedUser,
|