turbo lint

This commit is contained in:
Wells Bunker 2025-09-11 10:18:49 -06:00
parent 0182713788
commit 40de754f86
No known key found for this signature in database
GPG Key ID: DB16D6F2679B78FC
1 changed files with 28 additions and 25 deletions

View File

@ -7,16 +7,17 @@ import {
getUserSuggestedPrompts, getUserSuggestedPrompts,
updateUserSuggestedPrompts, updateUserSuggestedPrompts,
} from '@buster/database'; } from '@buster/database';
import { GetSuggestedPromptsRequestSchema, type GetSuggestedPromptsResponse } from '@buster/server-shared/user'; import {
GetSuggestedPromptsRequestSchema,
type GetSuggestedPromptsResponse,
} from '@buster/server-shared/user';
import { zValidator } from '@hono/zod-validator'; import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono'; import { Hono } from 'hono';
import { HTTPException } from 'hono/http-exception'; import { HTTPException } from 'hono/http-exception';
import { standardErrorHandler } from '../../../../../utils/response'; import { standardErrorHandler } from '../../../../../utils/response';
const app = new Hono().get( const app = new Hono()
'/', .get('/', zValidator('param', GetSuggestedPromptsRequestSchema), async (c) => {
zValidator('param', GetSuggestedPromptsRequestSchema),
async (c) => {
const userId = c.req.param('id'); const userId = c.req.param('id');
const authenticatedUser = c.get('busterUser'); const authenticatedUser = c.get('busterUser');
@ -27,35 +28,38 @@ const app = new Hono().get(
}); });
} }
const currentSuggestedPrompts: GetSuggestedPromptsResponse = await getUserSuggestedPrompts({ userId }); const currentSuggestedPrompts: GetSuggestedPromptsResponse = await getUserSuggestedPrompts({
userId,
});
if (currentSuggestedPrompts) { if (currentSuggestedPrompts) {
// Check if the updatedAt date is from today // Check if the updatedAt date is from today
const today = new Date(); const today = new Date();
const updatedDate = new Date(currentSuggestedPrompts.updatedAt); const updatedDate = new Date(currentSuggestedPrompts.updatedAt);
const isToday = const isToday =
today.getFullYear() === updatedDate.getFullYear() && today.getFullYear() === updatedDate.getFullYear() &&
today.getMonth() === updatedDate.getMonth() && today.getMonth() === updatedDate.getMonth() &&
today.getDate() === updatedDate.getDate(); today.getDate() === updatedDate.getDate();
if (isToday) { if (isToday) {
return c.json(currentSuggestedPrompts); return c.json(currentSuggestedPrompts);
}
} }
}
const timeoutMs = 10000; // 10 seconds timeout const timeoutMs = 10000; // 10 seconds timeout
const timeoutPromise = new Promise<never>((_, reject) => { const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(() => { setTimeout(() => {
reject( reject(new Error('Request timeout after 10 seconds. Returning current suggested prompts.'));
new Error('Request timeout after 10 seconds. Returning current suggested prompts.') }, timeoutMs);
); });
}, timeoutMs);
});
try { try {
const newPrompts: GetSuggestedPromptsResponse = await Promise.race([buildNewSuggestedPrompts(userId), timeoutPromise]); const newPrompts: GetSuggestedPromptsResponse = await Promise.race([
buildNewSuggestedPrompts(userId),
timeoutPromise,
]);
return c.json(newPrompts); return c.json(newPrompts);
} catch { } catch {
if (currentSuggestedPrompts) { if (currentSuggestedPrompts) {
@ -64,9 +68,8 @@ const app = new Hono().get(
const defaultPrompts: GetSuggestedPromptsResponse = DEFAULT_USER_SUGGESTED_PROMPTS; const defaultPrompts: GetSuggestedPromptsResponse = DEFAULT_USER_SUGGESTED_PROMPTS;
return c.json(defaultPrompts); return c.json(defaultPrompts);
} }
} })
) .onError(standardErrorHandler);
.onError(standardErrorHandler);
/** /**
* Generate new suggested prompts for a user and update the database with the new prompts * Generate new suggested prompts for a user and update the database with the new prompts