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

chore(inao-pp-cem): dataverse check and template-api-module adjustments #16958

Merged
merged 13 commits into from
Nov 22, 2024
Merged
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ codemagic.yaml
/libs/application/template-api-modules/src/lib/modules/templates/general-fishing-license/ @island-is/norda
/libs/application/template-api-modules/src/lib/modules/templates/data-protection-complaint/ @island-is/norda
/libs/shared/form-fields/ @island-is/norda @island-is/island-ui
/libs/clients/financial-statements-inao @island-is/norda

/libs/portals/my-pages/applications/ @island-is/norda-applications
/libs/portals/admin/application-system/ @island-is/norda-applications
Expand Down Expand Up @@ -316,7 +317,6 @@ codemagic.yaml
/apps/services/auth/personal-representative/ @island-is/programm @island-is/aranja
/apps/services/auth/personal-representative-public/ @island-is/programm @island-is/aranja
/libs/api/domains/financial-statements-inao/ @island-is/programm
/libs/clients/financial-statements-inao @island-is/programm
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
/libs/application/templates/financial-statements-inao/ @island-is/programm
/libs/application/template-api-modules/src/lib/modules/templates/financial-statements-inao @island-is/programm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { LOGGER_PROVIDER } from '@island.is/logging'
import {
CemeteryFinancialStatementValues,
FinancialStatementsInaoClientService,
ClientRoles,
} from '@island.is/clients/financial-statements-inao'
import {
ApplicationTypes,
Expand Down Expand Up @@ -36,9 +35,9 @@ export const getCurrentUserType = (
answers: Application['answers'],
externalData: Application['externalData'],
) => {
const fakeUserType: any = getValueViaPath(answers, 'fakeData.options')
const fakeUserType = getValueViaPath<number>(answers, 'fakeData.options')
jonnigs marked this conversation as resolved.
Show resolved Hide resolved

const currentUserType: any = getValueViaPath(
const currentUserType = getValueViaPath<number>(
externalData,
'getUserType.data.value',
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down Expand Up @@ -86,9 +85,7 @@ export class FinancialStatementCemeteryTemplateService extends BaseTemplateApiSe
async getUserType({ auth }: TemplateApiModuleActionProps) {
const { nationalId } = auth
if (kennitala.isPerson(nationalId)) {
return this.financialStatementClientService.getClientType(
ClientRoles.Individual,
)
return null
} else {
return this.financialStatementClientService.getUserClientType(nationalId)
}
Expand All @@ -97,63 +94,51 @@ export class FinancialStatementCemeteryTemplateService extends BaseTemplateApiSe
async submitApplication({ application, auth }: TemplateApiModuleActionProps) {
const { nationalId, actor } = auth
const answers = application.answers
const externalData = application.externalData
const currentUserType = getCurrentUserType(answers, externalData)

// Todo test before this goes live
// if (currentUserType !== FSIUSERTYPE.CEMETRY) {
// throw new Error('Application submission failed')
// }

if (!actor) {
return new Error('Enginn umboðsmaður fannst')
}

const values: CemeteryFinancialStatementValues =
mapValuesToCemeterytype(answers)

const values = this.prepareValues(application)
const client = { nationalId }
const { year, actorsName, contactsAnswer, clientPhone, clientEmail, file } =
getNeededCemeteryValues(answers)

const digitalSignee = mapDigitalSignee(clientEmail, clientPhone)
const fileName = file ? await this.getAttachments(application) : undefined

const client = { nationalId }

const contacts = mapContactsAnswersToContacts(
actor,
actorsName,
contactsAnswer,
)
const digitalSignee = mapDigitalSignee(clientEmail, clientPhone)

const result: DataResponse = await this.financialStatementClientService
.postFinancialStatementForCemetery(
client,
contacts,
digitalSignee,
year,
'',
values,
fileName,
)
.then((data) => {
if (data === true) {
return { success: true }
} else {
return { success: false }
}
})
.catch((e) => {
return {
success: false,
errorMessages: e.message,
}
})

if (!result.success) {
throw new Error('Application submission failed')
try {
const result =
await this.financialStatementClientService.postFinancialStatementForCemetery(
client,
contacts,
digitalSignee,
year,
'',
values,
fileName,
)

if (!result) {
throw new Error('Application submission failed')
}

return { success: true }
} catch (error) {
this.logger.error('Error submitting application', error)
return {
success: false,
message: error.message,
}
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
}
}

return { success: result.success }
private prepareValues(
application: Application,
): CemeteryFinancialStatementValues {
return mapValuesToCemeterytype(application.answers)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export const getCurrentUserType = (
answers: Application['answers'],
externalData: Application['externalData'],
) => {
const fakeUserType = getValueViaPath<number>(answers, 'fakeData.options')
jonnigs marked this conversation as resolved.
Show resolved Hide resolved

const currentUserType = getValueViaPath<number>(
externalData,
'getUserType.data.value',
)

const fakeUserType = getValueViaPath<number>(answers, 'fakeData.options')

return fakeUserType ?? currentUserType
}

Expand Down Expand Up @@ -89,7 +89,7 @@ export class FinancialStatementPoliticalPartyTemplateService extends BaseTemplat
async getUserType({ auth }: TemplateApiModuleActionProps) {
const { nationalId } = auth
if (kennitala.isPerson(nationalId)) {
return this.financialStatementClientService.getClientType('Einstaklingur')
return null
} else {
return this.financialStatementClientService.getUserClientType(nationalId)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { buildForm } from '@island.is/application/core'
import { notAllowedSection } from './notAllowedSection'
import Logo from '../../components/Logo'

export const notAllowedForm = buildForm({
id: 'notAllowedForm',
title: '',
logo: Logo,
children: [notAllowedSection],
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
buildDescriptionField,
buildSection,
} from '@island.is/application/core'
import { m } from '../../lib/messages'

export const notAllowedSection = buildSection({
id: 'notAllowedSection',
title: '',
children: [
buildDescriptionField({
id: 'notAllowedDescription',
title: m.notAllowedTitle,
description: m.notAllowedDescription,
}),
],
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
DefaultStateLifeCycle,
pruneAfterDays,
getValueViaPath,
} from '@island.is/application/core'

import {
ApplicationTemplate,
ApplicationTypes,
Expand All @@ -17,7 +17,6 @@ import {
import { m } from './messages'
import { AuthDelegationType } from '@island.is/shared/types'
import { dataSchema } from './dataSchema'

import {
CurrentUserTypeProvider,
IndentityApiProvider,
Expand All @@ -26,6 +25,7 @@ import {
} from '../dataProviders'
import { ApiActions, Events, Roles, States } from '../types/types'
import { Features } from '@island.is/feature-flags'
import { CEMETERY_USER_TYPE } from '../utils/constants'

const configuration =
ApplicationConfigurations[ApplicationTypes.FINANCIAL_STATEMENT_CEMETERY]
Expand All @@ -50,6 +50,10 @@ const FinancialStatementCemeteryTemplate: ApplicationTemplate<
name: States.PREREQUISITES,
progress: 0,
status: 'draft',
onEntry: defineTemplateApi({
action: ApiActions.getUserType,
shouldPersistToExternalData: true,
}),
actionCard: {
pendingAction: {
title: '',
Expand Down Expand Up @@ -80,6 +84,15 @@ const FinancialStatementCemeteryTemplate: ApplicationTemplate<
UserInfoApi,
],
},
{
id: Roles.NOTALLOWED,
formLoader: () =>
import('../forms/notAllowed').then((val) =>
Promise.resolve(val.notAllowedForm),
),
write: 'all',
delete: true,
},
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
],
},
on: {
Expand Down Expand Up @@ -136,13 +149,18 @@ const FinancialStatementCemeteryTemplate: ApplicationTemplate<
},
},
mapUserToRole(
nationalId: string,
_nationalId: string,
application: Application,
): ApplicationRole | undefined {
if (application.applicant === nationalId) {
const userType = getValueViaPath<number>(
application.externalData,
'getUserType.data.value',
)

if (userType === CEMETERY_USER_TYPE) {
return Roles.APPLICANT
}
return undefined
return Roles.NOTALLOWED
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,16 @@ export const m = defineMessages({
defaultMessage: 'Áfram',
description: 'continue',
},
notAllowedTitle: {
id: 'fsc.application:notAllowedTitle',
defaultMessage:
'Þessi kennitala er ekki skráð sem kirkjugarður hjá Ríkisendurskoðun',
description: 'Title when user is not allowed to apply',
},
notAllowedDescription: {
id: 'fsc.application:notAllowedDescription',
defaultMessage:
'Ef þú telur að þessi kennitala ætti að vera skráð sem kirkjugarður þá bendum við þér á að hafa samband við Ríkisendurskoðun í síma 448 8800',
description: 'Descriptionwhen user is not allowed to apply',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export enum States {

export enum Roles {
APPLICANT = 'applicant',
NOTALLOWED = 'notAllowed',
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const PartiesBackwardLimit = 'PartiesBackwardLimit'
export const CemeteriesBackwardLimit = 'CemeteriesBackwardLimit'
export const PartiesYearAllowed = 'PartiesYearAllowed'
export const CemeteriesYearAllowed = 'CemeteriesYearAllowed'
export const CEMETERY_USER_TYPE = 150000002

// error helpers
export const VALIDATOR = 'validator'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { buildForm } from '@island.is/application/core'
import { notAllowedSection } from './notAllowedSection'
import Logo from '../../components/Logo'

export const notAllowedForm = buildForm({
id: 'notAllowedForm',
title: '',
logo: Logo,
children: [notAllowedSection],
})
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
buildDescriptionField,
buildSection,
} from '@island.is/application/core'
import { m } from '../../lib/messages'

export const notAllowedSection = buildSection({
id: 'notAllowedSection',
title: '',
children: [
buildDescriptionField({
id: 'notAllowedDescription',
title: m.notAllowedTitle,
description: m.notAllowedDescription,
}),
],
})
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading