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(AOSH): Fixing a few minor bugs on AOSH applications #14898

Merged
merged 6 commits into from
May 24, 2024
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 @@ -69,7 +69,6 @@ export const generateApplicationRejectedEmail: ApplicationRejectedEmail = (
`<span>Beiðni um eigendaskipti á tækinu ${regNumber} hefur verið afturkölluð þar sem eftirfarandi aðilar staðfestu ekki:</span><br/>` +
`<ul><li><p>${rejectedByStr}</p></li></ul>` +
`<span>Til þess að skrá eigendaskiptin rafrænt verður að byrja ferlið að upp á nýtt á umsóknarvef island.is: island.is/umsoknir, ásamt því að allir aðilar þurfa að staðfesta rafrænt innan gefins tímafrests.</span><br/>` +
`<span>Þessi tilkynning á aðeins við um rafræna umsókn af umsóknarvef island.is en ekki um eigendaskipti sem skilað hefur verið inn til Vinnueftirlitsins á pappír.</span><br/>` +
`<span>Vinsamlegast hafið samband við Vinnueftirlitið [email protected] ef nánari upplýsinga er þörf.</span>`,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,9 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
async submitApplication({
application,
auth,
currentUserLocale,
}: TemplateApiModuleActionProps): Promise<void> {
// Validate payment
// Make sure a paymentUrl was created
const { paymentUrl } = application.externalData.createCharge.data as {
paymentUrl: string
}
if (!paymentUrl) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}

// Make sure payment is fulfilled (has been paid)
const payment: { fulfilled: boolean } | undefined =
await this.sharedTemplateAPIService.getPaymentStatus(auth, application.id)
if (!payment?.fulfilled) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}
await this.handlePayment({ application, auth, currentUserLocale })

// Confirm owner change in AOSH
const answers = application.answers as TransferOfMachineOwnershipAnswers
Expand Down Expand Up @@ -141,9 +124,10 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
generateApplicationSubmittedEmail(props, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending email about submit application to ${recipientList[i].email}`,
e,
)
})
}
Expand All @@ -155,9 +139,10 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
generateApplicationSubmittedSms(application, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending sms about submit application to ${recipientList[i].phone}`,
e,
)
})
}
Expand All @@ -166,32 +151,22 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
async initReview({
application,
auth,
currentUserLocale,
}: TemplateApiModuleActionProps): Promise<Array<EmailRecipient>> {
// 1. Validate payment

// 1a. Make sure a paymentUrl was created
const { paymentUrl, id: paymentId } = application.externalData.createCharge
.data as {
paymentUrl: string
id: string
}
const answers = application.answers as TransferOfMachineOwnershipAnswers

if (!paymentUrl) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}

// 1b. Make sure payment is fulfilled (has been paid)
const payment: { fulfilled: boolean } | undefined =
await this.sharedTemplateAPIService.getPaymentStatus(auth, application.id)
if (!payment?.fulfilled) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
if (
answers.machine.paymentRequiredForOwnerChange &&
application.state === 'draft'
) {
return []
}
const paymentId = await this.handlePayment({
application,
auth,
currentUserLocale,
})

const answers = application.answers as TransferOfMachineOwnershipAnswers
const machineId = answers.machine.id || answers.pickMachine.id
if (!machineId) {
throw new Error('Ekki er búið að velja vél')
Expand Down Expand Up @@ -221,9 +196,10 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
(props) => generateRequestReviewEmail(props, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending email about initReview to ${recipientList[i].email}`,
e,
)
})
}
Expand All @@ -235,16 +211,57 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
generateRequestReviewSms(application, options, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending sms about initReview to ${recipientList[i].phone}`,
e,
)
})
}
}

return recipientList
}

private async handlePayment({
application,
auth,
}: TemplateApiModuleActionProps): Promise<string | null> {
const answers = application.answers as TransferOfMachineOwnershipAnswers

if (answers.machine.paymentRequiredForOwnerChange) {
// 1. Validate payment

// 1a. Make sure a paymentUrl was created

const { paymentUrl = '', id: paymentId = '' } = (application.externalData
?.createCharge?.data ?? {}) as {
paymentUrl: string
id: string
}

if (!paymentUrl) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}

// 1b. Make sure payment is fulfilled (has been paid)
const payment: { fulfilled: boolean } | undefined =
await this.sharedTemplateAPIService.getPaymentStatus(
auth,
application.id,
)
if (!payment?.fulfilled) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}
return paymentId
}
return null
}

async rejectApplication({
application,
auth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ export const machineSubSection = buildSubSection({
return machine?.plate || ''
},
}),
buildDateField({
id: 'machine.date',
title: information.labels.machine.date,
required: false,
width: 'half',
maxDate: new Date(),
minDate: () => {
const minDate = new Date()
minDate.setDate(minDate.getDate() - 7)
return minDate
},
defaultValue: new Date().toISOString().substring(0, 10),
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const pickMachineSubSection = buildSubSection({
description: information.labels.pickMachine.description,
children: [
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: information.labels.pickMachine.title,
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
davidkef marked this conversation as resolved.
Show resolved Hide resolved
const machinesWithTotal = getValueViaPath(
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const pickMachineSubSection = buildSubSection({
description: information.labels.pickMachine.description,
children: [
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: information.labels.pickMachine.title,
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
const machines = getValueViaPath(
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
const machinesWithTotal = getValueViaPath(
davidkef marked this conversation as resolved.
Show resolved Hide resolved
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount
return machines.machines.find((machine) => machine.id === machineId)

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"extract-strings": {
"executor": "nx:run-commands",
"options": {
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/application/templates/aosh/request-for-inspection1/src/**/*.{js,ts,tsx}'"
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/application/templates/aosh/request-for-inspection/src/**/*.{js,ts,tsx}'"
}
},
"test": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const pickMachineSubSection = buildSubSection({
alertType: 'info',
}),
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: information.labels.pickMachine.title,
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const conclusion = {
description: 'Conclusion seller alert message',
},
alertTitle: {
id: 'aosh.rifm.application:conclusion.default.alertMessage',
id: 'aosh.rifm.application:conclusion.default.alertTitle',
defaultMessage: 'Beiðni um skoðun á tæki hefur verið móttekin!',
description: 'Conclusion seller alert title',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
davidkef marked this conversation as resolved.
Show resolved Hide resolved
const machinesWithTotal = getValueViaPath(
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const pickMachineSubSection = buildSubSection({
description: information.labels.pickMachine.description,
children: [
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: '',
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
const machines = getValueViaPath(
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
const machinesWithTotal = getValueViaPath(
davidkef marked this conversation as resolved.
Show resolved Hide resolved
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount
return machines.machines.find((machine) => machine.id === machineId)

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}

export const mustInspectBeforeStreetRegistration = (
Expand Down
Loading
Loading