From 0583cccc0777ff55892c792b439fef6702c8976b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 14 Aug 2024 19:26:06 +1000 Subject: [PATCH] fix: check if user has attributes before accessing attributes --- .../src/resources/organization/resolvers.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index a453529482..be7778c56d 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -391,20 +391,22 @@ export const getUsersByOrganizationId: ResolverFn = async ( groupMembers[member].user.owner = false groupMembers[member].user.admin = false groupMembers[member].user.comment = null - if (groupMembers[member].user.attributes["comment"]) { - groupMembers[member].user.comment = groupMembers[member].user.attributes["comment"][0] - } - if (groupMembers[member].user.attributes["lagoon-organizations"]) { - for (const a in groupMembers[member].user.attributes["lagoon-organizations"]) { - if (parseInt(groupMembers[member].user.attributes["lagoon-organizations"][a]) == args.organization) { - groupMembers[member].user.owner = true + if (groupMembers[member].user.attributes) { + if (groupMembers[member].user.attributes["comment"]) { + groupMembers[member].user.comment = groupMembers[member].user.attributes["comment"][0] + } + if (groupMembers[member].user.attributes["lagoon-organizations"]) { + for (const a in groupMembers[member].user.attributes["lagoon-organizations"]) { + if (parseInt(groupMembers[member].user.attributes["lagoon-organizations"][a]) == args.organization) { + groupMembers[member].user.owner = true + } } } - } - if (groupMembers[member].user.attributes["lagoon-organizations-admin"]) { - for (const a in groupMembers[member].user.attributes["lagoon-organizations-admin"]) { - if (parseInt(groupMembers[member].user.attributes["lagoon-organizations-admin"][a]) == args.organization) { - groupMembers[member].user.admin = true + if (groupMembers[member].user.attributes["lagoon-organizations-admin"]) { + for (const a in groupMembers[member].user.attributes["lagoon-organizations-admin"]) { + if (parseInt(groupMembers[member].user.attributes["lagoon-organizations-admin"][a]) == args.organization) { + groupMembers[member].user.admin = true + } } } }