feat(MED-87): improve naming
This commit is contained in:
@@ -11,7 +11,7 @@ import { loadUserAnalysis } from '../../_lib/server/load-user-analysis';
|
|||||||
import Analysis from './_components/analysis';
|
import Analysis from './_components/analysis';
|
||||||
import pathsConfig from '~/config/paths.config';
|
import pathsConfig from '~/config/paths.config';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { getOrders } from '~/lib/services/order.service';
|
import { getAnalysisOrders } from '~/lib/services/order.service';
|
||||||
import { getAnalysisElements } from '~/lib/services/analysis-element.service';
|
import { getAnalysisElements } from '~/lib/services/analysis-element.service';
|
||||||
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
||||||
import { createPageViewLog } from '~/lib/services/audit/pageView.service';
|
import { createPageViewLog } from '~/lib/services/audit/pageView.service';
|
||||||
@@ -34,9 +34,9 @@ async function AnalysisResultsPage() {
|
|||||||
const analysisResponses = await loadUserAnalysis();
|
const analysisResponses = await loadUserAnalysis();
|
||||||
const analysisResponseElements = analysisResponses?.flatMap(({ elements }) => elements);
|
const analysisResponseElements = analysisResponses?.flatMap(({ elements }) => elements);
|
||||||
|
|
||||||
const orders = await getOrders().catch(() => null);
|
const analysisOrders = await getAnalysisOrders().catch(() => null);
|
||||||
|
|
||||||
if (!orders) {
|
if (!analysisOrders) {
|
||||||
redirect(pathsConfig.auth.signIn);
|
redirect(pathsConfig.auth.signIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ async function AnalysisResultsPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const analysisElementIds = [
|
const analysisElementIds = [
|
||||||
...new Set(orders?.flatMap((order) => order.analysis_element_ids).filter(Boolean) as number[]),
|
...new Set(analysisOrders?.flatMap((order) => order.analysis_element_ids).filter(Boolean) as number[]),
|
||||||
];
|
];
|
||||||
const analysisElements = await getAnalysisElements({ ids: analysisElementIds });
|
const analysisElements = await getAnalysisElements({ ids: analysisElementIds });
|
||||||
const analysisElementsWithResults = analysisResponseElements
|
const analysisElementsWithResults = analysisResponseElements
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
|||||||
import OrdersTable from '../../_components/orders/orders-table';
|
import OrdersTable from '../../_components/orders/orders-table';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
import type { IOrderLineItem } from '../../_components/orders/types';
|
import type { IOrderLineItem } from '../../_components/orders/types';
|
||||||
import { getOrders } from '~/lib/services/order.service';
|
import { getAnalysisOrders } from '~/lib/services/order.service';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
@@ -21,19 +21,19 @@ export async function generateMetadata() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function OrdersPage() {
|
async function OrdersPage() {
|
||||||
const orders = await listOrders();
|
const medusaOrders = await listOrders();
|
||||||
const localOrders = await getOrders();
|
const analysisOrders = await getAnalysisOrders();
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
|
|
||||||
if (!orders || !productTypes) {
|
if (!medusaOrders || !productTypes) {
|
||||||
redirect(pathsConfig.auth.signIn);
|
redirect(pathsConfig.auth.signIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
|
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
|
||||||
const analysisPackageOrders: IOrderLineItem[] = orders.flatMap(({ id, items, payment_status, fulfillment_status }) => items
|
const analysisPackageOrders: IOrderLineItem[] = medusaOrders.flatMap(({ id, items, payment_status, fulfillment_status }) => items
|
||||||
?.filter((item) => item.product_type_id === analysisPackagesType?.id)
|
?.filter((item) => item.product_type_id === analysisPackagesType?.id)
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
const localOrder = localOrders.find((order) => order.medusa_order_id === id);
|
const localOrder = analysisOrders.find((order) => order.medusa_order_id === id);
|
||||||
if (!localOrder) {
|
if (!localOrder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -48,19 +48,19 @@ async function OrdersPage() {
|
|||||||
.filter((order) => order !== null)
|
.filter((order) => order !== null)
|
||||||
|| []);
|
|| []);
|
||||||
|
|
||||||
const otherOrders: IOrderLineItem[] = orders
|
const otherOrders: IOrderLineItem[] = medusaOrders
|
||||||
.filter(({ items }) => items?.some((item) => item.product_type_id !== analysisPackagesType?.id))
|
.filter(({ items }) => items?.some((item) => item.product_type_id !== analysisPackagesType?.id))
|
||||||
.flatMap(({ id, items, payment_status, fulfillment_status }) => items
|
.flatMap(({ id, items, payment_status, fulfillment_status }) => items
|
||||||
?.map((item) => {
|
?.map((item) => {
|
||||||
const localOrder = localOrders.find((order) => order.medusa_order_id === id);
|
const analysisOrder = analysisOrders.find((order) => order.medusa_order_id === id);
|
||||||
if (!localOrder) {
|
if (!analysisOrder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
item,
|
item,
|
||||||
medusaOrderId: id,
|
medusaOrderId: id,
|
||||||
orderId: localOrder.id,
|
orderId: analysisOrder.id,
|
||||||
orderStatus: localOrder.status,
|
orderStatus: analysisOrder.status,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((order) => order !== null)
|
.filter((order) => order !== null)
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* This file is used to register monitoring instrumentation
|
|
||||||
* for your Next.js application.
|
|
||||||
*/
|
|
||||||
import { type Instrumentation } from 'next';
|
import { type Instrumentation } from 'next';
|
||||||
|
|
||||||
const isEnabledInDev = process.env.ENABLE_LOCAL_JOBS === 'true';
|
const isEnabledInDev = process.env.ENABLE_LOCAL_JOBS === 'true';
|
||||||
@@ -59,7 +55,6 @@ async function registerJobScheduler() {
|
|||||||
}
|
}
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
try {
|
try {
|
||||||
// Ensure env variables are loaded for the handler
|
|
||||||
try {
|
try {
|
||||||
const { default: loadEnv } = await import('./app/api/job/handler/load-env');
|
const { default: loadEnv } = await import('./app/api/job/handler/load-env');
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -72,7 +67,6 @@ async function registerJobScheduler() {
|
|||||||
);
|
);
|
||||||
await syncAnalysisResults();
|
await syncAnalysisResults();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Log and continue; do not crash the process
|
|
||||||
console.error('Scheduled job syncAnalysisResults failed:', error);
|
console.error('Scheduled job syncAnalysisResults failed:', error);
|
||||||
} finally {
|
} finally {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export async function getOrder({
|
|||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getOrders({
|
export async function getAnalysisOrders({
|
||||||
orderStatus,
|
orderStatus,
|
||||||
}: {
|
}: {
|
||||||
orderStatus?: Tables<{ schema: 'medreport' }, 'analysis_orders'>['status'];
|
orderStatus?: Tables<{ schema: 'medreport' }, 'analysis_orders'>['status'];
|
||||||
|
|||||||
Reference in New Issue
Block a user