prettier fix

This commit is contained in:
Danel Kungla
2025-09-19 17:22:36 +03:00
parent efa94b3322
commit 0c2cfe6d18
509 changed files with 17988 additions and 9920 deletions

View File

@@ -2,7 +2,11 @@ import { config } from 'dotenv';
export default function loadEnv() {
config({ path: `.env` });
if (['local', 'test', 'development', 'production'].includes(process.env.NODE_ENV!)) {
if (
['local', 'test', 'development', 'production'].includes(
process.env.NODE_ENV!,
)
) {
config({ path: `.env.${process.env.NODE_ENV}` });
}
}

View File

@@ -1,9 +1,13 @@
import Medusa from "@medusajs/js-sdk"
import type { AdminProductCategory } from "@medusajs/types";
import { listProductTypes } from "@lib/data/products";
import { getAnalysisElements } from "~/lib/services/analysis-element.service";
import { getAnalysisGroups } from "~/lib/services/analysis-group.service";
import { createMedusaSyncFailEntry, createMedusaSyncSuccessEntry } from "~/lib/services/analyses.service";
import { listProductTypes } from '@lib/data/products';
import Medusa from '@medusajs/js-sdk';
import type { AdminProductCategory } from '@medusajs/types';
import {
createMedusaSyncFailEntry,
createMedusaSyncSuccessEntry,
} from '~/lib/services/analyses.service';
import { getAnalysisElements } from '~/lib/services/analysis-element.service';
import { getAnalysisGroups } from '~/lib/services/analysis-group.service';
const SYNLAB_SERVICES_CATEGORY_HANDLE = 'synlab-services';
const SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE = 'synlab-analysis';
@@ -12,7 +16,8 @@ const BASE_ANALYSIS_PRODUCT_HANDLE = 'analysis-base';
const getAdminSdk = () => {
const medusaBackendUrl = process.env.MEDUSA_BACKEND_PUBLIC_URL!;
const medusaPublishableApiKey = process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY!;
const medusaPublishableApiKey =
process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY!;
const key = process.env.MEDUSA_SECRET_API_KEY!;
if (!medusaBackendUrl || !medusaPublishableApiKey) {
@@ -23,15 +28,14 @@ const getAdminSdk = () => {
debug: process.env.NODE_ENV === 'development',
apiKey: key,
});
}
};
async function createProductCategories({
medusa,
}: {
medusa: Medusa;
}) {
const { product_categories: existingProductCategories } = await medusa.admin.productCategory.list();
const parentCategory = existingProductCategories.find(({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE);
async function createProductCategories({ medusa }: { medusa: Medusa }) {
const { product_categories: existingProductCategories } =
await medusa.admin.productCategory.list();
const parentCategory = existingProductCategories.find(
({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE,
);
if (!parentCategory) {
throw new Error('Parent category not found');
@@ -46,8 +50,12 @@ async function createProductCategories({
for (const analysisGroup of analysisGroups) {
console.info(`Processing analysis group '${analysisGroup.name}'`);
const isExisting = existingProductCategories.find(({ name }) => name === analysisGroup.name);
const isNewlyCreated = createdCategories.find(({ name }) => name === analysisGroup.name);
const isExisting = existingProductCategories.find(
({ name }) => name === analysisGroup.name,
);
const isNewlyCreated = createdCategories.find(
({ name }) => name === analysisGroup.name,
);
if (isExisting || isNewlyCreated) {
console.info(`Analysis group '${analysisGroup.name}' already exists`);
continue;
@@ -63,18 +71,19 @@ async function createProductCategories({
analysisGroupId: analysisGroup.id,
},
});
console.info(`Successfully created category, id=${createResponse.product_category.id}`);
console.info(
`Successfully created category, id=${createResponse.product_category.id}`,
);
createdCategories.push(createResponse.product_category);
}
}
async function getChildProductCategories({
medusa,
}: {
medusa: Medusa;
}) {
const { product_categories: allCategories } = await medusa.admin.productCategory.list();
const childCategories = allCategories.filter(({ parent_category_id }) => parent_category_id !== null);
async function getChildProductCategories({ medusa }: { medusa: Medusa }) {
const { product_categories: allCategories } =
await medusa.admin.productCategory.list();
const childCategories = allCategories.filter(
({ parent_category_id }) => parent_category_id !== null,
);
return childCategories;
}
@@ -93,34 +102,34 @@ async function deleteProductCategories({
/**
* In case a reset is needed
*/
async function deleteProducts({
medusa,
}: {
medusa: Medusa;
}) {
async function deleteProducts({ medusa }: { medusa: Medusa }) {
const { products: existingProducts } = await medusa.admin.product.list({
fields: 'id,collection_id',
limit: 1000,
});
await Promise.all(existingProducts.filter((a) => !a.collection_id).map(({ id }) => medusa.admin.product.delete(id)));
await Promise.all(
existingProducts
.filter((a) => !a.collection_id)
.map(({ id }) => medusa.admin.product.delete(id)),
);
}
async function getAnalysisPackagesType() {
const { productTypes } = await listProductTypes();
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE);
const analysisPackagesType = productTypes.find(
({ metadata }) => metadata?.handle === SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE,
);
if (!analysisPackagesType) {
throw new Error('Synlab analysis packages type not found');
}
return analysisPackagesType;
}
async function getProductDefaultFields({
medusa,
}: {
medusa: Medusa;
}) {
const baseProductsResponse = await medusa.admin.product.list({ handle: BASE_ANALYSIS_PRODUCT_HANDLE })
async function getProductDefaultFields({ medusa }: { medusa: Medusa }) {
const baseProductsResponse = await medusa.admin.product.list({
handle: BASE_ANALYSIS_PRODUCT_HANDLE,
});
const baseProduct = baseProductsResponse.products[0];
if (!baseProduct) {
throw new Error('Base product not found');
@@ -142,25 +151,18 @@ async function getProductDefaultFields({
defaultSalesChannels,
defaultProductOption,
defaultProductVariant,
}
};
}
async function createProducts({
medusa,
}: {
medusa: Medusa;
}) {
const { product_categories: allCategories } = await medusa.admin.productCategory.list();
async function createProducts({ medusa }: { medusa: Medusa }) {
const { product_categories: allCategories } =
await medusa.admin.productCategory.list();
const [
{ products: existingProducts },
analysisElements,
analysisPackagesType,
{
defaultSalesChannels,
defaultProductOption,
defaultProductVariant,
}
{ defaultSalesChannels, defaultProductOption, defaultProductVariant },
] = await Promise.all([
medusa.admin.product.list({
category_id: allCategories.map(({ id }) => id),
@@ -168,13 +170,17 @@ async function createProducts({
getAnalysisElements({ getAll: true }),
getAnalysisPackagesType(),
getProductDefaultFields({ medusa }),
])
]);
for (const analysisElement of analysisElements) {
const { analysis_id_original: originalId } = analysisElement;
const isExisting = existingProducts.find(({ metadata }) => metadata?.analysisIdOriginal === originalId);
const isExisting = existingProducts.find(
({ metadata }) => metadata?.analysisIdOriginal === originalId,
);
if (isExisting) {
console.info(`Analysis element '${analysisElement.analysis_name_lab}' already exists`);
console.info(
`Analysis element '${analysisElement.analysis_name_lab}' already exists`,
);
continue;
}
const { analysis_name_lab: name } = analysisElement;
@@ -183,7 +189,10 @@ async function createProducts({
continue;
}
const category = allCategories.find(({ metadata }) => metadata?.analysisGroupId === analysisElement.parent_analysis_group_id);
const category = allCategories.find(
({ metadata }) =>
metadata?.analysisGroupId === analysisElement.parent_analysis_group_id,
);
if (!category) {
console.error(`Category not found for analysis element '${name}'`);
continue;
@@ -227,9 +236,9 @@ export default async function syncAnalysisGroupsStore() {
// await deleteProductCategories({ medusa, categories });
// await deleteProducts({ medusa });
// return;
await createProducts({ medusa });
await createMedusaSyncSuccessEntry();
} catch (e) {
await createMedusaSyncFailEntry(JSON.stringify(e));

View File

@@ -1,16 +1,32 @@
import axios from 'axios';
import { XMLParser } from 'fast-xml-parser';
import fs from 'fs';
import { createAnalysisGroup, getAnalysisGroups } from '~/lib/services/analysis-group.service';
import { IMedipostPublicMessageDataParsed } from '~/lib/services/medipost/medipost.types';
import { createAnalysis, createNoDataReceivedEntry, createNoNewDataReceivedEntry, createSyncFailEntry, createSyncSuccessEntry, getAnalyses } from '~/lib/services/analyses.service';
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
import { AnalysisElement, createAnalysisElement, getAnalysisElements } from '~/lib/services/analysis-element.service';
import { createCodes } from '~/lib/services/codes.service';
import { getLatestPublicMessageListItem } from '~/lib/services/medipost/medipostPublicMessage.service';
import type { ICode } from '~/lib/types/code';
import { toArray } from '@kit/shared/utils';
import {
createAnalysis,
createNoDataReceivedEntry,
createNoNewDataReceivedEntry,
createSyncFailEntry,
createSyncSuccessEntry,
getAnalyses,
} from '~/lib/services/analyses.service';
import {
AnalysisElement,
createAnalysisElement,
getAnalysisElements,
} from '~/lib/services/analysis-element.service';
import {
createAnalysisGroup,
getAnalysisGroups,
} from '~/lib/services/analysis-group.service';
import { createCodes } from '~/lib/services/codes.service';
import { IMedipostPublicMessageDataParsed } from '~/lib/services/medipost/medipost.types';
import { getLatestPublicMessageListItem } from '~/lib/services/medipost/medipostPublicMessage.service';
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
import type { ICode } from '~/lib/types/code';
const WRITE_XML_TO_FILE = false as boolean;
export default async function syncAnalysisGroups() {
@@ -52,7 +68,8 @@ export default async function syncAnalysisGroups() {
}
const parser = new XMLParser({ ignoreAttributes: false });
const parsed: IMedipostPublicMessageDataParsed = parser.parse(publicMessageData);
const parsed: IMedipostPublicMessageDataParsed =
parser.parse(publicMessageData);
if (parsed.ANSWER?.CODE && parsed.ANSWER?.CODE !== 0) {
throw new Error(
@@ -77,12 +94,18 @@ export default async function syncAnalysisGroups() {
const codes: ICode[] = [];
for (const analysisGroup of analysisGroups) {
const existingAnalysisGroup = existingAnalysisGroups?.find(({ original_id }) => original_id === analysisGroup.UuringuGruppId);
const existingAnalysisGroup = existingAnalysisGroups?.find(
({ original_id }) => original_id === analysisGroup.UuringuGruppId,
);
let groupExistingAnalysisElements: AnalysisElement[] = [];
let analysisGroupId: number;
if (existingAnalysisGroup) {
console.info(`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists, only creating new analysis elements`);
groupExistingAnalysisElements = await getAnalysisElements({ analysisGroupId: existingAnalysisGroup.id });
console.info(
`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists, only creating new analysis elements`,
);
groupExistingAnalysisElements = await getAnalysisElements({
analysisGroupId: existingAnalysisGroup.id,
});
analysisGroupId = existingAnalysisGroup.id;
} else {
analysisGroupId = await createAnalysisGroup({
@@ -109,10 +132,14 @@ export default async function syncAnalysisGroups() {
for (const item of analysisGroupItems) {
const analysisElement = item.UuringuElement!;
const isExistingAnalysisElement = groupExistingAnalysisElements
.find(({ analysis_id_original }) => analysis_id_original === analysisElement.UuringId);
const isExistingAnalysisElement = groupExistingAnalysisElements.find(
({ analysis_id_original }) =>
analysis_id_original === analysisElement.UuringId,
);
if (isExistingAnalysisElement) {
console.info(`Analysis element '${analysisElement.UuringNimi}' already exists`);
console.info(
`Analysis element '${analysisElement.UuringNimi}' already exists`,
);
continue;
}
@@ -149,16 +176,24 @@ export default async function syncAnalysisGroups() {
const analyses = analysisElement.UuringuElement;
if (analyses?.length) {
const existingAnalyses = await getAnalyses({ originalIds: analyses.map(({ UuringId }) => UuringId) });
const existingAnalyses = await getAnalyses({
originalIds: analyses.map(({ UuringId }) => UuringId),
});
for (const analysis of analyses) {
const isExistingAnalysis = existingAnalyses.find(({ analysis_id_original }) => analysis_id_original === analysis.UuringId);
const isExistingAnalysis = existingAnalyses.find(
({ analysis_id_original }) =>
analysis_id_original === analysis.UuringId,
);
if (isExistingAnalysis) {
console.info(`Analysis '${analysis.UuringNimi}' already exists`);
continue;
}
const insertedAnalysisId = await createAnalysis(analysis, analysisGroupId);
const insertedAnalysisId = await createAnalysis(
analysis,
analysisGroupId,
);
if (analysis.Kood) {
const analysisCodes = toArray(analysis.Kood);
@@ -187,11 +222,17 @@ export default async function syncAnalysisGroups() {
await createSyncSuccessEntry();
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e);
await createSyncFailEntry(JSON.stringify({
message: errorMessage,
stack: e instanceof Error ? e.stack : undefined,
name: e instanceof Error ? e.name : 'Unknown',
}, null, 2));
await createSyncFailEntry(
JSON.stringify(
{
message: errorMessage,
stack: e instanceof Error ? e.stack : undefined,
name: e instanceof Error ? e.name : 'Unknown',
},
null,
2,
),
);
console.error('Sync failed:', e);
throw new Error(
`Failed to sync public message data, error: ${errorMessage}`,

View File

@@ -1,4 +1,4 @@
import { readPrivateMessageResponse } from "~/lib/services/medipost/medipostPrivateMessage.service";
import { readPrivateMessageResponse } from '~/lib/services/medipost/medipostPrivateMessage.service';
type ProcessedMessage = {
messageId: string;
@@ -15,9 +15,9 @@ type GroupedResults = {
};
export default async function syncAnalysisResults() {
console.info("Syncing analysis results");
let processedMessages: ProcessedMessage[] = [];
console.info('Syncing analysis results');
const processedMessages: ProcessedMessage[] = [];
const excludedMessageIds: string[] = [];
while (true) {
const result = await readPrivateMessageResponse({ excludedMessageIds });
@@ -26,7 +26,7 @@ export default async function syncAnalysisResults() {
}
if (!result.messageId) {
console.info("No more messages to process");
console.info('No more messages to process');
break;
}
@@ -59,5 +59,7 @@ export default async function syncAnalysisResults() {
}
return acc;
}, {} as GroupedResults);
console.info(`Processed ${processedMessages.length} messages, results: ${JSON.stringify(groupedResults)}`);
console.info(
`Processed ${processedMessages.length} messages, results: ${JSON.stringify(groupedResults)}`,
);
}

View File

@@ -1,4 +1,4 @@
import { NextRequest } from "next/server";
import { NextRequest } from 'next/server';
export default function validateApiKey(request: NextRequest) {
const envApiKey = process.env.JOBS_API_TOKEN;

View File

@@ -1,10 +1,13 @@
import { NextRequest, NextResponse } from "next/server";
import loadEnv from "../handler/load-env";
import validateApiKey from "../handler/validate-api-key";
import { getOrderedAnalysisIds } from "~/lib/services/medusaOrder.service";
import { sendOrderToMedipost } from "~/lib/services/medipost/medipostPrivateMessage.service";
import { retrieveOrder } from "@lib/data/orders";
import { getMedipostDispatchTries } from "~/lib/services/audit.service";
import { NextRequest, NextResponse } from 'next/server';
import { retrieveOrder } from '@lib/data/orders';
import { getMedipostDispatchTries } from '~/lib/services/audit.service';
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
import loadEnv from '../handler/load-env';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
@@ -19,23 +22,34 @@ export const POST = async (request: NextRequest) => {
const tries = await getMedipostDispatchTries(medusaOrderId);
if (tries >= 3) {
return NextResponse.json({
message: 'Order has been retried too many times',
}, { status: 400 });
return NextResponse.json(
{
message: 'Order has been retried too many times',
},
{ status: 400 },
);
}
try {
const medusaOrder = await retrieveOrder(medusaOrderId);
const orderedAnalysisElements = await getOrderedAnalysisIds({ medusaOrder });
const orderedAnalysisElements = await getOrderedAnalysisIds({
medusaOrder,
});
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
console.info("Successfully sent order to medipost");
return NextResponse.json({
message: 'Successfully sent order to medipost',
}, { status: 200 });
console.info('Successfully sent order to medipost');
return NextResponse.json(
{
message: 'Successfully sent order to medipost',
},
{ status: 200 },
);
} catch (e) {
console.error("Error sending order to medipost", e);
return NextResponse.json({
message: 'Failed to send order to medipost',
}, { status: 500 });
console.error('Error sending order to medipost', e);
return NextResponse.json(
{
message: 'Failed to send order to medipost',
},
{ status: 500 },
);
}
};

View File

@@ -4,6 +4,7 @@ import {
NotificationAction,
createNotificationLog,
} from '~/lib/services/audit/notificationEntries.service';
import loadEnv from '../handler/load-env';
import sendOpenJobsEmails from '../handler/send-open-jobs-emails';
import validateApiKey from '../handler/validate-api-key';

View File

@@ -1,7 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import loadEnv from "../handler/load-env";
import validateApiKey from "../handler/validate-api-key";
import syncAnalysisGroupsStore from "../handler/sync-analysis-groups-store";
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncAnalysisGroupsStore from '../handler/sync-analysis-groups-store';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
try {
await syncAnalysisGroupsStore();
console.info("Successfully synced analysis groups store");
return NextResponse.json({
message: 'Successfully synced analysis groups store',
}, { status: 200 });
console.info('Successfully synced analysis groups store');
return NextResponse.json(
{
message: 'Successfully synced analysis groups store',
},
{ status: 200 },
);
} catch (e) {
console.error("Error syncing analysis groups store", e);
return NextResponse.json({
message: 'Failed to sync analysis groups store',
}, { status: 500 });
console.error('Error syncing analysis groups store', e);
return NextResponse.json(
{
message: 'Failed to sync analysis groups store',
},
{ status: 500 },
);
}
};

View File

@@ -1,7 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import syncAnalysisGroups from "../handler/sync-analysis-groups";
import loadEnv from "../handler/load-env";
import validateApiKey from "../handler/validate-api-key";
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncAnalysisGroups from '../handler/sync-analysis-groups';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
try {
await syncAnalysisGroups();
console.info("Successfully synced analysis groups");
return NextResponse.json({
message: 'Successfully synced analysis groups',
}, { status: 200 });
console.info('Successfully synced analysis groups');
return NextResponse.json(
{
message: 'Successfully synced analysis groups',
},
{ status: 200 },
);
} catch (e) {
console.error("Error syncing analysis groups", e);
return NextResponse.json({
message: 'Failed to sync analysis groups',
}, { status: 500 });
console.error('Error syncing analysis groups', e);
return NextResponse.json(
{
message: 'Failed to sync analysis groups',
},
{ status: 500 },
);
}
};

View File

@@ -1,7 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import loadEnv from "../handler/load-env";
import validateApiKey from "../handler/validate-api-key";
import syncAnalysisResults from "../handler/sync-analysis-results";
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncAnalysisResults from '../handler/sync-analysis-results';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
try {
await syncAnalysisResults();
console.info("Successfully synced analysis results");
return NextResponse.json({
message: 'Successfully synced analysis results',
}, { status: 200 });
console.info('Successfully synced analysis results');
return NextResponse.json(
{
message: 'Successfully synced analysis results',
},
{ status: 200 },
);
} catch (e) {
console.error("Error syncing analysis results", e);
return NextResponse.json({
message: 'Failed to sync analysis results',
}, { status: 500 });
console.error('Error syncing analysis results', e);
return NextResponse.json(
{
message: 'Failed to sync analysis results',
},
{ status: 500 },
);
}
};

View File

@@ -1,7 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import loadEnv from "../handler/load-env";
import validateApiKey from "../handler/validate-api-key";
import syncConnectedOnline from "../handler/sync-connected-online";
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncConnectedOnline from '../handler/sync-connected-online';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
try {
await syncConnectedOnline();
console.info("Successfully synced connected-online");
return NextResponse.json({
message: 'Successfully synced connected-online',
}, { status: 200 });
console.info('Successfully synced connected-online');
return NextResponse.json(
{
message: 'Successfully synced connected-online',
},
{ status: 200 },
);
} catch (e) {
console.error("Error syncing connected-online", e);
return NextResponse.json({
message: 'Failed to sync connected-online',
}, { status: 500 });
console.error('Error syncing connected-online', e);
return NextResponse.json(
{
message: 'Failed to sync connected-online',
},
{ status: 500 },
);
}
};

View File

@@ -1,11 +1,17 @@
import { NextRequest, NextResponse } from "next/server";
import { getAnalysisOrdersAdmin } from "~/lib/services/order.service";
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/medipost/medipostTest.service";
import { retrieveOrder } from "@lib/data";
import { getAccountAdmin } from "~/lib/services/account.service";
import { getOrderedAnalysisIds } from "~/lib/services/medusaOrder.service";
import loadEnv from "../handler/load-env";
import validateApiKey from "../handler/validate-api-key";
import { NextRequest, NextResponse } from 'next/server';
import { retrieveOrder } from '@lib/data';
import { getAccountAdmin } from '~/lib/services/account.service';
import {
composeOrderTestResponseXML,
sendPrivateMessageTestResponse,
} from '~/lib/services/medipost/medipostTest.service';
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
import { getAnalysisOrdersAdmin } from '~/lib/services/order.service';
import loadEnv from '../handler/load-env';
import validateApiKey from '../handler/validate-api-key';
export async function POST(request: NextRequest) {
loadEnv();
@@ -16,17 +22,27 @@ export async function POST(request: NextRequest) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
const analysisOrders = await getAnalysisOrdersAdmin({ orderStatus: 'PROCESSING' });
const analysisOrders = await getAnalysisOrdersAdmin({
orderStatus: 'PROCESSING',
});
console.error(`Sending test responses for ${analysisOrders.length} analysis orders`);
console.error(
`Sending test responses for ${analysisOrders.length} analysis orders`,
);
for (const medreportOrder of analysisOrders) {
const medusaOrderId = medreportOrder.medusa_order_id;
const medusaOrder = await retrieveOrder(medusaOrderId)
const medusaOrder = await retrieveOrder(medusaOrderId);
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({ medusaOrder });
const account = await getAccountAdmin({
primaryOwnerUserId: medreportOrder.user_id,
});
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({
medusaOrder,
});
console.info(`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`);
console.info(
`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`,
);
const idsToSend = orderedAnalysisElementsIds;
const messageXml = await composeOrderTestResponseXML({
person: {
@@ -35,8 +51,12 @@ export async function POST(request: NextRequest) {
lastName: account.last_name ?? '',
phone: account.phone ?? '',
},
orderedAnalysisElementsIds: idsToSend.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
orderedAnalysesIds: idsToSend.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
orderedAnalysisElementsIds: idsToSend
.map(({ analysisElementId }) => analysisElementId)
.filter(Boolean) as number[],
orderedAnalysesIds: idsToSend
.map(({ analysisId }) => analysisId)
.filter(Boolean) as number[],
orderId: medreportOrder.id,
orderCreatedAt: new Date(medreportOrder.created_at),
});
@@ -44,7 +64,7 @@ export async function POST(request: NextRequest) {
try {
await sendPrivateMessageTestResponse({ messageXml });
} catch (error) {
console.error("Error sending private message test response: ", error);
console.error('Error sending private message test response: ', error);
}
}