Skip to content

Commit

Permalink
fix(signature-colletion): remove candidate if all lists removed (#16425)
Browse files Browse the repository at this point in the history
* fix: remove candidate if all lists removed

* fix: remove candidate if all lists removed make sure has candidate id

* chore: nx format:write update dirty files

* Update libs/clients/signature-collection/src/lib/signature-collection.service.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 16, 2024
1 parent 775afb3 commit 4a5ebba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Collection,
CreateParliamentaryCandidacyInput,
MandateType,
ReasonKey,
SignatureCollectionClientService,
} from '@island.is/clients/signature-collection'
import { errorMessages } from '@island.is/application/templates/signature-collection/parliamentary-list-creation'
Expand Down Expand Up @@ -53,13 +52,11 @@ export class ParliamentaryListCreationService extends BaseTemplateApiService {
405,
)
}
const contactNationalId = isCompany(auth.nationalId)
? auth.actor?.nationalId ?? auth.nationalId
: auth.nationalId
// Candidates are stored on user national id never the actors so should be able to check just the auth national id

if (
currentCollection.candidates.some(
(c) => c.nationalId.replace('-', '') === contactNationalId,
(c) => c.nationalId.replace('-', '') === auth.nationalId,
)
) {
throw new TemplateApiError(errorMessages.alreadyCandidate, 412)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { defineTemplateApi } from '@island.is/application/types'

export const CandidateApi = defineTemplateApi({
action: 'candidate',
order: 0,
})

export const ParliamentaryCollectionApi = defineTemplateApi({
action: 'parliamentaryCollection',
order: 1,
})

export const ParliamentaryIdentityApi = defineTemplateApi({
action: 'parliamentaryIdentity',
order: 2,
})
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const errorMessages = {
},
summary: {
id: 'plc.application:error.alreadyCandidate.summary',
defaultMessage: 'Þú ert nú þegar með framboð',
defaultMessage:
'Þú ert nú þegar með framboð. Þú getur nálgast nánari upplýsingar um þína meðmælasöfnun á Mínum Síðum.',
description: '',
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,21 @@ export class SignatureCollectionClientService {
}),
),
)
// If no lists remain remove Candidate so that they can start a new collection through applications again
await this.checkIfRemoveCandidate(candidate.id, auth)

return { success: true }
}

private async checkIfRemoveCandidate(id: string, auth: User) {
const { ownedLists, candidate } = await this.getSignee(auth)
if ((!ownedLists || ownedLists.length === 0) && candidate?.id) {
await this.getApiWithAuth(this.candidateApi, auth).frambodIDDelete({
iD: parseInt(id),
})
}
}

async getSignedList(auth: User): Promise<SignedList[] | null> {
const { signatures } = await this.getSignee(auth)
const { endTime, isPresidential } = await this.currentCollection()
Expand Down Expand Up @@ -404,7 +416,7 @@ export class SignatureCollectionClientService {
}: CanSignInput): Promise<Success> {
// User is not allowed to have more than one signature
// They are marked as invalid but count as participation
const noInvalidSignature = !signatures?.find((s) => !s.valid) ?? true
const noInvalidSignature = !signatures?.find((s) => !s.valid)

const reasons = mapReasons({
...canSignInfo,
Expand Down

0 comments on commit 4a5ebba

Please sign in to comment.