Skip to content

Commit

Permalink
fix: autoNumber duplicating
Browse files Browse the repository at this point in the history
  • Loading branch information
7sete7 committed Jun 5, 2024
1 parent 78df70c commit a11dfa3
Showing 1 changed file with 6 additions and 38 deletions.
44 changes: 6 additions & 38 deletions src/imports/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,12 @@ export async function create({ authTokenId, document, data, contextUser, upsert,
tracingSpan?.addEvent('Validate&processValueFor all fields');
const validateAllFieldsResult = await BluebirdPromise.mapSeries(Object.keys(metaObject.fields), async key => {
const value = cleanedData[key];
const field = metaObject.fields[key];

if (field.type === 'autoNumber' && (ignoreAutoNumber || value != null)) {
return successReturn();
}

const result = await validateAndProcessValueFor({
meta: metaObject,
fieldName: key,
Expand Down Expand Up @@ -704,44 +710,6 @@ export async function create({ authTokenId, document, data, contextUser, upsert,
}
}

tracingSpan?.addEvent('Processing autoNumber');
const autoNumberResult = await BluebirdPromise.mapSeries(Object.keys(metaObject.fields), async key => {
const field = metaObject.fields[key];
if (field.type === 'autoNumber') {
const value = get(data, key);

if (ignoreAutoNumber !== true || value == null) {
const autoNumberResult = await validateAndProcessValueFor({
meta: metaObject,
fieldName: key,
value,
actionType: 'insert',
objectOriginalValues: data,
objectNewValues: cleanedData,
});

if (autoNumberResult.success === false) {
return autoNumberResult;
}
if (autoNumberResult.data != null) {
cleanedData[key] = autoNumberResult.data;
}
} else {
cleanedData[key] = value;
}
}
return successReturn();
});

if (autoNumberResult.some(result => result.success === false)) {
return errorReturn(
autoNumberResult
.filter(result => result.success === false)
.map(result => result.errors)
.flat(),
);
}

if (Object.keys(cleanedData).length > 0) {
const insertedQuery = {};

Expand Down

0 comments on commit a11dfa3

Please sign in to comment.