Skip to content

Commit

Permalink
Added mock for updating documentation and audience description
Browse files Browse the repository at this point in the history
  • Loading branch information
martinaCampoli committed Feb 5, 2025
1 parent 057f114 commit fa77877
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/api/template/template.downloads.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useTranslation } from 'react-i18next'
import { TemplateServices } from './template.services'
import { useDownloadFile } from '../hooks'

function useDownloadVersionDocument() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'eservice.downloadVersionDraftDocument',
})
return useDownloadFile(TemplateServices.downloadVersionDraftDocument, {

Check failure on line 9 in src/api/template/template.downloads.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Argument of type '({ templateId, documentId, }: { templateId: string; documentId: string; }) => Promise<void>' is not assignable to parameter of type '(args: { templateId: string; documentId: string; }) => Promise<string | File | { file: File; filename: string; }>'.
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
})
}

export const TemplateDownloads = {
useDownloadVersionDocument,
}
90 changes: 89 additions & 1 deletion src/api/template/template.mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TemplateServices } from './template.services'

function useUpdateEServiceTemplateName() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'eservice.updateEServiceName',
keyPrefix: 'template.updateEServiceTemplateName',

Check failure on line 7 in src/api/template/template.mutations.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Type '"template.updateEServiceTemplateName"' is not assignable to type 'KeyPrefix<"mutations-feedback">'.
})
return useMutation({
mutationFn: TemplateServices.updateEServiceTemplateName,
Expand All @@ -16,6 +16,94 @@ function useUpdateEServiceTemplateName() {
})
}

function useUpdateEServiceTemplateAudience() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'template.updateEServiceTemplateAudience',

Check failure on line 21 in src/api/template/template.mutations.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Type '"template.updateEServiceTemplateAudience"' is not assignable to type 'KeyPrefix<"mutations-feedback">'.
})
return useMutation({
mutationFn: TemplateServices.updateEServiceTemplateAudience,
meta: {
successToastLabel: t('outcome.success'),
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
},
})
}

function useUpdateTemplateEServiceDescription() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'eservice.updateEServiceDescription',
})
return useMutation({
mutationFn: TemplateServices.updateTemplateEServiceDescription,
meta: {
successToastLabel: t('outcome.success'),
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
},
})
}

function useUpdateQuotas() {
const { t } = useTranslation('mutations-feedback', { keyPrefix: 'eservice.updateVersion' })
return useMutation({
mutationFn: TemplateServices.updateEServiceTemplateQuotas, //TODO
meta: {
successToastLabel: t('outcome.success'),
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
},
})
}

function usePostVersionDraftDocument() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'eservice.postVersionDraftDocument',
})
return useMutation({
mutationFn: TemplateServices.postVersionDraftDocument,
meta: {
successToastLabel: t('outcome.success'),
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
},
})
}

function useDeleteVersionDraftDocument() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'eservice.deleteVersionDraftDocument',
})
return useMutation({
mutationFn: TemplateServices.deleteVersionDraftDocument,

Check failure on line 78 in src/api/template/template.mutations.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Type '({ templateId, documentId, }: { templateId: string; documentId: string; }) => void' is not assignable to type 'MutationFunction<unknown, { templateId: string; documentId: string; }>'.
meta: {
successToastLabel: t('outcome.success'),
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
},
})
}

function useUpdateVersionDraftDocumentDescription() {
const { t } = useTranslation('mutations-feedback', {
keyPrefix: 'eservice.updateVersionDraftDocumentDescription',
})
return useMutation({
mutationFn: TemplateServices.updateVersionDraftDocumentDescription,
meta: {
successToastLabel: t('outcome.success'),
errorToastLabel: t('outcome.error'),
loadingLabel: t('loading'),
},
})
}

export const TemplateMutations = {
useUpdateEServiceTemplateName,
useUpdateEServiceTemplateAudience,
useUpdateTemplateEServiceDescription,
useUpdateQuotas,
usePostVersionDraftDocument,
useDeleteVersionDraftDocument,
useUpdateVersionDraftDocumentDescription,
}
118 changes: 116 additions & 2 deletions src/api/template/template.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,131 @@ async function getSingle(eserviceTemplateId: string) {
async function updateEServiceTemplateName({
eserviceTemplateId,
...payload
}: { eserviceTemplateId: string } & EServiceTempalteNameUpdateSeed) {
}: { eserviceTemplateId: string } & EServiceTemplateNameUpdateSeed) {

Check failure on line 63 in src/api/template/template.services.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Cannot find name 'EServiceTemplateNameUpdateSeed'.
/*const response = await axiosInstance.post(
`${BACKEND_FOR_FRONTEND_URL}/eservices/templates/${eserviceTemplateId}/name/update`,
payload
)
return response.data*/
return console.log('name template updated')
return console.log('name template updated') //TODO
}

