Skip to content

Commit

Permalink
ROCKS-30 Fix resetting,handling age null values
Browse files Browse the repository at this point in the history
  • Loading branch information
patschilf committed Jul 30, 2024
1 parent 50d4541 commit 7b2610e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions app/components/Form/Specimen/Details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions app/server/plugins/specimens/specimen.base.payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 7b2610e

Please sign in to comment.