Merge branch 'develop' of https://github.com/MR-medreport/MRB2B into MED-103
This commit is contained in:
@@ -41,7 +41,7 @@ async function analysesLoader() {
|
||||
const categoryProducts = category
|
||||
? await listProducts({
|
||||
countryCode,
|
||||
queryParams: { limit: 100, category_id: category.id },
|
||||
queryParams: { limit: 100, category_id: category.id, order: 'title' },
|
||||
})
|
||||
: null;
|
||||
|
||||
@@ -51,8 +51,10 @@ async function analysesLoader() {
|
||||
|
||||
return {
|
||||
analyses:
|
||||
categoryProducts?.response.products.map<OrderAnalysisCard>(
|
||||
({ title, description, subtitle, variants, status, metadata }) => {
|
||||
categoryProducts?.response.products
|
||||
.filter(({ status, metadata }) => status === 'published' && !!metadata?.analysisIdOriginal)
|
||||
.map<OrderAnalysisCard>(
|
||||
({ title, description, subtitle, variants }) => {
|
||||
const variant = variants![0]!;
|
||||
return {
|
||||
title,
|
||||
@@ -61,8 +63,6 @@ async function analysesLoader() {
|
||||
variant: {
|
||||
id: variant.id,
|
||||
},
|
||||
isAvailable:
|
||||
status === 'published' && !!metadata?.analysisIdOriginal,
|
||||
price: variant.calculated_price?.calculated_amount ?? null,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { cache } from 'react';
|
||||
import Isikukood, { Gender } from 'isikukood';
|
||||
|
||||
import { listProductTypes, listProducts } from "@lib/data/products";
|
||||
import { listRegions } from '@lib/data/regions';
|
||||
@@ -8,6 +7,7 @@ import type { StoreProduct } from '@medusajs/types';
|
||||
import { loadCurrentUserAccount } from './load-user-account';
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/server/api';
|
||||
import { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
||||
import PersonalCode from '~/lib/utils';
|
||||
|
||||
async function countryCodesLoader() {
|
||||
const countryCodes = await listRegions().then((regions) =>
|
||||
@@ -32,27 +32,8 @@ function userSpecificVariantLoader({
|
||||
if (!personalCode) {
|
||||
throw new Error('Personal code not found');
|
||||
}
|
||||
const parsed = new Isikukood(personalCode);
|
||||
const ageRange = (() => {
|
||||
const age = parsed.getAge();
|
||||
if (age >= 18 && age <= 29) {
|
||||
return '18-29';
|
||||
}
|
||||
if (age >= 30 && age <= 39) {
|
||||
return '30-39';
|
||||
}
|
||||
if (age >= 40 && age <= 49) {
|
||||
return '40-49';
|
||||
}
|
||||
if (age >= 50 && age <= 59) {
|
||||
return '50-59';
|
||||
}
|
||||
if (age >= 60) {
|
||||
return '60';
|
||||
}
|
||||
throw new Error('Age range not supported');
|
||||
})();
|
||||
const gender = parsed.getGender() === Gender.MALE ? 'M' : 'F';
|
||||
|
||||
const { ageRange, gender: { value: gender } } = PersonalCode.parsePersonalCode(personalCode);
|
||||
|
||||
return ({
|
||||
product,
|
||||
@@ -89,6 +70,7 @@ async function analysisPackageElementsLoader({
|
||||
queryParams: {
|
||||
id: analysisElementMedusaProductIds,
|
||||
limit: 100,
|
||||
order: "title",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -140,8 +122,9 @@ async function analysisPackagesWithVariantLoader({
|
||||
return [
|
||||
...acc,
|
||||
{
|
||||
variant,
|
||||
variantId: variant.id,
|
||||
nrOfAnalyses: getAnalysisElementMedusaProductIds([product]).length,
|
||||
nrOfAnalyses: getAnalysisElementMedusaProductIds([{ ...product, variant }]).length,
|
||||
price: variant.calculated_price?.calculated_amount ?? 0,
|
||||
title: product.title,
|
||||
subtitle: product.subtitle,
|
||||
@@ -158,7 +141,7 @@ async function analysisPackagesWithVariantLoader({
|
||||
}
|
||||
|
||||
async function analysisPackagesLoader() {
|
||||
const account = await loadCurrentUserAccount();
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
throw new Error('Account not found');
|
||||
}
|
||||
|
||||
@@ -16,14 +16,17 @@ export const loadUserAccount = cache(accountLoader);
|
||||
|
||||
export async function loadCurrentUserAccount() {
|
||||
const user = await requireUserInServerComponent();
|
||||
return user?.identities?.[0]?.id
|
||||
? await loadUserAccount(user?.identities?.[0]?.id)
|
||||
: null;
|
||||
const userId = user?.id;
|
||||
if (!userId) {
|
||||
return { account: null, user: null };
|
||||
}
|
||||
const account = await loadUserAccount(userId);
|
||||
return { account, user };
|
||||
}
|
||||
|
||||
async function accountLoader(accountId: string) {
|
||||
async function accountLoader(userId: string) {
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createAccountsApi(client);
|
||||
|
||||
return api.getAccount(accountId);
|
||||
return api.getPersonalAccountByUserId(userId);
|
||||
}
|
||||
|
||||
@@ -28,20 +28,15 @@ async function workspaceLoader() {
|
||||
|
||||
const workspacePromise = api.getAccountWorkspace();
|
||||
|
||||
// TODO!: remove before deploy to prod
|
||||
const tempAccountsPromise = () => api.loadTempUserAccounts();
|
||||
|
||||
const [accounts, workspace, user, tempVisibleAccounts] = await Promise.all([
|
||||
const [accounts, workspace, user] = await Promise.all([
|
||||
accountsPromise(),
|
||||
workspacePromise,
|
||||
requireUserInServerComponent(),
|
||||
tempAccountsPromise(),
|
||||
]);
|
||||
|
||||
return {
|
||||
accounts,
|
||||
workspace,
|
||||
user,
|
||||
tempVisibleAccounts,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user