Skip to content

Commit

Permalink
Merge pull request #8170 from opencrvs/auto-pr-release-v1.6.2-8010-80
Browse files Browse the repository at this point in the history
🍒 Merge changes from PR #8010 to release-v1.6.2
  • Loading branch information
euanmillar authored Dec 9, 2024
2 parents 5c54bc3 + 0fda0af commit 8c8b46b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 70 deletions.
31 changes: 0 additions & 31 deletions packages/gateway/src/utils/documents.ts

This file was deleted.

63 changes: 32 additions & 31 deletions packages/workflow/src/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,40 @@ import {
} from '@opencrvs/commons/types'
import { CertifyInput, IssueInput } from './records/validations'

const fetchDocuments = async <T = any>(
suffix: string,
authHeader: IAuthHeader,
method = 'GET',
body: string | undefined = undefined
): Promise<T> => {
const result = await fetch(`${DOCUMENTS_URL}${suffix}`, {
method,
export async function uploadFileToMinio(
fileData: string,
authHeader: IAuthHeader
): Promise<string> {
const suffix = '/upload'
const request = {
method: 'POST',
headers: {
...authHeader,
'Content-Type': 'application/json'
},
body
})
body: JSON.stringify({ fileData: fileData })
}
const result = await fetch(`${DOCUMENTS_URL}${suffix}`, request)
const res = await result.json()
return res
return res.refUrl
}

export async function uploadBase64ToMinio(
async function uploadSVGToMinio(
fileData: string,
authHeader: IAuthHeader
): Promise<string> {
const docUploadResponse = await fetchDocuments(
'/upload',
authHeader,
'POST',
JSON.stringify({ fileData: fileData })
)

return docUploadResponse.refUrl
const suffix = '/upload-svg'
const request = {
method: 'POST',
headers: {
...authHeader,
'Content-Type': 'image/svg+xml'
},
body: fileData
}
const result = await fetch(`${DOCUMENTS_URL}${suffix}`, request)
const res = await result.json()
return res.refUrl
}

export async function uploadCertificateAttachmentsToDocumentsStore<
Expand All @@ -58,11 +62,11 @@ export async function uploadCertificateAttachmentsToDocumentsStore<
certificateDetails.collector.affidavit
) {
for (const affidavit of certificateDetails.collector.affidavit) {
affidavit.data = await uploadBase64ToMinio(affidavit.data, authHeader)
affidavit.data = await uploadFileToMinio(affidavit.data, authHeader)
}
}
if ('data' in certificateDetails) {
certificateDetails.data = await uploadBase64ToMinio(
certificateDetails.data = await uploadSVGToMinio(
certificateDetails.data,
authHeader
)
Expand All @@ -86,7 +90,7 @@ function uploadOrNormaliseSignatureData(
authHeader: IAuthHeader
) {
if (isBase64FileString(signature)) {
return uploadBase64ToMinio(signature, authHeader)
return uploadFileToMinio(signature, authHeader)
}

if (isPresignedUrl(signature)) {
Expand Down Expand Up @@ -138,7 +142,7 @@ export async function uploadBase64AttachmentsToDocumentsStore(
if (record.registration?.attachments) {
for (const attachment of record.registration.attachments) {
if (attachment.data && isBase64FileString(attachment.data)) {
const fileUri = await uploadBase64ToMinio(attachment.data, authHeader)
const fileUri = await uploadFileToMinio(attachment.data, authHeader)
attachment.data = fileUri
}
}
Expand All @@ -151,18 +155,15 @@ export async function uploadBase64AttachmentsToDocumentsStore(
if (certificate.collector.affidavit) {
for (const affidavit of certificate.collector.affidavit) {
if (affidavit.data && isBase64FileString(affidavit.data)) {
const fileUri = await uploadBase64ToMinio(
affidavit.data,
authHeader
)
const fileUri = await uploadFileToMinio(affidavit.data, authHeader)
affidavit.data = fileUri
}
}
}
if (certificate.collector.photo) {
for (const photo of certificate.collector.photo) {
if (photo.data && isBase64FileString(photo.data)) {
const fileUri = await uploadBase64ToMinio(photo.data, authHeader)
const fileUri = await uploadFileToMinio(photo.data, authHeader)
photo.data = fileUri
}
}
Expand All @@ -172,13 +173,13 @@ export async function uploadBase64AttachmentsToDocumentsStore(
if (record.registration?.correction?.attachments) {
for (const attachment of record.registration.correction.attachments) {
if (attachment.data && isBase64FileString(attachment.data)) {
const fileUri = await uploadBase64ToMinio(attachment.data, authHeader)
const fileUri = await uploadFileToMinio(attachment.data, authHeader)
attachment.data = fileUri
}
}
}
if (record.registration?.correction?.payment?.attachmentData) {
const fileUri = await uploadBase64ToMinio(
const fileUri = await uploadFileToMinio(
record.registration.correction.payment.attachmentData,
authHeader
)
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow/src/records/handler/certify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Certify record endpoint', () => {

// Upload certificate to minio
mswServer.use(
rest.post('http://localhost:9050/upload', (_, res, ctx) => {
rest.post('http://localhost:9050/upload-svg', (_, res, ctx) => {
return res(
ctx.json({ refUrl: '/ocrvs/6e964d7a-25d0-4524-bdc2-b1f29d1e816c' })
)
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Certify record endpoint', () => {

// Upload certificate to minio
mswServer.use(
rest.post('http://localhost:9050/upload', (_, res, ctx) => {
rest.post('http://localhost:9050/upload-svg', (_, res, ctx) => {
return res(
ctx.json({ refUrl: '/ocrvs/6e964d7a-25d0-4524-bdc2-b1f29d1e816c' })
)
Expand Down
6 changes: 3 additions & 3 deletions packages/workflow/src/records/handler/correction/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { conflict } from '@hapi/boom'
import { getAuthHeader } from '@opencrvs/commons/http'
import { CorrectionRequestedRecord } from '@opencrvs/commons/types'
import { uploadBase64ToMinio } from '@workflow/documents'
import { uploadFileToMinio } from '@workflow/documents'
import {
getLoggedInPractitionerResource,
getPractitionerOfficeId
Expand Down Expand Up @@ -51,15 +51,15 @@ export const requestCorrectionRoute = createRoute({

const paymentAttachmentUrl =
correctionDetails.payment?.attachmentData &&
(await uploadBase64ToMinio(
(await uploadFileToMinio(
correctionDetails.payment.attachmentData,
getAuthHeader(request)
))

const proofOfLegalCorrectionAttachments = await Promise.all(
correctionDetails.attachments.map(async (attachment) => ({
type: attachment.type,
url: await uploadBase64ToMinio(attachment.data, getAuthHeader(request))
url: await uploadFileToMinio(attachment.data, getAuthHeader(request))
}))
)

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23937,9 +23937,9 @@ [email protected], typescript@^4.5:
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

"typescript@>=3 < 6":
version "5.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611"
integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==
version "5.6.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b"
integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==

typical@^2.6.1:
version "2.6.1"
Expand Down

0 comments on commit 8c8b46b

Please sign in to comment.