async function updateEServiceTemplateAudience({
eserviceTemplateId,
...payload
}: { eserviceTemplateId: string } & EServiceTemplateAudienceUpdateSeed) {

Check failure on line 75 in src/api/template/template.services.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Cannot find name 'EServiceTemplateAudienceUpdateSeed'.
/*const response = await axiosInstance.post(
`${BACKEND_FOR_FRONTEND_URL}/eservices/templates/${eServiceTemplateId}/audienceDescription/update`,
payload
)
return response.data*/
return console.log('audience description template updated') //TODO
}

async function updateTemplateEServiceDescription({
eserviceTemplateId,
...payload
}: { eserviceTemplateId: string } & TemplateEServiceDescriptionUpdateSeed) {

Check failure on line 87 in src/api/template/template.services.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Cannot find name 'TemplateEServiceDescriptionUpdateSeed'.
/*const response = await axiosInstance.post(
`${BACKEND_FOR_FRONTEND_URL}/eservices/templates/${eServiceTemplateId}/eserviceDescription/update`,
payload
)
return response.data*/
return console.log('template eservice description updated') //TODO
}

async function updateEServiceTemplateQuotas({
eserviceTemplateId,
voucherLifespan,
dailyCallsPerConsumer,
dailyCallsTotal,
...payload
}: {
eserviceTemplateId: string
voucherLifespan: number
dailyCallsPerConsumer: number
dailyCallsTotal: number
}) {
/*const response = await axiosInstance.post(
`${BACKEND_FOR_FRONTEND_URL}/eservices/templates/${eServiceTemplateId}/versions/{eServiceTemplateVersionId}/quotas/update`,
payload
)
return response.data*/
return console.log('template eservice quotas updated') //TODO
}

async function postVersionDraftDocument({
templateId,
...payload
}: {
eserviceId: string
descriptorId: string
} & CreateEServiceDocumentPayload) {

Check failure on line 122 in src/api/template/template.services.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Cannot find name 'CreateEServiceDocumentPayload'.
/*const formData = new FormData()
Object.entries(payload).forEach(([key, data]) => formData.append(key, data))
const response = await axiosInstance.post<CreatedResource>(
`${BACKEND_FOR_FRONTEND_URL}/eservices/${eserviceId}/descriptors/${descriptorId}/documents`,
formData,
{ headers: { 'Content-Type': 'multipart/form-data' } }
)
return response.data*/
return console.log('uploaded doc')
}

function deleteVersionDraftDocument({
templateId,
documentId,
}: {
templateId: string
documentId: string
}) {
/* return axiosInstance.delete(
`${BACKEND_FOR_FRONTEND_URL}/eservices/${eserviceId}/descriptors/${descriptorId}/documents/${documentId}`
)*/
return console.log('deleted doc')
}

async function updateVersionDraftDocumentDescription({
templateId,
documentId,
...payload
}: {
templateId: string
documentId: string
} & UpdateEServiceDescriptorDocumentSeed) {

Check failure on line 155 in src/api/template/template.services.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 18.15.0)

Cannot find name 'UpdateEServiceDescriptorDocumentSeed'.
/*const response = await axiosInstance.post<EServiceDoc>(
`${BACKEND_FOR_FRONTEND_URL}/eservices/${eserviceId}/descriptors/${descriptorId}/documents/${documentId}/update`,
payload
)
return response.data*/
return console.log('updated doc')
}

async function downloadVersionDraftDocument({
templateId,
documentId,
}: {
templateId: string
documentId: string
}) {
/*const response = await axiosInstance.get<File>(
`${BACKEND_FOR_FRONTEND_URL}/eservices/${eserviceId}/descriptors/${descriptorId}/documents/${documentId}`,
{ responseType: 'arraybuffer' }
)
return response.data*/
return console.log('downloaded file')
}

export const TemplateServices = {
getProviderTemplatesList,
getSingle,
updateEServiceTemplateName,
updateEServiceTemplateAudience,
updateTemplateEServiceDescription,
updateEServiceTemplateQuotas,
postVersionDraftDocument,
deleteVersionDraftDocument,
updateVersionDraftDocumentDescription,
downloadVersionDraftDocument,
}

0 comments on commit fa77877

Please sign in to comment.