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