From c0b9f4bdfb4ee96803ea6187ec91aa946fc1c5d3 Mon Sep 17 00:00:00 2001 From: MallanagoudaB Date: Thu, 12 Dec 2024 16:28:47 +0530 Subject: [PATCH 1/2] "added-validation-for-bulkCreate" --- src/generics/constants/api-responses.js | 3 +++ src/module/entities/helper.js | 23 ++++++++++++++++++++--- src/module/entityTypes/helper.js | 13 +++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/generics/constants/api-responses.js b/src/generics/constants/api-responses.js index 8af02f1..1344c82 100644 --- a/src/generics/constants/api-responses.js +++ b/src/generics/constants/api-responses.js @@ -56,4 +56,7 @@ module.exports = { USER_ROLE_UPDATED: 'USER_ROLE_UPDATED', USER_ROLE_DELETED: 'USER_ROLE_DELETED', ENTITY_UPDATED: 'ENTITY_UPDATED', + ENTITIES_FAILED: 'Some entities could not be created due to missing required fields.', + ENTITY_TYPE_FAILED: 'Some entity type could not be created due to missing required fields.', + FIELD_MISSING: 'Fields are missing', } diff --git a/src/module/entities/helper.js b/src/module/entities/helper.js index 7b741b8..cb1d13a 100644 --- a/src/module/entities/helper.js +++ b/src/module/entities/helper.js @@ -1265,6 +1265,11 @@ module.exports = class UserProjectsHelper { return _.startsWith(key, '_') }) + if (!entityCreation.metaInformation.name || !entityCreation.metaInformation.externalId) { + entityCreation.status = CONSTANTS.apiResponses.ENTITIES_FAILED + entityCreation.message = CONSTANTS.apiResponses.FIELD_MISSING + return entityCreation + } // if (solutionsData && singleEntity._solutionId && singleEntity._solutionId != '') // singleEntity['createdByProgramId'] = solutionsData[singleEntity._solutionId]['programId'] let newEntity = await entitiesQueries.create(entityCreation) @@ -1274,6 +1279,11 @@ module.exports = class UserProjectsHelper { singleEntity['_SYSTEM_ID'] = newEntity._id.toString() + if (singleEntity._SYSTEM_ID) { + singleEntity.status = CONSTANTS.apiResponses.SUCCESS + singleEntity.message = CONSTANTS.apiResponses.SUCCESS + } + // if ( // solutionsData && // singleEntity._solutionId && @@ -1373,6 +1383,12 @@ module.exports = class UserProjectsHelper { updateData[`metaInformation.${key}`] = columnsToUpdate[key] }) + if (!updateData['metaInformation.name'] || !updateData['metaInformation.externalId']) { + singleEntity.status = CONSTANTS.apiResponses.ENTITIES_FAILED + singleEntity.message = CONSTANTS.apiResponses.FIELD_MISSING + return singleEntity + } + if (Object.keys(updateData).length > 0) { let updateEntity = await entitiesQueries.findOneAndUpdate( { _id: singleEntity['_SYSTEM_ID'] }, @@ -1381,12 +1397,13 @@ module.exports = class UserProjectsHelper { ) if (!updateEntity || !updateEntity._id) { - singleEntity['UPDATE_STATUS'] = CONSTANTS.apiResponses.ENTITY_NOT_FOUND + singleEntity['status'] = CONSTANTS.apiResponses.ENTITY_NOT_FOUND } else { - singleEntity['UPDATE_STATUS'] = CONSTANTS.apiResponses.SUCCESS + singleEntity['status'] = CONSTANTS.apiResponses.SUCCESS + singleEntity['message'] = CONSTANTS.apiResponses.SUCCESS } } else { - singleEntity['UPDATE_STATUS'] = CONSTANTS.apiResponses.NO_INFORMATION_TO_UPDATE + singleEntity['status'] = CONSTANTS.apiResponses.NO_INFORMATION_TO_UPDATE } return singleEntity diff --git a/src/module/entityTypes/helper.js b/src/module/entityTypes/helper.js index fea596a..09eba26 100644 --- a/src/module/entityTypes/helper.js +++ b/src/module/entityTypes/helper.js @@ -86,6 +86,13 @@ module.exports = class UserProjectsHelper { userDetails && userDetails.userInformation.id ? userDetails && userDetails.userInformation.id : CONSTANTS.common.SYSTEM + + if (!entityType.name) { + entityType['_SYSTEM_ID'] = '' + entityType.status = CONSTANTS.apiResponses.ENTITY_TYPE_FAILED + entityType.message = CONSTANTS.apiResponses.FIELD_MISSING + return entityType + } let newEntityType = await entityTypeQueries.create( _.merge( { @@ -296,6 +303,12 @@ module.exports = class UserProjectsHelper { ? userDetails && userDetails.userInformation.id : CONSTANTS.common.SYSTEM + if (!entityType.name) { + entityType['_SYSTEM_ID'] = '' + entityType.status = CONSTANTS.apiResponses.ENTITY_TYPE_FAILED + entityType.message = CONSTANTS.apiResponses.FIELD_MISSING + return entityType + } // Find and update the entityType by _SYSTEM_ID with merged data let updateEntityType = await entityTypeQueries.findOneAndUpdate( { From ef8ce2242353bd23f65877e6559f139e25850aa5 Mon Sep 17 00:00:00 2001 From: MallanagoudaB <162961360+MallanagoudaB@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:00:50 +0530 Subject: [PATCH 2/2] Update api-responses.js --- src/generics/constants/api-responses.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generics/constants/api-responses.js b/src/generics/constants/api-responses.js index 1d69688..7708986 100644 --- a/src/generics/constants/api-responses.js +++ b/src/generics/constants/api-responses.js @@ -55,8 +55,8 @@ module.exports = { USER_ROLE_UPDATED: 'USER_ROLE_UPDATED', USER_ROLE_DELETED: 'USER_ROLE_DELETED', ENTITY_UPDATED: 'ENTITY_UPDATED', - ENTITIES_FAILED: 'Some entities could not be created due to missing required fields.', - ENTITY_TYPE_FAILED: 'Some entity type could not be created due to missing required fields.', + ENTITIES_FAILED: 'The creation of this entities was skipped due to missing required data.', + ENTITY_TYPE_FAILED: 'The creation of this entity type was skipped due to missing required data.', FIELD_MISSING: 'Fields are missing', ENTITY_TYPE_CREATION_FAILED: 'ENTITY TYPE CREATION FAILED',