diff --git a/README.md b/README.md index 09bc104..56d807b 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,11 @@ const { actions: actionsClient } = actionStepClient(tokenClient) `get actions` reads all actions one page at a time. Use params to specify the page number and number of items per page as documented [here](https://docs.actionstep.com/api-requests/). ```ts -const { data, error } = await actionsClient.getActions({ page: 1, pageSize: 50}) +const { data, error } = await actionsClient.getActions({ + page: 1, + pageSize: 10, + filter: "status ilike '%active%'" +}) if (error) console.error('error:', error) else { for (const action of data.actions) { diff --git a/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecord.ts b/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecord.ts index 250056b..5c041a1 100644 --- a/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecord.ts +++ b/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecord.ts @@ -6,7 +6,7 @@ export const createDataCollectionRecord = async ( const { dataCollectionRecords: client } = actionStepClient(tokenClient) const testActionId = 68330 - const testDataCollectionId = 662 + const testDataCollectionId = 695 const { data, error } = await client.createDataCollectionRecord({ datacollectionrecords: { diff --git a/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecordValue.ts b/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecordValue.ts new file mode 100644 index 0000000..04f408d --- /dev/null +++ b/monorepo/actionstep-sandbox/src/endpoints/createDataCollectionRecordValue.ts @@ -0,0 +1,34 @@ +import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep' + +export const createDataCollectionRecordValue = async ( + tokenClient: ActionStepTokenClient, +) => { + const { dataCollectionRecordValues: client } = actionStepClient(tokenClient) + + const testActionId = 68330 + // Run createDataCollection and obtain id + const testDataCollectionId = 695 + const testDataCollectionField = '109--Postcode' + // Edit createDataCollectionRecord and replace collection id with above and run it to obtain id + const testDataCollectionRecordId = 416631 + + const { data, error } = await client.createDataCollectionRecordValues({ + datacollectionrecordvalues: { + stringValue: 'TEST01', + links: { + action: testActionId, + dataCollection: testDataCollectionId, + dataCollectionField: testDataCollectionField, + dataCollectionRecord: testDataCollectionRecordId, + }, + }, + }) + if (error) console.error('error:', error) + else { + console.log('created datacollectionrecordvalue:', { + id: data.datacollectionrecordvalues.id, + stringValue: data.datacollectionrecordvalues.stringValue, + links: data.datacollectionrecordvalues.links, + }) + } +} diff --git a/monorepo/actionstep-sandbox/src/endpoints/getDataCollectionRecordValue.ts b/monorepo/actionstep-sandbox/src/endpoints/getDataCollectionRecordValue.ts new file mode 100644 index 0000000..2d2dbd7 --- /dev/null +++ b/monorepo/actionstep-sandbox/src/endpoints/getDataCollectionRecordValue.ts @@ -0,0 +1,21 @@ +import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep' + +export const getDataCollectionRecordValue = async ( + tokenClient: ActionStepTokenClient, +) => { + const { dataCollectionRecordValues: client } = actionStepClient(tokenClient) + + const testDataCollectionValueId = '109--Postcode--100019' + + const { data, error } = await client.getDataCollectionRecordValue( + testDataCollectionValueId, + ) + if (error) console.error('error:', error) + else { + console.log('get datacollectionrecordvalue:', { + id: data.datacollectionrecordvalues.id, + stringValue: data.datacollectionrecordvalues.stringValue, + links: data.datacollectionrecordvalues.links, + }) + } +} diff --git a/monorepo/actionstep-sandbox/src/endpoints/getDataCollectionRecordValues.ts b/monorepo/actionstep-sandbox/src/endpoints/getDataCollectionRecordValues.ts new file mode 100644 index 0000000..5607699 --- /dev/null +++ b/monorepo/actionstep-sandbox/src/endpoints/getDataCollectionRecordValues.ts @@ -0,0 +1,21 @@ +import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep' + +export const getDataCollectionRecordValues = async ( + tokenClient: ActionStepTokenClient, +) => { + const { dataCollectionRecordValues: client } = actionStepClient(tokenClient) + + const { data, error } = await client.getDataCollectionRecordValues({ + pageSize: 5, + }) + if (error) console.error('error:', error) + else { + for (const datacollectionrecordvalue of data.datacollectionrecordvalues) { + console.log('get datacollectionrecordvalue:', { + id: datacollectionrecordvalue.id, + stringValue: datacollectionrecordvalue.stringValue, + links: datacollectionrecordvalue.links, + }) + } + } +} diff --git a/monorepo/actionstep-sandbox/src/endpoints/updateDataCollectionRecordValue.ts b/monorepo/actionstep-sandbox/src/endpoints/updateDataCollectionRecordValue.ts new file mode 100644 index 0000000..2fa20c1 --- /dev/null +++ b/monorepo/actionstep-sandbox/src/endpoints/updateDataCollectionRecordValue.ts @@ -0,0 +1,26 @@ +import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep' + +export const updateDataCollectionRecordValue = async ( + tokenClient: ActionStepTokenClient, +) => { + const { dataCollectionRecordValues: client } = actionStepClient(tokenClient) + + const testDataCollectionRecordValueId = 629 + + const { data, error } = await client.updateDataCollectionRecordValue( + testDataCollectionRecordValueId, + { + datacollectionrecordvalues: { + stringValue: 'TEST02', + }, + }, + ) + if (error) console.error('error:', error) + else { + console.log('updated datacollectionrecordvalue:', { + id: data.datacollectionrecordvalues.id, + stringValue: data.datacollectionrecordvalues.stringValue, + links: data.datacollectionrecordvalues.links, + }) + } +} diff --git a/monorepo/actionstep-sandbox/src/runner.ts b/monorepo/actionstep-sandbox/src/runner.ts index 72e2fe7..e6b786f 100644 --- a/monorepo/actionstep-sandbox/src/runner.ts +++ b/monorepo/actionstep-sandbox/src/runner.ts @@ -20,6 +20,10 @@ import { getDataCollectionRecords } from './endpoints/getDataCollectionRecords' import { getDataCollectionRecord } from './endpoints/getDataCollectionRecord' import { createDataCollectionRecord } from './endpoints/createDataCollectionRecord' import { deleteDataCollectionRecord } from './endpoints/deleteDataCollectionRecord' +import { getDataCollectionRecordValues } from './endpoints/getDataCollectionRecordValues' +import { getDataCollectionRecordValue } from './endpoints/getDataCollectionRecordValue' +import { createDataCollectionRecordValue } from './endpoints/createDataCollectionRecordValue' +import { updateDataCollectionRecordValue } from './endpoints/updateDataCollectionRecordValue' dotenv.config() const runner = async (endpointName: string) => { @@ -75,6 +79,14 @@ const runner = async (endpointName: string) => { return createDataCollectionRecord(tokenClient) case 'deleteDataCollectionRecord': return deleteDataCollectionRecord(tokenClient) + case 'getDataCollectionRecordValues': + return getDataCollectionRecordValues(tokenClient) + case 'getDataCollectionRecordValue': + return getDataCollectionRecordValue(tokenClient) + case 'createDataCollectionRecordValue': + return createDataCollectionRecordValue(tokenClient) + case 'updateDataCollectionRecordValue': + return updateDataCollectionRecordValue(tokenClient) } } diff --git a/monorepo/actionstep/src/action-step-client.ts b/monorepo/actionstep/src/action-step-client.ts index b6ddee9..be7e2db 100644 --- a/monorepo/actionstep/src/action-step-client.ts +++ b/monorepo/actionstep/src/action-step-client.ts @@ -1,11 +1,12 @@ -import { ActionStepTokenClient } from './types/action-step-auth.type' import { actionParticipantsClient, actionsClient, + dataCollectionRecordValuesClient, dataCollectionRecordsClient, dataCollectionsClient, participantsClient, } from './api' +import { ActionStepTokenClient } from './types/action-step-auth.type' export const actionStepClient = (tokenClient: ActionStepTokenClient) => { return { @@ -13,6 +14,7 @@ export const actionStepClient = (tokenClient: ActionStepTokenClient) => { actionParticipants: actionParticipantsClient(tokenClient), dataCollections: dataCollectionsClient(tokenClient), dataCollectionRecords: dataCollectionRecordsClient(tokenClient), + dataCollectionRecordValues: dataCollectionRecordValuesClient(tokenClient), participants: participantsClient(tokenClient), } } diff --git a/monorepo/actionstep/src/api/datacollectionrecordvalues/datacollectionrecordvalues.schema.ts b/monorepo/actionstep/src/api/datacollectionrecordvalues/datacollectionrecordvalues.schema.ts new file mode 100644 index 0000000..35aa270 --- /dev/null +++ b/monorepo/actionstep/src/api/datacollectionrecordvalues/datacollectionrecordvalues.schema.ts @@ -0,0 +1,294 @@ +/** + * This file was auto-generated by openapi-typescript. + * Do not make direct changes to the file. + */ + +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace DataCollectionRecordValues { + export interface paths { + '/datacollectionrecordvalues': { + /** @description Returns a collection of data collection record values. */ + get: { + responses: { + /** @description OK. */ + 200: { + content: { + 'application/json': components['schemas']['PagedDataCollectionRecordValues'] + } + } + } + } + /** @description Create a new data collection record value. */ + post: { + requestBody: components['requestBodies']['CreateDataCollectionRecordValue'] + responses: { + /** @description OK. */ + 200: { + content: { + 'application/json': components['schemas']['SingleDataCollectionRecordValues'] + } + } + } + } + } + '/datacollectionrecordvalues/{id}': { + /** @description Returns a single data collection record value. */ + get: { + parameters: { + path: { + /** + * @description Unique identifier for a data collection record value. + * @example 380 + */ + id: string + } + } + responses: { + /** @description OK. */ + 200: { + content: { + 'application/json': components['schemas']['SingleDataCollectionRecordValues'] + } + } + } + } + /** @description Update a data collection record value. */ + put: { + parameters: { + path: { + /** + * @description Unique identifier for a data collection record value. + * @example 608 + */ + id: number + } + } + requestBody: components['requestBodies']['UpdateDataCollectionRecordValue'] + responses: { + /** @description OK. */ + 200: { + content: { + 'application/json': components['schemas']['SingleDataCollectionRecordValues'] + } + } + } + } + } + } + + export type webhooks = Record + + export interface components { + schemas: { + SingleDataCollectionRecordValues: { + datacollectionrecordvalues?: components['schemas']['DataCollectionRecordValue'] + meta?: components['schemas']['PageMetaData'] + } + PagedDataCollectionRecordValues: { + datacollectionrecordvalues?: components['schemas']['DataCollectionRecordValue'][] + meta?: components['schemas']['PageMetaData'] + } + PageMetaData: { + paging?: components['schemas']['PagingData'] + } + PagingData: { + datacollectionrecordvalues?: components['schemas']['DataCollectionRecordValuesPageData'] + } + DataCollectionRecordValuesPageData: { + /** + * @description The total number of data collection record values returned by the underlying query. + * @example 2487 + */ + recordCount?: number + /** + * @description The total number of pages generated by the underlying query. + * @example 50 + */ + pageCount?: number + /** + * @description The page number for this page of data collection record values. + * @example 2 + */ + page?: number + /** + * @description Page size. + * @example 50 + */ + pageSize?: number + /** + * @description A URL to the previous page of data collection record values. + * @example https://ap-southeast-2.actionstep.com/api/rest/datacollectionrecordvalues?page=1 + */ + prevPage?: string + /** + * @description A URL to the next page of data collection record values. + * @example https://ap-southeast-2.actionstep.com/api/rest/datacollectionrecordvalues?page=3 + */ + nextPage?: string + } + DataCollectionRecordValue: { + /** + * Format: string + * @description Unique identifier for the data collection record value. This is a composite identifier constructed from the data collection unique identifier, the data field name, and the data collection record unique identifier, all separated by a '--' delimiter. + * @example 148--victim_age--6234 + */ + id?: string + /** + * Format: string + * @description Data field value as a string. + * @example "2023-12-25T00:00:00.000Z" + */ + stringValue?: string + /** + * Format: timestamp + * @description Date and time the data field value was last modified. + * @example "2023-06-02T12:09:30.000Z" + */ + last_modified_time_stamp?: string + /** + * @description Unique identifier for the Actionstep user who last modified the data field value. + * @example 7837 + */ + last_modified_by_user_id?: number + links?: components['schemas']['DataCollectionRecordValueLinks'] + } + DataCollectionRecordValueLinks: { + /** + * @description Unique identifier of the matter to which the data collection field value is associated. + * @example 500 + */ + action?: number + /** + * Format: string + * @description Unique identifier for the data collection field. This is a composite unique identifier composed from the data collection unique identifier and the data field name, separated by a '--' delimiter. + * @example 148--victim_age + */ + dataCollectionField?: string + /** + * @description Unique identifier for the data record. + * @example 6234 + */ + dataCollectionRecord?: number + /** + * @description Unique identifier of the data collection to which the data collection record is associated. + * @example 148 + */ + dataCollection?: number + } + CreateDataCollectionRecordValues: { + datacollectionrecordvalues?: components['schemas']['CreateDataCollectionRecordValue'] + } + CreateDataCollectionRecordValue: { + /** + * Format: string + * @description Data field value as a string. + * @example "2023-12-25T00:00:00.000Z" + */ + stringValue: string + /** + * Format: timestamp + * @description Date and time the data field value is created. + * @example "2023-06-02T12:09:30.000Z" + */ + last_modified_time_stamp?: string + /** + * @description Unique identifier for the Actionstep user who is creating the data field value. + * @example 7837 + */ + last_modified_by_user_id?: number + links?: components['schemas']['CreateDataCollectionRecordValueLinks'] + } + CreateDataCollectionRecordValueLinks: { + /** + * @description Unique identifier of the matter to which the data collection field value is associated. + * @example 500 + */ + action: number + /** + * Format: string + * @description Unique identifier for the data collection field. This is a composite unique identifier composed from the data collection unique identifier and the data field name, separated by a '--' delimiter. + * @example 148--victim_age + */ + dataCollectionField: string + /** + * @description Unique identifier for the data collection record. + * @example 6234 + */ + dataCollectionRecord: number + /** + * @description Unique identifier of the data collection to which the data collection record is associated. + * @example 148 + */ + dataCollection: number + } + UpdateDataCollectionRecordValues: { + datacollectionrecordvalues?: components['schemas']['UpdateDataCollectionRecordValue'] + } + UpdateDataCollectionRecordValue: { + /** + * Format: string + * @description Data field value as a string. + * @example "2023-12-25T00:00:00.000Z" + */ + stringValue: string + /** + * Format: timestamp + * @description Date and time the data field value is modified. + * @example "2023-06-02T12:09:30.000Z" + */ + last_modified_time_stamp?: string + /** + * @description Unique identifier for the Actionstep user who is modifying the data field value. + * @example 7837 + */ + last_modified_by_user_id?: number + links?: components['schemas']['UpdateDataCollectionRecordValueLinks'] + } + UpdateDataCollectionRecordValueLinks: { + /** + * @description Unique identifier of the matter to which the data collection field value is associated. + * @example 500 + */ + action?: number + /** + * Format: string + * @description Unique identifier for the data collection field. This is a composite unique identifier composed from the data collection unique identifier and the data field name, separated by a '--' delimiter. + * @example 148--victim_age + */ + dataCollectionField?: string + /** + * @description Unique identifier for the data record. + * @example 6234 + */ + dataCollectionRecord?: number + /** + * @description Unique identifier of the data collection to which the data collection record is associated. + * @example 148 + */ + dataCollection?: number + } + } + responses: never + parameters: never + requestBodies: { + CreateDataCollectionRecordValue?: { + content: { + 'application/json': components['schemas']['CreateDataCollectionRecordValues'] + } + } + UpdateDataCollectionRecordValue?: { + content: { + 'application/json': components['schemas']['UpdateDataCollectionRecordValues'] + } + } + } + headers: never + pathItems: never + } + + export type $defs = Record + + export type external = Record + + export type operations = Record +} diff --git a/monorepo/actionstep/src/api/datacollectionrecordvalues/index.ts b/monorepo/actionstep/src/api/datacollectionrecordvalues/index.ts new file mode 100644 index 0000000..04d3442 --- /dev/null +++ b/monorepo/actionstep/src/api/datacollectionrecordvalues/index.ts @@ -0,0 +1,100 @@ +export * from './datacollectionrecordvalues.schema' + +import createClient from 'openapi-fetch' +import { authMiddleware } from '../auth-middleware' +import { ActionStepTokenClient } from '../../types' +import { DataCollectionRecordValues } from './datacollectionrecordvalues.schema' + +export type PagedDataCollectionRecordValuesSuccessResponse = + DataCollectionRecordValues.paths['/datacollectionrecordvalues']['get']['responses'][200]['content']['application/json'] + +export type DataCollectionRecordValuesSuccessResponse = + DataCollectionRecordValues.paths['/datacollectionrecordvalues/{id}']['get']['responses'][200]['content']['application/json'] + +export type DataCollectionRecordValuesCreate = + DataCollectionRecordValues.components['schemas']['CreateDataCollectionRecordValues'] + +export type DataCollectionRecordValuesUpdate = + DataCollectionRecordValues.components['schemas']['UpdateDataCollectionRecordValues'] + +export type DataCollectionRecordValuesClient = ReturnType< + typeof createClient +> + +export const getDataCollectionRecordValues = async ( + client: DataCollectionRecordValuesClient, + params?: Record, +) => { + const query = params || {} + return client.GET('/datacollectionrecordvalues', { + params: { + query, + }, + }) +} + +export const createDataCollectionRecordValues = async ( + client: DataCollectionRecordValuesClient, + body: DataCollectionRecordValuesCreate, +) => { + return client.POST('/datacollectionrecordvalues', { + body, + }) +} + +export const getDataCollectionRecordValue = async ( + client: DataCollectionRecordValuesClient, + id: string, + params?: Record, +) => { + const query = params || {} + return client.GET('/datacollectionrecordvalues/{id}', { + params: { + path: { + id, + }, + query, + }, + }) +} + +export const updateDataCollectionRecordValue = async ( + client: DataCollectionRecordValuesClient, + id: number, + body: DataCollectionRecordValuesUpdate, +) => { + return client.PUT('/datacollectionrecordvalues/{id}', { + params: { + path: { + id, + }, + }, + body, + }) +} + +export const dataCollectionRecordValuesClient = ( + tokenClient: ActionStepTokenClient, +) => { + const client = createClient({ + baseUrl: tokenClient.api_url, + }) + + client.use(authMiddleware(tokenClient)) + + return { + getDataCollectionRecordValues: (params?: Record) => + getDataCollectionRecordValues(client, params), + createDataCollectionRecordValues: ( + body: DataCollectionRecordValuesCreate, + ) => createDataCollectionRecordValues(client, body), + getDataCollectionRecordValue: ( + id: string, + params?: Record, + ) => getDataCollectionRecordValue(client, id, params), + updateDataCollectionRecordValue: ( + id: number, + body: DataCollectionRecordValuesUpdate, + ) => updateDataCollectionRecordValue(client, id, body), + } +} diff --git a/monorepo/actionstep/src/api/index.ts b/monorepo/actionstep/src/api/index.ts index 23257ea..bc4a410 100644 --- a/monorepo/actionstep/src/api/index.ts +++ b/monorepo/actionstep/src/api/index.ts @@ -2,4 +2,5 @@ export * from './actions' export * from './actionparticipants' export * from './datacollections' export * from './datacollectionrecords' +export * from './datacollectionrecordvalues' export * from './participants'