generated from template/router-template
update
This commit is contained in:
@@ -11,7 +11,8 @@ app.route({
|
||||
}).define(async (ctx) => {
|
||||
const force = ctx.query.force ?? false;
|
||||
const db = getDb();
|
||||
const day = getTodayDate();
|
||||
const today = ctx.query?.date;
|
||||
const day = today || getTodayDate();
|
||||
if (force) {
|
||||
const existingQuestion = await db
|
||||
.select()
|
||||
|
||||
@@ -12,7 +12,7 @@ app.route({
|
||||
}).define(async (ctx) => {
|
||||
const query = ctx.query;
|
||||
const page = query.page ?? 1;
|
||||
const pageSize = query.pageSize ?? 10;
|
||||
const pageSize = query.pageSize ?? 99999;
|
||||
const db = getDb();
|
||||
try {
|
||||
const offset = (page - 1) * pageSize;
|
||||
@@ -153,31 +153,3 @@ app.route({
|
||||
ctx.throw(500, '获取数据详情失败');
|
||||
}
|
||||
}).addTo(app);
|
||||
|
||||
// 获取今日问题
|
||||
app.route({
|
||||
description: '获取今日问题',
|
||||
path: 'daily',
|
||||
key: 'today'
|
||||
}).define(async (ctx) => {
|
||||
const db = getDb();
|
||||
try {
|
||||
const allResults = await db.select().from(dailyQuestions);
|
||||
|
||||
// Sort by createdAt in descending order (newest first)
|
||||
const sortedResults = allResults.sort((a, b) =>
|
||||
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
||||
);
|
||||
|
||||
const result = sortedResults.slice(0, 1);
|
||||
|
||||
if (result.length === 0) {
|
||||
ctx.throw(404, '暂无今日问题');
|
||||
}
|
||||
|
||||
ctx.body = result[0];
|
||||
} catch (error) {
|
||||
console.error('获取今日问题失败:', error);
|
||||
ctx.throw(500, '获取今日问题失败');
|
||||
}
|
||||
}).addTo(app);
|
||||
@@ -12,7 +12,7 @@ app.route({
|
||||
}).define(async (ctx) => {
|
||||
const query = ctx.query;
|
||||
const page = query.page ?? 1;
|
||||
const pageSize = query.pageSize ?? 10;
|
||||
const pageSize = query.pageSize ?? 99999;
|
||||
const db = getDb();
|
||||
try {
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
Reference in New Issue
Block a user