Skip to content

Commit

Permalink
Merge branch 'main' into feat/ojoi-application-additional-state
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbjarnio authored Oct 25, 2024
2 parents ea4ddfd + 07db7b9 commit 4bd4f2b
Show file tree
Hide file tree
Showing 281 changed files with 4,034 additions and 1,495 deletions.
17 changes: 14 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@ codemagic.yaml
/libs/application/templates/university/ @island-is/origo
/libs/application/template-api-modules/src/lib/modules/templates/university/ @island-is/origo

# Temporary assignment while the QA bootstrap project is in progress
/apps/system-e2e/ @island-is/qa

# DevOps
/.github/ @island-is/devops
/.githooks/ @island-is/devops
Expand All @@ -386,3 +383,17 @@ codemagic.yaml
/scripts/postinstall.js @island-is/devops @island-is/core
/scripts/codegen.js @island-is/devops @island-is/core
/charts/ @island-is/devops


# System tests
# Catch-all
/apps/system-e2e/ @island-is/qa
# Islandis
/apps/system-e2e/src/tests/islandis/admin-portal/ @island-is/aranja
/apps/system-e2e/src/tests/islandis/application-system/ @island-is/norda-applications
/apps/system-e2e/src/tests/islandis/application-system/acceptance/parental-leave.spec.ts @island-is/deloitte
/apps/system-e2e/src/tests/islandis/consultation-portal/ @island-is/advania
/apps/system-e2e/src/tests/islandis/service-portal/ @island-is/hugsmidjan @island-is/juni @island-is/norda-applications
/apps/system-e2e/src/tests/islandis/web/ @island-is/hugsmidjan @island-is/juni @island-is/stefna
# Judicial system
/apps/system-e2e/src/tests/judicial-system/ @island-is/kolibri-justice-league
4 changes: 4 additions & 0 deletions apps/application-system/api/infra/application-system-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const serviceSetup = (services: {
skilavottordWs: ServiceBuilder<'skilavottord-ws'>
// The user profile service is named service-portal-api in infra setup
servicePortalApi: ServiceBuilder<'service-portal-api'>
userNotificationService: ServiceBuilder<'services-user-notification'>
}): ServiceBuilder<'application-system-api'> =>
service('application-system-api')
.namespace(namespace)
Expand Down Expand Up @@ -256,6 +257,9 @@ export const serviceSetup = (services: {
SERVICE_USER_PROFILE_URL: ref(
(h) => `http://${h.svc(services.servicePortalApi)}`,
),
USER_NOTIFICATION_API_URL: ref(
(h) => `http://${h.svc(services.userNotificationService)}`,
),
})
.xroad(
Base,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.changeColumn('payment', 'definition', {
type: Sequelize.TEXT,
allowNull: true,
})
},

