diff --git a/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx b/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx index aee25f9c033a..9f274e15eb52 100644 --- a/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx +++ b/apps/skilavottord/web/screens/AccessControl/AccessControl.tsx @@ -135,6 +135,9 @@ const AccessControl: FC> = () => { const [createSkilavottordAccessControl] = useMutation( CreateSkilavottordAccessControlMutation, { + onError(_) { + // Hide Runtime error message. The error message is already shown to the user in toast. + }, refetchQueries: [ { query: SkilavottordAccessControlsQuery, @@ -145,6 +148,9 @@ const AccessControl: FC> = () => { const [updateSkilavottordAccessControl] = useMutation( UpdateSkilavottordAccessControlMutation, { + onError(_) { + // Hide Runtime error message. The error message is already shown to the user in toast. + }, refetchQueries: [ { query: SkilavottordAccessControlsQuery, diff --git a/apps/skilavottord/web/screens/RecyclingCompanies/RecyclingCompanyCreate/RecyclingCompanyCreate.tsx b/apps/skilavottord/web/screens/RecyclingCompanies/RecyclingCompanyCreate/RecyclingCompanyCreate.tsx index 20908b593766..a3d6c84b134e 100644 --- a/apps/skilavottord/web/screens/RecyclingCompanies/RecyclingCompanyCreate/RecyclingCompanyCreate.tsx +++ b/apps/skilavottord/web/screens/RecyclingCompanies/RecyclingCompanyCreate/RecyclingCompanyCreate.tsx @@ -50,6 +50,9 @@ const RecyclingCompanyCreate: FC> = () => { const [createSkilavottordRecyclingPartner] = useMutation( CreateSkilavottordRecyclingPartnerMutation, { + onError: (_) => { + // Hide Runtime error message. The error message is already shown to the user in toast. + }, refetchQueries: [ { query: SkilavottordAllRecyclingPartnersQuery, diff --git a/apps/skilavottord/ws/src/app/modules/accessControl/accessControl.resolver.ts b/apps/skilavottord/ws/src/app/modules/accessControl/accessControl.resolver.ts index 666861e944ca..61dffa84992a 100644 --- a/apps/skilavottord/ws/src/app/modules/accessControl/accessControl.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/accessControl/accessControl.resolver.ts @@ -1,16 +1,20 @@ -import { Query, Resolver, Args, Mutation } from '@nestjs/graphql' -import { NotFoundException, BadRequestException } from '@nestjs/common' +import { + BadRequestException, + ConflictException, + NotFoundException, +} from '@nestjs/common' +import { Args, Mutation, Query, Resolver } from '@nestjs/graphql' import { ApolloError } from 'apollo-server-express' -import { Authorize, CurrentUser, User, Role } from '../auth' +import { Authorize, CurrentUser, Role, User } from '../auth' -import { AccessControlModel } from './accessControl.model' -import { AccessControlService } from './accessControl.service' import { - UpdateAccessControlInput, CreateAccessControlInput, DeleteAccessControlInput, + UpdateAccessControlInput, } from './accessControl.input' +import { AccessControlModel } from './accessControl.model' +import { AccessControlService } from './accessControl.service' @Authorize({ roles: [Role.developer, Role.recyclingFund, Role.recyclingCompanyAdmin], @@ -77,6 +81,15 @@ export class AccessControlResolver { this.verifyDeveloperAccess(user, input.role) this.verifyRecyclingCompanyAdminInput(input.role, user) this.verifyRecyclingCompanyInput(input) + + const access = await this.accessControlService.findOne(input.nationalId) + + if (access) { + throw new ConflictException( + `Access with the national id ${input.nationalId} already exists`, + ) + } + return this.accessControlService.createAccess(input) } diff --git a/apps/skilavottord/ws/src/app/modules/recyclingPartner/recyclingPartner.resolver.ts b/apps/skilavottord/ws/src/app/modules/recyclingPartner/recyclingPartner.resolver.ts index 9efc48c9c865..66fb91a354a4 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingPartner/recyclingPartner.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingPartner/recyclingPartner.resolver.ts @@ -56,7 +56,7 @@ export class RecyclingPartnerResolver { if (recyclingPartner) { throw new ConflictException( - 'Recycling partner with that id already exists', + `Recycling partner with the id ${input.companyId} already exists`, ) }