diff --git a/app/api/job/handler/send-open-jobs-emails.ts b/app/api/job/handler/send-open-jobs-emails.ts index 9f09e12..44d436e 100644 --- a/app/api/job/handler/send-open-jobs-emails.ts +++ b/app/api/job/handler/send-open-jobs-emails.ts @@ -7,10 +7,18 @@ import { sendEmailFromTemplate } from '~/lib/services/mailer.service'; export default async function sendOpenJobsEmails() { const analysisResponseIds = await getOpenJobAnalysisResponseIds(); + if (analysisResponseIds.length === 0) { + return; + } + const doctorAccounts = await getDoctorAccounts(); - const doctorEmails: string[] = doctorAccounts + const doctorEmails = doctorAccounts .map(({ email }) => email) - .filter((email): email is string => !!email); + .filter((email) => !!email); + + if (doctorEmails !== null) { + return []; + } await sendEmailFromTemplate( renderNewJobsAvailableEmail, @@ -20,4 +28,6 @@ export default async function sendOpenJobsEmails() { }, doctorEmails, ); + + return doctorAccounts.filter((email) => !!email).map(({ id }) => id); } diff --git a/app/api/job/handler/sync-analysis-results.ts b/app/api/job/handler/sync-analysis-results.ts index b631045..3be7639 100644 --- a/app/api/job/handler/sync-analysis-results.ts +++ b/app/api/job/handler/sync-analysis-results.ts @@ -1,3 +1,6 @@ +import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api'; +import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client'; + import { readPrivateMessageResponse } from '~/lib/services/medipost/medipostPrivateMessage.service'; type ProcessedMessage = { @@ -16,6 +19,8 @@ type GroupedResults = { export default async function syncAnalysisResults() { console.info('Syncing analysis results'); + const supabase = getSupabaseServerClient(); + const api = createUserAnalysesApi(supabase); const processedMessages: ProcessedMessage[] = []; const excludedMessageIds: string[] = []; @@ -25,6 +30,12 @@ export default async function syncAnalysisResults() { processedMessages.push(result as ProcessedMessage); } + await api.sendAnalysisResultsNotification({ + hasFullAnalysisResponse: result.hasFullAnalysisResponse, + hasPartialAnalysisResponse: result.hasAnalysisResponse, + analysisOrderId: result.analysisOrderId, + }); + if (!result.messageId) { console.info('No more messages to process'); break; diff --git a/app/api/job/send-open-jobs-emails/route.ts b/app/api/job/send-open-jobs-emails/route.ts index 0c22957..a18d3c6 100644 --- a/app/api/job/send-open-jobs-emails/route.ts +++ b/app/api/job/send-open-jobs-emails/route.ts @@ -19,13 +19,14 @@ export const POST = async (request: NextRequest) => { } try { - await sendOpenJobsEmails(); + const doctors = await sendOpenJobsEmails(); console.info( - 'Successfully sent out open job notification emails to doctors.', + 'Successfully sent out open job notification emails to doctors', ); await createNotificationLog({ action: NotificationAction.DOCTOR_NEW_JOBS, status: 'SUCCESS', + comment: `doctors that received email: ${doctors}`, }); return NextResponse.json( { diff --git a/app/auth/membership-confirmation/_components/membership-confirmation-notification.tsx b/app/auth/membership-confirmation/_components/membership-confirmation-notification.tsx index 86b8079..1931d21 100644 --- a/app/auth/membership-confirmation/_components/membership-confirmation-notification.tsx +++ b/app/auth/membership-confirmation/_components/membership-confirmation-notification.tsx @@ -25,7 +25,7 @@ const MembershipConfirmationNotification: React.FC<{ descriptionKey="account:membershipConfirmation:successDescription" buttonProps={{ buttonTitleKey: 'account:membershipConfirmation:successButton', - href: pathsConfig.app.home, + href: pathsConfig.app.selectPackage, }} /> ); diff --git a/app/select-package/page.tsx b/app/select-package/page.tsx index 532794f..bba9f72 100644 --- a/app/select-package/page.tsx +++ b/app/select-package/page.tsx @@ -48,6 +48,7 @@ async function SelectPackagePage() { } + countryCode={countryCode} /> ; }) { const supabase = getSupabaseServerAdminClient(); - const { t } = await createI18nServerInstance(); const orderStatus = AnalysisOrderStatus[TellimuseOlek]; @@ -304,7 +300,6 @@ export async function syncPrivateMessage({ log, }); - let newElementsAdded = 0; for (const element of newElements) { try { await upsertAnalysisResponseElement({ @@ -313,7 +308,6 @@ export async function syncPrivateMessage({ analysis_response_id: analysisResponseId, }, }); - newElementsAdded++; } catch (e) { log( `Failed to create order response element for response id ${analysisResponseId}, element id '${element.analysis_element_original_id}' (order id: ${order.id})`, @@ -322,16 +316,6 @@ export async function syncPrivateMessage({ } } - log(`Added ${newElementsAdded} new elements`); - - if (newElementsAdded !== 0) { - await createNotificationsApi(supabase).createNotification({ - account_id: analysisOrder.user_id, - body: t('analysis-results:notification.body'), - link: `${pathsConfig.app.analysisResults}/${order.id}`, - }); - } - return (await hasAllAnalysisResponseElements({ analysisResponseId, order })) ? { isCompleted: orderStatus === 'COMPLETED' } : { isPartial: true }; diff --git a/packages/email-templates/src/locales/et/invite-email.json b/packages/email-templates/src/locales/et/invite-email.json new file mode 100644 index 0000000..1705d0f --- /dev/null +++ b/packages/email-templates/src/locales/et/invite-email.json @@ -0,0 +1,9 @@ +{ + "subject": "Teid on kutsutud tiimi", + "heading": "Liitu tiimiga {{teamName}}", + "hello": "Tere {{invitedUserEmail}},", + "mainText": "{{inviter}} on kutsunud teid ühinema tiimiga {{teamName}} platvormil {{productName}}.", + "joinTeam": "Liitu {{teamName}}", + "copyPasteLink": "või kopeeri ja kleebi see URL teie brauseris:", + "invitationIntendedFor": "See kutse on mõeldud {{invitedUserEmail}} omanikule." +} diff --git a/packages/features/accounts/src/server/api.ts b/packages/features/accounts/src/server/api.ts index b934e39..96366bd 100644 --- a/packages/features/accounts/src/server/api.ts +++ b/packages/features/accounts/src/server/api.ts @@ -214,7 +214,7 @@ class AccountsApi { .schema('medreport') .from('accounts_memberships') .select('account_id', { count: 'exact', head: true }) - .eq('account_id', accountId); + .eq('user_id', accountId); if (error) { throw error; diff --git a/packages/features/doctor/src/lib/server/services/doctor-analysis.service.ts b/packages/features/doctor/src/lib/server/services/doctor-analysis.service.ts index 8068a32..23f355d 100644 --- a/packages/features/doctor/src/lib/server/services/doctor-analysis.service.ts +++ b/packages/features/doctor/src/lib/server/services/doctor-analysis.service.ts @@ -58,6 +58,11 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) { .in('primary_owner_user_id', userIds), ]); + if (!analysisResponseElements || analysisResponseElements?.length === 0) { + console.info(`${analysisResponseIds} has no response elements`); + return []; + } + const doctorUserIds = doctorFeedbackItems ?.map((item) => item.doctor_user_id) @@ -285,7 +290,6 @@ export async function getOpenResponses({ `, { count: 'exact' }, ) - .neq('order_status', 'ON_HOLD') .order('created_at', { ascending: false }); if (assignedIds.length > 0) { diff --git a/packages/features/user-analyses/src/server/api.ts b/packages/features/user-analyses/src/server/api.ts index fa738ec..463f2c8 100644 --- a/packages/features/user-analyses/src/server/api.ts +++ b/packages/features/user-analyses/src/server/api.ts @@ -1,10 +1,14 @@ import { SupabaseClient } from '@supabase/supabase-js'; +import { createNotificationsApi } from '@kit/notifications/api'; +import { pathsConfig } from '@kit/shared/config'; import { getLogger } from '@kit/shared/logger'; import type { UuringuVastus } from '@kit/shared/types/medipost-analysis'; import { toArray } from '@kit/shared/utils'; import { Database } from '@kit/supabase/database'; +import { createI18nServerInstance } from '~/lib/i18n/i18n.server'; + import type { AnalysisOrder, AnalysisOrderStatus, @@ -488,6 +492,39 @@ class UserAnalysesApi { }) .throwOnError(); } + + async sendAnalysisResultsNotification({ + hasFullAnalysisResponse, + hasPartialAnalysisResponse, + analysisOrderId, + }: { + hasFullAnalysisResponse: boolean; + hasPartialAnalysisResponse: boolean; + analysisOrderId?: number; + }) { + if (!analysisOrderId) { + return; + } + const { data, error: userError } = await this.client.auth.getUser(); + if (userError) { + throw userError; + } + const { user } = data; + const notificationsApi = createNotificationsApi(this.client); + const { t } = await createI18nServerInstance(); + + console.info( + `Order ${analysisOrderId} got new responses -> Sending new notification`, + ); + + if (hasFullAnalysisResponse || hasPartialAnalysisResponse) { + await notificationsApi.createNotification({ + account_id: user.id, + body: t('analysis-results:notification.body'), + link: `${pathsConfig.app.analysisResults}/${analysisOrderId}`, + }); + } + } } export function createUserAnalysesApi(client: SupabaseClient) { diff --git a/packages/features/user-analyses/tsconfig.json b/packages/features/user-analyses/tsconfig.json index 8d5bae9..e2b4bf5 100644 --- a/packages/features/user-analyses/tsconfig.json +++ b/packages/features/user-analyses/tsconfig.json @@ -1,10 +1,7 @@ { - "extends": "@kit/tsconfig/base.json", + "extends": "../../../tsconfig.json", "compilerOptions": { - "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json", - "paths": { - "~/lib/utils": ["../../../lib/utils.ts"] - } + "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" }, "include": ["*.ts", "*.tsx", "src"], "exclude": ["node_modules"] diff --git a/public/locales/et/cart.json b/public/locales/et/cart.json index ab43940..0120bc0 100644 --- a/public/locales/et/cart.json +++ b/public/locales/et/cart.json @@ -29,9 +29,9 @@ "title": "Kinkekaart või sooduskood", "label": "Lisa promo kood", "apply": "Rakenda", - "subtitle": "Kui soovid, võid lisada promo koodi", - "placeholder": "Sisesta promo kood", - "remove": "Eemalda promo kood", + "subtitle": "Kui soovid, võid lisada promokoodi", + "placeholder": "Sisesta promokood", + "remove": "Eemalda promokood", "appliedCodes": "Rakendatud sooduskoodid:", "removeError": "Sooduskoodi eemaldamine ebaõnnestus", "removeSuccess": "Sooduskood eemaldatud", diff --git a/public/locales/et/common.json b/public/locales/et/common.json index a7f5809..8615a16 100644 --- a/public/locales/et/common.json +++ b/public/locales/et/common.json @@ -63,7 +63,7 @@ "myActions": "Minu toimingud", "healthPackageComparison": { "label": "Tervisepakettide võrdlus", - "description": "Alljärgnevalt on antud eelinfo (sugu, vanus ja kehamassiindeks) põhjal tehtud personaalne terviseauditi valik. Tabelis on võimalik soovitatud terviseuuringute paketile lisada üksikuid uuringuid juurde." + "description": "Alljärgnevalt on antud eelinfo (sugu, vanus ja kehamassiindeks) põhjal tehtud personaalne terviseauditi valik. Terviseuuringute paketile on võimalik lisada üksikuid uuringuid juurde." }, "routes": { "home": "Avaleht",