down: async (queryInterface, Sequelize) => {
// Check for records that might be truncated
const records = await queryInterface.sequelize.query(
`SELECT id FROM payment WHERE LENGTH(CAST(definition AS TEXT)) > 255`,
)
if (records[0].length > 0) {
throw new Error(
'Cannot safely rollback: Some records exceed STRING length limit',
)
}

await queryInterface.changeColumn('payment', 'definition', {
type: Sequelize.STRING,
allowNull: true,
})
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { setup } from '../../../../../../test/setup'
import { ApplicationLifeCycleService } from '../application-lifecycle.service'
import { ApplicationTypes } from '@island.is/application/types'
import * as utils from '../../utils/application'
import { AwsService } from '@island.is/nest/aws'
import { S3Service } from '@island.is/nest/aws'
import { EmailService } from '@island.is/email-service'
import { ContentfulRepository } from '@island.is/cms'
import { ApplicationLifecycleModule } from '../application-lifecycle.module'
Expand All @@ -18,7 +18,7 @@ import { MockFeatureFlagService } from '../../e2e/mockFeatureFlagService'
let app: INestApplication
let server: request.SuperTest<request.Test>
let lifeCycleService: ApplicationLifeCycleService
let awsService: AwsService
let s3Service: S3Service
const sendMail = () => ({
messageId: 'some id',
})
Expand Down Expand Up @@ -80,9 +80,9 @@ beforeAll(async () => {
lifeCycleService = lifeCycleApp.get<ApplicationLifeCycleService>(
ApplicationLifeCycleService,
)
awsService = app.get<AwsService>(AwsService)
s3Service = app.get<S3Service>(S3Service)

jest.spyOn(awsService, 'deleteObject').mockResolvedValue()
jest.spyOn(s3Service, 'deleteObject').mockResolvedValue()
server = request(app.getHttpServer())
})
describe('ApplicationLifecycleService', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApplicationService } from '@island.is/application/api/core'
import { createApplication } from '@island.is/application/testing'
import { ApplicationWithAttachments as Application } from '@island.is/application/types'
import { AwsService } from '@island.is/nest/aws'
import { S3Service } from '@island.is/nest/aws'
import { TestApp } from '@island.is/testing/nest'

import { setup } from '../../../../../../test/setup'
Expand All @@ -10,7 +10,7 @@ import { ApplicationLifecycleModule } from '../application-lifecycle.module'
import { ApplicationLifeCycleService } from '../application-lifecycle.service'

let lifeCycleService: ApplicationLifeCycleService
let awsService: AwsService
let s3Service: S3Service

export const createApplications = () => {
return [
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('ApplicationLifecycleService Unit tests', () => {
.useClass(ApplicationChargeServiceMock),
})

awsService = app.get<AwsService>(AwsService)
s3Service = app.get<S3Service>(S3Service)
lifeCycleService = app.get<ApplicationLifeCycleService>(
ApplicationLifeCycleService,
)
Expand All @@ -97,7 +97,7 @@ describe('ApplicationLifecycleService Unit tests', () => {
it('should prune answers and prune true.', async () => {
//PREPARE
const deleteObjectSpy = jest
.spyOn(awsService, 'deleteObject')
.spyOn(s3Service, 'deleteObject')
.mockResolvedValue()

//ACT
Expand All @@ -116,7 +116,7 @@ describe('ApplicationLifecycleService Unit tests', () => {
it('should prune answers leave one attachment on exist true.', async () => {
//PREPARE
const deleteObjectSpy = jest
.spyOn(awsService, 'deleteObject')
.spyOn(s3Service, 'deleteObject')
.mockReset()
.mockImplementationOnce(() => {
throw new Error('Error')
Expand All @@ -142,7 +142,7 @@ describe('ApplicationLifecycleService Unit tests', () => {
it('should not remove attachments if deleteObject throws Error.', async () => {
//PREPARE
const deleteObjectSpy = jest
.spyOn(awsService, 'deleteObject')
.spyOn(s3Service, 'deleteObject')
.mockReset()
.mockImplementation(() => {
throw new Error('Error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TemplateAPIConfig,
} from '@island.is/application/template-api-modules'
import { ApplicationService } from '@island.is/application/api/core'
import { AwsService } from '@island.is/nest/aws'
import { S3Service } from '@island.is/nest/aws'
import { ConfigService } from '@nestjs/config'
import jwt from 'jsonwebtoken'
import { uuid } from 'uuidv4'
Expand All @@ -17,7 +17,7 @@ import { uuid } from 'uuidv4'
export class TemplateApiApplicationService extends BaseTemplateApiApplicationService {
constructor(
private readonly applicationService: ApplicationService,
private readonly awsService: AwsService,
private readonly s3Service: S3Service,
@Inject(ConfigService)
private readonly configService: ConfigService<TemplateAPIConfig>,
) {
Expand All @@ -40,7 +40,7 @@ export class TemplateApiApplicationService extends BaseTemplateApiApplicationSer
const fileId = uuid()
const attachmentKey = `${fileId}-${fileName}`
const s3key = `${application.id}/${attachmentKey}`
const url = await this.awsService.uploadFile(
const url = await this.s3Service.uploadFile(
buffer,
{ bucket: uploadBucket, key: s3key },
uploadParameters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Controller, Get, Inject, Query, UseGuards } from '@nestjs/common'
import {
Controller,
Get,
Inject,
Param,
Query,
UseGuards,
} from '@nestjs/common'
import { ApiOkResponse, ApiTags } from '@nestjs/swagger'

import { apiBasePath } from '@island.is/financial-aid/shared/lib'
Expand Down Expand Up @@ -44,4 +51,20 @@ export class OpenApiApplicationController {
state,
)
}

@Get('id/:id')
@ApiOkResponse({
type: ApplicationModel,
description: 'Get application',
})
async getById(
@Param('id') id: string,
@CurrentMunicipalityCode() municipalityCode: string,
) {
this.logger.info(
`Open api Application controller: Getting application by id ${id}`,
)

return this.applicationService.getbyID(municipalityCode, id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,77 @@ export class OpenApiApplicationService {
],
})
}

async getbyID(
municipalityCodes: string,
id: string,
): Promise<ApplicationModel> {
return this.applicationModel.findOne({
where: {
id: id,
municipalityCode: municipalityCodes,
state: {
[Op.or]: [ApplicationState.REJECTED, ApplicationState.APPROVED],
},
},
attributes: {
exclude: [
'staffId',
'applicationSystemId',
'interview',
'homeCircumstances',
'homeCircumstancesCustom',
'employment',
'employmentCustom',
'student',
'studentCustom',
],
},
order: [['modified', 'DESC']],
include: [
{
model: ApplicationFileModel,
as: 'files',
separate: true,
order: [['created', 'DESC']],
attributes: ['key', 'name', 'type'],
},
{
model: StaffModel,
as: 'staff',
attributes: ['name', 'nationalId'],
},
{
model: AmountModel,
as: 'amount',
attributes: [
'aidAmount',
'childrenAidAmount',
'decemberAidAmount',
'income',
'personalTaxCredit',
'tax',
'finalAmount',
'spousePersonalTaxCredit',
],
include: [
{
model: DeductionFactorsModel,
as: 'deductionFactors',
attributes: ['amount', 'description'],
},
],
separate: true,
order: [['created', 'DESC']],
},
{
model: DirectTaxPaymentModel,
as: 'directTaxPayments',
attributes: {
exclude: ['id', 'applicationId', 'created', 'modified'],
},
},
],
})
}
}
21 changes: 20 additions & 1 deletion apps/financial-aid/open-api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Headers, Inject, Query } from '@nestjs/common'
import { Controller, Get, Headers, Inject, Param, Query } from '@nestjs/common'
import { ApiCreatedResponse } from '@nestjs/swagger'

import type { Logger } from '@island.is/logging'
Expand Down Expand Up @@ -34,4 +34,23 @@ export class AppController {
return applications
})
}

@Get('pdf')
@ApiCreatedResponse({
type: [ApplicationBackendModel],
description: 'Gets application',
})
async getPdf(
@Headers('API-Key') apiKey: string,
@Headers('Municipality-Code') municipalityCode: string,
@Query('id') id: string,
): Promise<ApplicationModel> {
this.logger.info('Gets one application and returns pdf')
return this.appService
.getApplication(apiKey, municipalityCode, id)
.then((application) => {
this.logger.info(`Application fetched`)
return application
})
}
}
26 changes: 26 additions & 0 deletions apps/financial-aid/open-api/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,30 @@ export class AppService {
return res.json()
})
}

async getApplication(
apiKey: string,
municipalityCode: string,
id: string,
): Promise<ApplicationModel> {
this.logger.info(
`trying to fetching all applications with municipalityCode ${municipalityCode}`,
id,
)

const url = new URL(
`${this.config.backend.url}/api/financial-aid/open-api-applications/id/${id}`,
)

return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'API-Key': apiKey,
'Municipality-Code': municipalityCode,
},
}).then(async (res) => {
return res.json()
})
}
}
Loading

0 comments on commit 4bd4f2b

Please sign in to comment.