Skip to content

Commit

Permalink
fix(signature-collection): Fix admin paper signature upload (#16500)
Browse files Browse the repository at this point in the history
* Fix admin paper signature upload

* rename query to match api

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
juni-haukur and kodiakhq[bot] authored Oct 22, 2024
1 parent 11b480a commit f05a38e
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -287,4 +288,13 @@ export class SignatureCollectionAdminResolver {
): Promise<SignatureCollectionSuccess> {
return this.signatureCollectionService.lockList(input, user)
}

@Mutation(() => SignatureCollectionSuccess)
@Audit()
async signatureCollectionAdminUploadPaperSignature(
@CurrentUser() user: User,
@Args('input') input: SignatureCollectionUploadPaperSignatureInput,
): Promise<SignatureCollectionSuccess> {
return this.signatureCollectionService.uploadPaperSignature(input, user)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -243,4 +251,14 @@ export class SignatureCollectionAdminService {
input.listId,
)
}

async uploadPaperSignature(
input: SignatureCollectionUploadPaperSignatureInput,
user: User,
): Promise<SignatureCollectionSuccess> {
return await this.signatureCollectionClientService.uploadPaperSignature(
user,
input,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -423,4 +427,47 @@ export class SignatureCollectionAdminClientService {
return { success: false }
}
}

async uploadPaperSignature(
auth: Auth,
{
listId,
nationalId,
pageNumber,
}: { listId: string; nationalId: string; pageNumber: number },
): Promise<Success> {
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],
}
}
}
}
26 changes: 26 additions & 0 deletions libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MedmaeliBulkResponseDTO } from '../../../gen/fetch'
import { ReasonKey } from '../signature-collection.types'

export interface NationalIds {
nationalId: string
Expand Down Expand Up @@ -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<string>
| undefined
if (list?.includes(nationalId)) {
return [reason]
}
}
return []
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
useSignatureCollectionAdminCanSignInfoQuery,
useIdentityQuery,
} from './identityAndCanSignLookup.generated'
import { useSignatureCollectionUploadPaperSignatureMutation } from './uploadPaperSignee.generated'
import { useSignatureCollectionAdminUploadPaperSignatureMutation } from './uploadPaperSignee.generated'

export const PaperSignees = ({ listId }: { listId: string }) => {
useNamespaces('sp.signatureCollection')
Expand Down Expand Up @@ -61,16 +61,20 @@ export const PaperSignees = ({ listId }: { listId: string }) => {
}, [nationalIdInput, loading, data])

const [uploadPaperSignee, { loading: uploadingPaperSignature }] =
useSignatureCollectionUploadPaperSignatureMutation({
useSignatureCollectionAdminUploadPaperSignatureMutation({
variables: {
input: {
listId: listId,
nationalId: nationalIdInput,
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('')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mutation SignatureCollectionUploadPaperSignature(
mutation SignatureCollectionAdminUploadPaperSignature(
$input: SignatureCollectionUploadPaperSignatureInput!
) {
signatureCollectionUploadPaperSignature(input: $input) {
signatureCollectionAdminUploadPaperSignature(input: $input) {
success
reasons
}
Expand Down

0 comments on commit f05a38e

Please sign in to comment.