change recommendations to update through doctor

This commit is contained in:
Danel Kungla
2025-10-23 16:48:27 +03:00
parent cd6476821a
commit 9a01c15a76
8 changed files with 205 additions and 147 deletions

View File

@@ -3,7 +3,11 @@ import { cache } from 'react';
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
import { ILifeStyleResponse, PROMPT_NAME } from '../../_components/ai/types';
import {
AnalysisResponses,
ILifeStyleResponse,
PROMPT_NAME,
} from '../../_components/ai/types';
import { updateLifeStyle } from './ai-actions';
const failedResponse = {
@@ -13,17 +17,12 @@ const failedResponse = {
async function lifeStyleLoader(
account: AccountWithParams,
analysisResponses?: AnalysisResponses,
): Promise<ILifeStyleResponse> {
if (!account?.personal_code) {
return failedResponse;
}
const lifeStylePromptId = process.env.PROMPT_ID_LIFE_STYLE;
if (!lifeStylePromptId) {
return failedResponse;
}
const supabaseClient = getSupabaseServerClient();
const { data, error } = await supabaseClient
.schema('medreport')
@@ -43,7 +42,7 @@ async function lifeStyleLoader(
if (data?.response) {
return JSON.parse(data.response as string);
} else {
return await updateLifeStyle({ account });
return await updateLifeStyle({ account, analysisResponses });
}
}
export const loadLifeStyle = cache(lifeStyleLoader);