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(university-application): file uploads added to service #15056

Merged
merged 9 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -106,10 +106,17 @@ class CreateApplicationFileDto {

@IsString()
@ApiProperty({
description: 'Base 64 for file',
description: 'File type',
example: 'profskirteini',
})
fileType!: string

@IsString()
@ApiProperty({
description: 'Blob for file',
example: '',
})
base64!: string
blob!: Blob
}

class CreateApplicationEducationDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export class UniversityApplicationService {
)
}

const allAttachments = applicationDto.educationList
.map((x) => x.degreeAttachments)
.filter((y) => !!y)
.flat()

// Wrap answers in obj that can be sent to libs/clients for universities
const applicationObj: IApplication = {
id: applicationDto.applicationId,
Expand Down Expand Up @@ -116,6 +121,7 @@ export class UniversityApplicationService {
educationOption: applicationDto.educationOption,
workExperienceList: applicationDto.workExperienceList,
extraFieldList: applicationDto.extraFieldList,
attachments: allAttachments,
}

// Create application in our DB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,26 @@ export class SharedTemplateApiService {
const fileContent = file.Body as Buffer
return fileContent?.toString('base64') || ''
}

async getAttachmentContentAsBlob(
application: ApplicationWithAttachments,
attachmentKey: string,
): Promise<Blob> {
const fileName = (
application.attachments as {
[key: string]: string
}
)[attachmentKey]
const { bucket, key } = AmazonS3URI(fileName)
const uploadBucket = bucket
const file = await this.s3
.getObject({
Bucket: uploadBucket,
Key: key,
})
.promise()
const fileContent = file.Body as Buffer
const blob: Blob = new Blob([fileContent], { type: 'multipart/form-data' })
return blob
}
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ export class UniversityService extends BaseTemplateApiService {
? {
degreeAttachments: await this.getFilesFromAttachment(
application,
answers.educationDetails.exemptionDetails?.degreeAttachments,
answers.educationDetails.exemptionDetails?.degreeAttachments?.map(
(x, i) => {
const type = this.mapFileTypes(i)
return {
name: x.name,
key: x.key,
type: type,
}
},
),
),
moreDetails: answers.educationDetails.exemptionDetails?.moreDetails,
}
Expand All @@ -160,7 +169,16 @@ export class UniversityService extends BaseTemplateApiService {
answers.educationDetails.thirdLevelDetails?.moreDetails,
degreeAttachments: await this.getFilesFromAttachment(
application,
answers.educationDetails.thirdLevelDetails?.degreeAttachments,
answers.educationDetails.thirdLevelDetails?.degreeAttachments?.map(
(x, i) => {
const type = this.mapFileTypes(i)
return {
name: x.name,
key: x.key,
type: type,
}
},
),
),
}
: undefined
Expand All @@ -171,7 +189,14 @@ export class UniversityService extends BaseTemplateApiService {
...item,
degreeAttachments: await this.getFilesFromAttachment(
application,
item.degreeAttachments,
item.degreeAttachments?.map((x, i) => {
const type = this.mapFileTypes(i)
return {
name: x.name,
key: x.key,
type: type,
}
}),
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
),
}
})) ||
Expand Down Expand Up @@ -233,20 +258,39 @@ export class UniversityService extends BaseTemplateApiService {

private async getFilesFromAttachment(
application: ApplicationWithAttachments,
attachments?: { name: string; key: string }[],
): Promise<{ fileName: string; base64: string }[]> {
attachments?: { name: string; key: string; type: string }[],
): Promise<{ fileName: string; fileType: string; blob: Blob }[]> {
return await Promise.all(
attachments?.map(async (file) => {
const base64 =
await this.sharedTemplateAPIService.getAttachmentContentAsBase64(
const blob =
await this.sharedTemplateAPIService.getAttachmentContentAsBlob(
application,
file.key,
)
return {
fileName: file.name,
base64,
fileType: file.type,
blob,
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
}
}) || [],
)
}

private mapFileTypes = (fileIndex: number): string => {
let type
switch (fileIndex) {
case 1:
type = 'profskirteini'
break
case 2:
type = 'profskirteini2'
break
case 3:
type = 'profskirteini3'
break
default:
type = ''
}
return type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const SummaryBlock = ({ children, editAction }: Props) => {
borderColor="blue300"
>
<Box width="full">{children}</Box>
<Button
{/* <Button
icon="pencil"
iconType="filled"
variant="utility"
onClick={editAction}
>
{formatMessage(review.labels.changeButtonText)}
</Button>
</Button> */}
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
</Box>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export const DetailsRepeaterItem: FC<DetailsRepeaterItemProps> = ({

{!readOnly && (
<FileUploadController
id={degreeAttachmentsField}
id={degreeAttachmentsField} //profskirteini, profskirteini2, profskirteini3
application={application}
multiple
header={formatMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ProgramReview: FC<Props> = ({
const answers = application.answers as UniversityApplication

return (
<Box paddingBottom={4}>
<Box paddingBottom={4} paddingTop={4}>
<Box></Box>
<GridRow>
<GridColumn span="1/2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const FormerEducationSection = buildSection({
NotFinishedEducationSubSection,
ThirdLevelEducationSubSection,
ExemptionSubSection,
OtherDocumentsSection,
// OtherDocumentsSection, //TODO replace again when there are some programs that request otherDocuments
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
],
})
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,40 @@ paths:
type: 'string'
required:
type: 'boolean'
extraApplicationTexts:
extraApplicationTextsIs:
type: 'object'
properties:
toptextIs:
type: 'string'
sociallifeIs:
type: 'string'
forYouIs:
type: 'string'
exchangeStudyIs:
type: 'string'
workIs:
type: 'string'
aboutIs:
type: 'string'
items:
type: 'object'
properties:
toptext:
type: 'string'
sociallife:
type: 'string'
forYou:
type: 'string'
exchangeStudy:
type: 'string'
work:
type: 'string'
about:
type: 'string'
extraApplicationTextsEn:
type: 'object'
items:
type: 'object'
properties:
toptext:
type: 'string'
sociallife:
type: 'string'
forYou:
type: 'string'
exchangeStudy:
type: 'string'
work:
type: 'string'
about:
type: 'string'
kjorsvid:
type: 'array'
items:
Expand Down Expand Up @@ -494,6 +513,45 @@ paths:
description: 'Application ID'
tags:
- 'Application'
/applications/attachments/{guid}:
post:
parameters:
- name: guid
required: true
in: path
allowEmptyValue: false
description: Application ID
schema:
type: string
format: uuid
summary: Submit an applications accompanying documents
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
attachment:
type: string
format: binary
attachmentKey:
$ref: '#/components/schemas/AttachmentKey'
responses:
'200':
description: Successful submission
content:
application/json:
schema:
type: object
properties:
id:
type: string
description: Attachment ID
'400':
description: Bad Request - No application with given ID
tags:
- Application
/openapi.yaml:
get:
operationId: 'InfraController_openapi'
Expand Down Expand Up @@ -590,6 +648,23 @@ components:
- 'universityId'
- 'programId'
- 'modeOfDelivery'
AttachmentKey:
type: string
enum:
- cv
- markmid
- rannsoknaraaetlun
- namsaaetlun
- rannsoknarverkefni
- profskirteini
- profskirteini2
- profskirteini3
- onnur_skjol
- kynningarbref
- ferilsskra
- leyfisbref
- portofolio
- sakavottord
UpdateApplicationDto:
type: 'object'
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { logger } from '@island.is/logging'
import { mapUglaPrograms } from './utils/mapUglaPrograms'
import { mapUglaCourses } from './utils/mapUglaCourses'
import { mapUglaApplication } from './utils/mapUglaApplication'
import { InlineResponse2004 } from '../../gen/fetch'
import { AttachmentKey, InlineResponse2004 } from '../../gen/fetch'

@Injectable()
export class UniversityOfIcelandApplicationClient {
Expand Down Expand Up @@ -73,6 +73,20 @@ export class UniversityOfIcelandApplicationClient {
const response = await this.applicationApi.applicationsPost(
mappedApplication,
)

application.attachments?.filter(Boolean).forEach(async (attachment) => {
const attachmentKey = attachment?.fileType
? AttachmentKey[attachment.fileType as keyof typeof AttachmentKey] ||
undefined
: undefined
const requestParams = {
guid: application.id,
attachment: attachment?.blob,
attachmentKey,
}
await this.applicationApi.applicationsAttachmentsGuidPost(requestParams)
})

return response
}

Expand Down
7 changes: 7 additions & 0 deletions libs/university-gateway/src/lib/model/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IApplication {
workExperienceList: IApplicationWorkExperience[]
extraFieldList: IApplicationExtraFields[]
educationOption?: string
attachments?: Array<IApplicationAttachment | undefined>
}

export interface IApplicationApplicant {
Expand Down Expand Up @@ -47,6 +48,12 @@ export interface IApplicationWorkExperience {
jobTitle: string
}

export interface IApplicationAttachment {
fileName: string
fileType: string
blob: Blob
}

export interface IApplicationExtraFields {
key: string
value: object
Expand Down
Loading