Skip to content

Commit

Permalink
fix(skilavottord): Improve error handling when creating access and co…
Browse files Browse the repository at this point in the history
…mpanies (#16559)

* TS-931 Fix error handling when creating a new access and companies

* TS-931 Fix error handling when updating  access

* TS-931 Improve the error msg to the user

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
birkirkristmunds and kodiakhq[bot] authored Oct 31, 2024
1 parent f0dd1e4 commit 7adc95a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
6 changes: 6 additions & 0 deletions apps/skilavottord/web/screens/AccessControl/AccessControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ const AccessControl: FC<React.PropsWithChildren<unknown>> = () => {
const [createSkilavottordAccessControl] = useMutation(
CreateSkilavottordAccessControlMutation,
{
onError(_) {
// Hide Runtime error message. The error message is already shown to the user in toast.
},
refetchQueries: [
{
query: SkilavottordAccessControlsQuery,
Expand All @@ -145,6 +148,9 @@ const AccessControl: FC<React.PropsWithChildren<unknown>> = () => {
const [updateSkilavottordAccessControl] = useMutation(
UpdateSkilavottordAccessControlMutation,
{
onError(_) {
// Hide Runtime error message. The error message is already shown to the user in toast.
},
refetchQueries: [
{
query: SkilavottordAccessControlsQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const RecyclingCompanyCreate: FC<React.PropsWithChildren<unknown>> = () => {
const [createSkilavottordRecyclingPartner] = useMutation(
CreateSkilavottordRecyclingPartnerMutation,
{
onError: (_) => {
// Hide Runtime error message. The error message is already shown to the user in toast.
},
refetchQueries: [
{
query: SkilavottordAllRecyclingPartnersQuery,
Expand Down
Original file line number Diff line number Diff line change
@@ -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],
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
)
}

Expand Down

0 comments on commit 7adc95a

Please sign in to comment.