Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(signature-collection): Fix admin paper signature upload #16500

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -399,4 +403,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],
}
}
}
}
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 @@ -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('')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mutation SignatureCollectionUploadPaperSignature(
$input: SignatureCollectionUploadPaperSignatureInput!
) {
signatureCollectionUploadPaperSignature(input: $input) {
signatureCollectionAdminUploadPaperSignature(input: $input) {
success
reasons
}
Expand Down
Loading