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

feat(application-plc): Procuration #15945

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -10,6 +10,10 @@ import { BaseTemplateAPIModuleConfig } from '../../../../types'
// Here you import your module service
import { ParliamentaryListCreationService } from './parliamentary-list-creation.service'
import { SignatureCollectionClientModule } from '@island.is/clients/signature-collection'
import {
NationalRegistryClientModule,
NationalRegistryClientService,
} from '@island.is/clients/national-registry-v2'

export class ParliamentaryListCreationModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
Expand All @@ -18,8 +22,12 @@ export class ParliamentaryListCreationModule {
imports: [
SharedTemplateAPIModule.register(config),
SignatureCollectionClientModule,
NationalRegistryClientModule,
],
providers: [
ParliamentaryListCreationService,
NationalRegistryClientService,
],
providers: [ParliamentaryListCreationService],
exports: [ParliamentaryListCreationService],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ import { LOGGER_PROVIDER } from '@island.is/logging'
import { CollectionType } from '@island.is/clients/signature-collection'
import { CreateListSchema } from '@island.is/application/templates/signature-collection/parliamentary-list-creation'
import { FetchError } from '@island.is/clients/middlewares'
import { NationalRegistryClientService } from '@island.is/clients/national-registry-v2'
import { isCompany } from 'kennitala'
import { coreErrorMessages } from '@island.is/application/core'

@Injectable()
export class ParliamentaryListCreationService extends BaseTemplateApiService {
constructor(
@Inject(LOGGER_PROVIDER) private logger: Logger,
private readonly _sharedTemplateAPIService: SharedTemplateApiService,
private signatureCollectionClientService: SignatureCollectionClientService,
private nationalRegisryClientService: NationalRegistryClientService,
) {
super(ApplicationTypes.PARLIAMENTARY_LIST_CREATION)
}
Expand Down Expand Up @@ -53,13 +57,37 @@ export class ParliamentaryListCreationService extends BaseTemplateApiService {
return currentCollection
}

async parliamentaryIdentity({ auth }: TemplateApiModuleActionProps) {
const contactNationalId = isCompany(auth.nationalId)
? auth.actor?.nationalId ?? auth.nationalId
: auth.nationalId

const identity = await this.nationalRegisryClientService.getIndividual(
contactNationalId,
)

if (!identity) {
throw new TemplateApiError(
coreErrorMessages.nationalIdNotFoundInNationalRegistrySummary,
500,
)
}

return identity
}

async submit({ application, auth }: TemplateApiModuleActionProps) {
const answers = application.answers as CreateListSchema
const parliamentaryCollection = application.externalData
.parliamentaryCollection.data as Collection

const input: CreateParliamentaryCandidacyInput = {
owner: answers.applicant,
owner: {
...answers.applicant,
nationalId: application?.applicantActors?.[0]
? application.applicant
: answers.applicant.nationalId,
},
agents: (answers.managers ?? [])
.map((manager) => ({
nationalId: manager.manager.nationalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const CandidateApi = defineTemplateApi({
export const ParliamentaryCollectionApi = defineTemplateApi({
action: 'parliamentaryCollection',
})

export const ParliamentaryIdentityApi = defineTemplateApi({
action: 'parliamentaryIdentity',
})
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const Draft: Form = buildForm({
width: 'half',
readOnly: true,
defaultValue: ({ externalData }: Application) => {
return externalData.nationalRegistry?.data.fullName
return externalData.parliamentaryIdentity?.data.fullName
},
}),
buildTextField({
Expand All @@ -103,7 +103,9 @@ export const Draft: Form = buildForm({
width: 'half',
readOnly: true,
defaultValue: (application: Application) =>
formatNationalId(application.applicant),
application?.applicantActors[0]
? formatNationalId(application?.applicantActors[0])
: formatNationalId(application.applicant),
}),
buildPhoneField({
id: 'applicant.phone',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {

import { m } from '../lib/messages'
import Logo from '../../assets/Logo'
import { ParliamentaryCollectionApi, CandidateApi } from '../dataProviders'
import {
ParliamentaryCollectionApi,
CandidateApi,
ParliamentaryIdentityApi,
} from '../dataProviders'

export const Prerequisites: Form = buildForm({
id: 'CreateListPrerequisites',
Expand Down Expand Up @@ -73,17 +77,12 @@ export const Prerequisites: Form = buildForm({
subTitle: m.userProfileProviderSubtitle,
}),
buildDataProviderItem({
provider: NationalRegistryUserApi,
title: m.nationalRegistryProviderTitle,
subTitle: m.nationalRegistryProviderSubtitle,
}),
buildDataProviderItem({
//provider: TODO: Add providers needed for creating collection,
provider: ParliamentaryCollectionApi,
title: '',
subTitle: '',
}),
buildDataProviderItem({
provider: ParliamentaryCollectionApi,
provider: ParliamentaryIdentityApi,
title: '',
subTitle: '',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { dataSchema } from './dataSchema'
import { m } from './messages'
import { EphemeralStateLifeCycle } from '@island.is/application/core'
import { Features } from '@island.is/feature-flags'
import { ParliamentaryCollectionApi, CandidateApi } from '../dataProviders'
import {
ParliamentaryCollectionApi,
CandidateApi,
ParliamentaryIdentityApi,
} from '../dataProviders'
import { AuthDelegationType } from '@island.is/shared/types'

const WeekLifeCycle: StateLifeCycle = {
Expand Down Expand Up @@ -76,6 +80,7 @@ const createListTemplate: ApplicationTemplate<
UserProfileApi,
CandidateApi,
ParliamentaryCollectionApi,
ParliamentaryIdentityApi,
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,9 @@ export class SignatureCollectionClientService {
throw new Error('Collection is not open')
}

// check if user is sending in their own nationalId
if (owner.nationalId.replace(/\D/g, '') !== auth.nationalId) {
// TODO: create ApplicationTemplateError
throw new Error('NationalId does not match')
}
// check if user is already owner of lists

const { canCreate, isOwner, name, partyBallotLetterInfo } =
await this.getSignee(auth)
const { canCreate, isOwner, partyBallotLetterInfo } = await this.getSignee(
auth,
)
if (!canCreate || isOwner) {
// TODO: create ApplicationTemplateError
throw new Error('User is already owner of lists')
Expand Down