Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
nad-au committed Mar 7, 2024
1 parent 3327fdc commit c3fbcf0
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 150 deletions.
36 changes: 25 additions & 11 deletions monorepo/actionstep-sandbox/src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
actionStepClient,
actionStepLegacyTokenClient,
actionStepTokenClient,
actionsClient,
} from '@dbc-tech/actionstep'
import * as dotenv from 'dotenv'
dotenv.config()
Expand All @@ -15,24 +15,38 @@ const actionLister = async () => {
process.env.ACTIONSTEP_TOKEN_URL,
process.env.ACTIONSTEP_API_URL,
)
const client = actionsClient(tokenClient)
const { actions: actionsClient } = actionStepClient(tokenClient)

// const { actions } = await client.getActions(1, 50)
// const { actions } = await actionsClient.getActions(1, 50)
// for (const action of actions) {
// console.log('id:', action.id)
// }

const testId1 = 68330
const testId2 = 84407
const { actions: action } = await client.getAction(testId1)
console.log('action:', JSON.stringify(action))
const { data: action, error: getError } =
await actionsClient.getAction(testId1)
if (getError) console.error('get error:', getError)
else
console.log('get action:', {
id: action.actions.id,
name: action.actions.name,
reference: action.actions.reference,
})

const { actions: updatedAction } = await client.updateAction(testId1, {
actions: {
reference: 'TEST04',
},
})
console.log('updated action.reference:', updatedAction.reference)
const { data: updatedAction, error: updateError } =
await actionsClient.updateAction(testId1, {
actions: {
reference: 'TEST07',
},
})
if (updateError) console.error('update error:', updateError)
else
console.log('updated action:', {
id: updatedAction.actions.id,
name: updatedAction.actions.name,
reference: updatedAction.actions.reference,
})
}

actionLister()
Expand Down
26 changes: 3 additions & 23 deletions monorepo/actionstep/src/action-step-client.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
import { HttpService } from '@dbc-tech/http-kit'
import { ActionStepTokenClient } from './types/action-step-auth.type'
import { ActionStepData } from './dtos/actions.dto'
import { ActionIds } from './dtos/action-ids.dto'
import { CreateFileNotes } from './dtos/create-file-notes.dto'
import { actionsClient } from './api/actions'

export const actionStepClient = (auth: ActionStepTokenClient) => {
const http = new HttpService(
auth.apiapi_url,
async () => (await auth.token()).access_token,
)
export const actionStepClient = (tokenClient: ActionStepTokenClient) => {
return {
getActions: async (id: string): Promise<ActionStepData> => {
const response = await http.getJson<ActionStepData>(`rest/actions/${id}`)
return response.data
},
getLatestActions: async (pageSize: number): Promise<ActionIds> => {
const response = await http.getJson<ActionIds>(
`rest/actions?sort=-id&pageSize=${pageSize}&fields=id`,
)
return response.data
},
createFileNotes: async (filenotes: CreateFileNotes): Promise<unknown> => {
const response = await http.postJson<unknown>(`rest/filenotes`, filenotes)
return response.data
},
actions: actionsClient(tokenClient),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface paths {
/** @description OK. */
200: {
content: {
'application/json': components['schemas']['Action']
'application/json': components['schemas']['SingleAction']
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export * from './actions-schema'

import createClient from 'openapi-fetch'
import type { components, paths } from './actions-schema' // generated by openapi-typescript
import { authMiddleware } from './auth-middleware'
import { ActionStepTokenClient } from '../types'
import { authMiddleware } from '../auth-middleware'
import { ActionStepTokenClient } from '../../types'

export type PagedActionsSuccessResponse =
paths['/actions']['get']['responses'][200]['content']['application/json']
Expand All @@ -17,48 +19,40 @@ export const getActions = async (
client: ActionsClient,
page: number = 1,
pageSize: number = 50,
): Promise<PagedActionsSuccessResponse> => {
const { data } = await client.GET('/actions', {
) => {
return await client.GET('/actions', {
params: {
query: {
pageSize,
page,
},
},
})

return data
}

export const getAction = async (
client: ActionsClient,
id: number,
): Promise<ActionSuccessResponse> => {
const { data } = await client.GET('/actions/{id}', {
export const getAction = async (client: ActionsClient, id: number) => {
return await client.GET('/actions/{id}', {
params: {
path: {
id,
},
},
})

return data
}

export const updateAction = async (
client: ActionsClient,
id: number,
body: ActionUpdate,
): Promise<ActionSuccessResponse> => {
const { data } = await client.PUT('/actions/{id}', {
) => {
return await client.PUT('/actions/{id}', {
params: {
path: {
id,
},
},
body,
})
return data
}

export const actionsClient = (tokenClient: ActionStepTokenClient) => {
Expand Down
1 change: 0 additions & 1 deletion monorepo/actionstep/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './actions'
export * from './actions-schema'
6 changes: 0 additions & 6 deletions monorepo/actionstep/src/dtos/action-ids.dto.ts

This file was deleted.

50 changes: 0 additions & 50 deletions monorepo/actionstep/src/dtos/actions.dto.ts

This file was deleted.

6 changes: 0 additions & 6 deletions monorepo/actionstep/src/dtos/create-file-notes.dto.ts

This file was deleted.

3 changes: 0 additions & 3 deletions monorepo/actionstep/src/dtos/id.dto.ts

This file was deleted.

33 changes: 0 additions & 33 deletions monorepo/actionstep/src/dtos/meta.dto.ts

This file was deleted.

1 change: 1 addition & 0 deletions monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"scripts": {
"turbo": "turbo",
"build": "turbo build",
"lint": "turbo lint",
"test": "npm run test --workspaces"
},
"devDependencies": {
Expand Down

0 comments on commit c3fbcf0

Please sign in to comment.