Skip to content

Commit

Permalink
Implement datacollectionrecordvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
nad-au committed Mar 11, 2024
1 parent cd09a2a commit 4fa486f
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
}
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
12 changes: 12 additions & 0 deletions monorepo/actionstep-sandbox/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion monorepo/actionstep/src/action-step-client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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 {
actions: actionsClient(tokenClient),
actionParticipants: actionParticipantsClient(tokenClient),
dataCollections: dataCollectionsClient(tokenClient),
dataCollectionRecords: dataCollectionRecordsClient(tokenClient),
dataCollectionRecordValues: dataCollectionRecordValuesClient(tokenClient),
participants: participantsClient(tokenClient),
}
}
Expand Down
Loading

0 comments on commit 4fa486f

Please sign in to comment.