From a11dfa392e05f584e754b34d122354ba8f2ceca5 Mon Sep 17 00:00:00 2001 From: Leonardo Viva Date: Wed, 5 Jun 2024 11:22:59 -0300 Subject: [PATCH] fix: autoNumber duplicating --- src/imports/data/data.js | 44 ++++++---------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/src/imports/data/data.js b/src/imports/data/data.js index 6f94d27..47d4664 100644 --- a/src/imports/data/data.js +++ b/src/imports/data/data.js @@ -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, @@ -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 = {};