diff --git a/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts b/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts index f2b03a067111..a54a3b6e464c 100644 --- a/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts +++ b/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts @@ -36,6 +36,7 @@ import { SignatureCollectionSignatureUpdateInput } from './dto/signatureUpdate.i import { SignatureCollectionSignatureLookupInput } from './dto/signatureLookup.input' import { SignatureCollectionAreaSummaryReportInput } from './dto/areaSummaryReport.input' import { SignatureCollectionAreaSummaryReport } from './models/areaSummaryReport.model' +import { SignatureCollectionUploadPaperSignatureInput } from './dto/uploadPaperSignature.input' @UseGuards(IdsUserGuard, ScopesGuard) @Scopes(AdminPortalScope.signatureCollectionProcess) @@ -287,4 +288,13 @@ export class SignatureCollectionAdminResolver { ): Promise { return this.signatureCollectionService.lockList(input, user) } + + @Mutation(() => SignatureCollectionSuccess) + @Audit() + async signatureCollectionAdminUploadPaperSignature( + @CurrentUser() user: User, + @Args('input') input: SignatureCollectionUploadPaperSignatureInput, + ): Promise { + return this.signatureCollectionService.uploadPaperSignature(input, user) + } } diff --git a/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts b/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts index 784e81b42f46..020bcb34ee79 100644 --- a/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts +++ b/libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts @@ -25,7 +25,10 @@ import { SignatureCollectionSignatureUpdateInput } from './dto/signatureUpdate.i import { SignatureCollectionSignatureLookupInput } from './dto/signatureLookup.input' import { SignatureCollectionAreaSummaryReportInput } from './dto/areaSummaryReport.input' import { SignatureCollectionAreaSummaryReport } from './models/areaSummaryReport.model' -import { SignatureCollectionListIdInput } from './dto' +import { + SignatureCollectionListIdInput, + SignatureCollectionUploadPaperSignatureInput, +} from './dto' @Injectable() export class SignatureCollectionAdminService { @@ -64,9 +67,14 @@ export class SignatureCollectionAdminService { (signatureSignee.canSignInfo[0] === ReasonKey.AlreadySigned || signatureSignee.canSignInfo[0] === ReasonKey.noInvalidSignature)) + const inArea = list.area.id === signatureSignee.area?.id return { - success: canSign && list.area.id === signatureSignee.area?.id, - reasons: canSign ? [] : signatureSignee.canSignInfo, + success: canSign && inArea, + reasons: canSign + ? inArea + ? [] + : [ReasonKey.NotInArea] + : signatureSignee.canSignInfo, } } @@ -243,4 +251,14 @@ export class SignatureCollectionAdminService { input.listId, ) } + + async uploadPaperSignature( + input: SignatureCollectionUploadPaperSignatureInput, + user: User, + ): Promise { + return await this.signatureCollectionClientService.uploadPaperSignature( + user, + input, + ) + } } diff --git a/libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts b/libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts index 37522bfc51cf..362eb0eb512f 100644 --- a/libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts +++ b/libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts @@ -16,7 +16,11 @@ import { } from './types/list.dto' import { Signature, mapSignature } from './types/signature.dto' import { CandidateLookup } from './types/user.dto' -import { BulkUpload, mapBulkResponse } from './types/bulkUpload.dto' +import { + BulkUpload, + getReasonKeyForPaperSignatureUpload, + mapBulkResponse, +} from './types/bulkUpload.dto' import { Success } from './types/success.dto' import { mapCandidate } from './types/candidate.dto' import { Slug } from './types/slug.dto' @@ -399,4 +403,47 @@ export class SignatureCollectionAdminClientService { return { success: false } } } + + async uploadPaperSignature( + auth: Auth, + { + listId, + nationalId, + pageNumber, + }: { listId: string; nationalId: string; pageNumber: number }, + ): Promise { + try { + const signature = await this.getApiWithAuth( + this.adminApi, + auth, + ).adminMedmaelalistiIDMedmaeliBulkPost({ + medmaeliBulkRequestDTO: { + medmaeli: [ + { + kennitala: nationalId, + bladsida: pageNumber, + }, + ], + }, + iD: parseInt(listId), + }) + + const success = !!( + signature.medmaeliKenn?.includes(nationalId) || + signature.medMedmaeliAnnarListi?.includes(nationalId) + ) + + return { + success, + reasons: success + ? [] + : getReasonKeyForPaperSignatureUpload(signature, nationalId), + } + } catch { + return { + success: false, + reasons: [ReasonKey.DeniedByService], + } + } + } } diff --git a/libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts b/libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts index e0d8d2341896..50a89ad568fa 100644 --- a/libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts +++ b/libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts @@ -1,4 +1,5 @@ import { MedmaeliBulkResponseDTO } from '../../../gen/fetch' +import { ReasonKey } from '../signature-collection.types' export interface NationalIds { nationalId: string @@ -48,3 +49,28 @@ export const mapBulkResponse = ( })) ?? []), ], }) + +export const getReasonKeyForPaperSignatureUpload = ( + bulkResponse: MedmaeliBulkResponseDTO, + nationalId: string, +): ReasonKey[] => { + const listMapping: { [key in keyof MedmaeliBulkResponseDTO]?: ReasonKey } = { + notFound: ReasonKey.notFound, + undirAldri: ReasonKey.UnderAge, + ekkiIsRik: ReasonKey.NoCitizenship, + ekkiBuseta: ReasonKey.NotISResidency, + ekkiASvaedi: ReasonKey.NotInArea, + medMedmaeliALista: ReasonKey.AlreadySigned, + medMedmaeliAnnarListi: ReasonKey.noInvalidSignature, + } + + for (const [key, reason] of Object.entries(listMapping)) { + const list = bulkResponse[key as keyof MedmaeliBulkResponseDTO] as + | Array + | undefined + if (list?.includes(nationalId)) { + return [reason] + } + } + return [] +} diff --git a/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx b/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx index e7dad47c52cf..3d18a52e8158 100644 --- a/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx +++ b/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx @@ -69,8 +69,12 @@ export const PaperSignees = ({ listId }: { listId: string }) => { pageNumber: Number(page), }, }, - onCompleted: () => { - toast.success(formatMessage(m.paperSigneeSuccess)) + onCompleted: (res) => { + if (res.signatureCollectionAdminUploadPaperSignature?.success) { + toast.success(formatMessage(m.paperSigneeSuccess)) + } else { + toast.error(formatMessage(m.paperSigneeError)) + } reset() setNationalIdTypo(false) setName('') diff --git a/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql b/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql index d06c5c01131f..c1a1a3c36b48 100644 --- a/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql +++ b/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql @@ -1,7 +1,7 @@ mutation SignatureCollectionUploadPaperSignature( $input: SignatureCollectionUploadPaperSignatureInput! ) { - signatureCollectionUploadPaperSignature(input: $input) { + signatureCollectionAdminUploadPaperSignature(input: $input) { success reasons }