Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- BPay handling to NSW GovPay provider
- `formsAppService.getFormSubmissionMetaList()`

## [10.1.2] - 2026-05-07

Expand Down
94 changes: 92 additions & 2 deletions src/apps/forms-app-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { FormsAppsTypes, EnvironmentTypes } from '@oneblink/types'
import {
FormsAppsTypes,
EnvironmentTypes,
SubmissionTypes,
} from '@oneblink/types'
import tenants from './tenants'
import { HTTPError, getRequest } from './services/fetch'
import { HTTPError, getRequest, searchRequest } from './services/fetch'
import { isOffline } from './offline-service'
import OneBlinkAppsError from './services/errors/oneBlinkAppsError'
import Sentry from './Sentry'
Expand Down Expand Up @@ -70,3 +74,89 @@ export async function getFormsAppConfiguration(
}
}
}

/** Query parameters for `GET /forms-apps/:formsAppId/form-submission-meta` */
export type GetFormSubmissionMetaQuery = {
formId?: number
submissionDateFrom?: string
submissionDateTo?: string
submissionId?: string
externalId?: string
submissionTitle?: string
limit?: number
offset?: number
}

export type FormSubmissionMetaListResponse = {
meta: {
limit: number | undefined
offset: number | undefined
/** `undefined` means there are no results left to fetch */
nextOffset: number | undefined
}
formSubmissionMeta: SubmissionTypes.FormSubmissionMeta[]
}

/**
* List form submission metadata for a Forms App for the current user.
*
* @param formsAppId
* @param query
* @param abortSignal
*/
export async function getFormSubmissionMetaList(
formsAppId: number,
query: GetFormSubmissionMetaQuery = {},
abortSignal?: AbortSignal,
): Promise<FormSubmissionMetaListResponse> {
const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/form-submission-meta`
const searchParameters: Record<string, unknown> = {
...query,
offset: query.offset ?? 0,
}

try {
return await searchRequest<FormSubmissionMetaListResponse>(
url,
searchParameters,
abortSignal,
)
} catch (err) {
Sentry.captureException(err)

const error = err as HTTPError

if (isOffline()) {
throw new OneBlinkAppsError(
'You are currently offline, please connect to the internet and try again',
{
originalError: error,
isOffline: true,
},
)
}

switch (error.status) {
case 400:
case 404: {
throw new OneBlinkAppsError(
'We could not find the forms app you are looking for. Please contact support if the problem persists.',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd to display this in a forms app, but I get that it's accurate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need to worry about it happening.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

400 error shouldn't throw this message though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy/paste from other services. Happy to change to anything suggested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, ideally we should provide some information that comes from the server on a 400, but I don't care enough to consider that right now. Ship it.

{
originalError: error,
title: 'Invalid Request',
httpStatusCode: error.status,
},
)
}
default: {
throw new OneBlinkAppsError(
'An unknown error has occurred. Please contact support if the problem persists.',
{
originalError: error,
httpStatusCode: error.status,
},
)
}
}
}
}
Loading