From 7b2610ea13e9be2be874d630e8eef96132fa4eaa Mon Sep 17 00:00:00 2001 From: Patrick Schilf Date: Tue, 30 Jul 2024 10:04:11 -0300 Subject: [PATCH] ROCKS-30 Fix resetting,handling age null values --- app/components/Form/Specimen/Details.vue | 8 ++++---- app/server/plugins/specimens/specimen.base.payload.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/components/Form/Specimen/Details.vue b/app/components/Form/Specimen/Details.vue index 54e6887..6533b88 100644 --- a/app/components/Form/Specimen/Details.vue +++ b/app/components/Form/Specimen/Details.vue @@ -90,8 +90,8 @@ const emits = defineEmits<{ const data = reactive({ classification: props.specimen.classification?.self, - ageNumeric: props.specimen.age.numeric?.map(n => n / 1e6) ?? [], - ageRelative: props.specimen.age.relative?.map(u => u.self) ?? [], + ageNumeric: props.specimen.age?.numeric?.map(n => n / 1e6) ?? [], + ageRelative: props.specimen.age?.relative?.map(u => u.self) ?? [], composition: (props.specimen as Fossil | Rock).composition?.entities.map(c => c.self), pieces: props.specimen.pieces || 1, partial: props.specimen.partial, @@ -122,8 +122,8 @@ const onSave = () => { const payload = { classification: classification ?? (props.specimen.classification ? null : undefined), age: ageType.value === `numeric` - ? (ageNumeric.filter(n => n).length && ageNumeric.filter(a => !isNaN(a)).map(age => age * 1e6)) || (props.specimen.age?.relative ? null : undefined) - : (ageRelative.filter(r => r).length && ageRelative.filter(a => a)) || (props.specimen.age?.numeric ? null : undefined), + ? (ageNumeric.filter(n => n).length && ageNumeric.filter(a => !isNaN(a)).map(age => age * 1e6)) || (props.specimen.age?.numeric ? null : undefined) + : (ageRelative.filter(r => r).length && ageRelative.filter(a => a)) || (props.specimen.age?.relative ? null : undefined), composition: composition || ((props.specimen as Fossil | Rock).composition ? null : undefined), pieces, partial, diff --git a/app/server/plugins/specimens/specimen.base.payload.ts b/app/server/plugins/specimens/specimen.base.payload.ts index 4d95820..6ef606a 100644 --- a/app/server/plugins/specimens/specimen.base.payload.ts +++ b/app/server/plugins/specimens/specimen.base.payload.ts @@ -76,14 +76,14 @@ export default defineMongooseReader(Specimen.Base, async (payload, { op }) => { return { ...body, - pk: (create && `UNB-${`${Math.floor(Math.random() * 1000000)}`.padStart(8, `0`)}`) || undefined, + // pk: (create && `UNB-${`${Math.floor(Math.random() * 1000000)}`.padStart(8, `0`)}`) || undefined, legal: legal && useEnum(Legal).valueOf(legal), lenderID, classification: classification && { _id: classification.substring(1).split(`/`).at(-1)! }, kollektion: collection && { _id: collection.substring(1).split(`/`).at(-1)! }, images: images?.map(uri => ({ _id: uri.substring(1).split(`/`).at(-1)! })), - relativeAge: (age && (age.every(a => typeof a === `string`)) && age.map(age => ({ _id: age.substring(1).split(`/`).at(-1)! }))) || (age?.length ? null : undefined), - numericAge: (age && (age.every(a => typeof a === `number`)) && age) || (age?.length ? null : undefined), + relativeAge: (age && (age.every(a => typeof a === `string`)) && age.map(age => ({ _id: age.substring(1).split(`/`).at(-1)! }))) || (age === null || age?.length ? null : undefined), + numericAge: (age && (age.every(a => typeof a === `number`)) && age) || (age === null || age?.length ? null : undefined), composition: (composition && composition.map(c => ({ _id: c.substring(1).split(`/`).at(-1)! }))) || undefined, measurements: (measurements && Object.keys(measurements).length > 0 && { count: useEnum(MeasurementCount).valueOf(measurements.count),