notification system implemented
need refinements
This commit is contained in:
1 parent
612259f020
commit
1143f8ca02
33 files changed
+2221
-222
No files matched your search
@@ -15,18 +15,27 @@ export async function POST(req: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
log.debug("Generating recommendation for user", {
|
||||
userId,
|
||||
modelProvider,
|
||||
useExternalModel,
|
||||
});
|
||||
|
||||
const db = await getDatabase();
|
||||
|
||||
// Fetch fitness profile
|
||||
const profile = await db.getFitnessProfileByUserId(userId);
|
||||
|
||||
if (!profile) {
|
||||
log.error("Fitness profile not found", undefined, { userId });
|
||||
return NextResponse.json(
|
||||
{ error: "Fitness profile not found for this user" },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
|
||||
log.debug("Fitness profile found", { profileId: profile.id });
|
||||
|
||||
// Build AI context with goals and recommendations
|
||||
let prompt: string;
|
||||
try {
|
||||
@@ -270,21 +279,45 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
// Save to database
|
||||
log.debug("Saving recommendation to database", {
|
||||
userId,
|
||||
profileId: profile.id,
|
||||
hasRecommendationText: !!parsedResponse.recommendationText,
|
||||
hasActivityPlan: !!parsedResponse.activityPlan,
|
||||
hasDietPlan: !!parsedResponse.dietPlan,
|
||||
});
|
||||
|
||||
const recommendation = await db.createRecommendation({
|
||||
id: crypto.randomUUID(),
|
||||
userId,
|
||||
fitnessProfileId: profile.id,
|
||||
recommendationText: parsedResponse.recommendationText,
|
||||
activityPlan: parsedResponse.activityPlan,
|
||||
dietPlan: parsedResponse.dietPlan,
|
||||
recommendationText: parsedResponse.recommendationText || "",
|
||||
activityPlan: parsedResponse.activityPlan || "",
|
||||
dietPlan: parsedResponse.dietPlan || "",
|
||||
status: "pending",
|
||||
generatedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
return NextResponse.json(recommendation);
|
||||
log.info("Recommendation generated successfully", {
|
||||
recommendationId: recommendation.id,
|
||||
userId,
|
||||
});
|
||||
|
||||
// Return in standardized format
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: recommendation,
|
||||
meta: {
|
||||
timestamp: new Date().toISOString(),
|
||||
requestId: `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
log.error("Failed to generate recommendation", error);
|
||||
log.error("Failed to generate recommendation", error, {
|
||||
errorMessage: error instanceof Error ? error.message : String(error),
|
||||
errorStack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
return NextResponse.json(
|
||||
{ error: "Internal server error" },
|
||||
{ status: 500 },
|
||||
|
||||
Reference in new issue
Block a user