Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #1369 The Web Components Config API should store config by appId #1401

Conversation

phmngocnghia
Copy link
Contributor

@phmngocnghia phmngocnghia commented May 28, 2020

Pull request checklist

Does this close any currently open issues?

fixes: #1369

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (yarn build) was run locally and any changes were pushed
  • Lint (yarn lint) has passed locally and any fixes were made for failures
  • Test (yarn test) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

old route:
webComponentsConfig.get('/:customerId', webComponentsConfigGetByIdHandler) webComponentsConfig.put('/', webComponentsConfigPutHandler) webComponentsConfig.patch('/:customerId', webComponentsConfigPatchHandler) webComponentsConfig.delete('/:customerId', webComponentsConfigDeleteHandler)

Issue Number: #1369

What is the new behavior?

Add appId to all CRUD routes

webComponentsConfig.post('/:customerId/:appId', webComponentsConfigPostHandler) webComponentsConfig.get('/:customerId/:appId', webComponentsConfigGetByIdHandler) webComponentsConfig.delete('/:customerId/:appId', webComponentsConfigDeleteHandler) webComponentsConfig.patch('/:customerId/:appId', webComponentsConfigPatchHandler) webComponentsConfig.put('/:customerId/:appId', webComponentsConfigPutHandler)

Does this introduce a breaking change?

  • Yes
  • No

Other information

Will need to add global secondary index key to appId field: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/getting-started-step-6.html

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Closing this pull request since the title does not match ^(:?[WIP] ?)?(?:build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test):(?:\ +?#\d+?\ +?)?.* pattern. Please fix the title and re-open the pull request.

@phmngocnghia phmngocnghia changed the title [WIP] feat #1369: The Web Components Config API should store config by appId feat #1369: The Web Components Config API should store config by appId May 28, 2020
@phmngocnghia phmngocnghia changed the title feat #1369: The Web Components Config API should store config by appId feat: #1369 The Web Components Config API should store config by appId May 28, 2020
@phmngocnghia phmngocnghia reopened this May 28, 2020
@github-actions github-actions bot closed this May 28, 2020
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Closing this pull request since the title does not match ^(:?[WIP] ?)?(?:build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test):(?:\ +?#\d+?\ +?)?.* pattern. Please fix the title and re-open the pull request.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Closing this pull request since the title does not match ^(:?[WIP] ?)?(?:build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test):(?:\ +?#\d+?\ +?)?.* pattern. Please fix the title and re-open the pull request.

@phmngocnghia phmngocnghia reopened this May 28, 2020
@phmngocnghia phmngocnghia changed the title feat: #1369 The Web Components Config API should store config by appId [WIP]feat: #1369 The Web Components Config API should store config by appId May 28, 2020
@duong-se duong-se added the do not merge Branch should not be merged into main workflow in current state label May 31, 2020
export const webComponentsConfigPostHandler = async (req: AppRequest, res: AppResponse) => {
try {
const params = {
data: { ...req.body, customerId: req.params.customerId, appId: req.params.appId },
Copy link
Contributor

Choose a reason for hiding this comment

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

shoud we use opt chain to check null or undefined ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's params from express route matching. Pretty sure about value of these field are always something not null

@phmngocnghia phmngocnghia force-pushed the feat-#1039-the-web-components-config-api-should-store-config-by-app-id branch from 3f66d73 to 7735943 Compare June 18, 2020 05:59
@phmngocnghia phmngocnghia removed the do not merge Branch should not be merged into main workflow in current state label Jun 18, 2020
@github-actions github-actions bot requested a review from duong-se June 18, 2020 05:59
@phmngocnghia phmngocnghia changed the title [WIP]feat: #1369 The Web Components Config API should store config by appId feat: #1369 The Web Components Config API should store config by appId Jun 18, 2020
Copy link
Contributor

@duong-se duong-se left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@vuhuucuong vuhuucuong left a comment

Choose a reason for hiding this comment

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

Others LGTM

Comment on lines +42 to +61
export const patchConfig = async ({ traceId, data }: UpdateParams): Promise<WebComponentConfig> => {
try {
logger.info('Updating config...', { traceId, data })
const { customerId, ...rest } = data
const oldItem = await getConfigByClientId({ traceId, data: { customerId } })
logger.info('Patching config...', { traceId, data })
const { customerId, appId, ...rest } = data
const oldItem = await getConfigByClientId({ traceId, data: { customerId, appId } })
const itemToUpdate = generateSchemaItem({ ...oldItem, ...rest })
const result = await dynamoDBMapper.update(itemToUpdate)
logger.info('Patch config successfully', { traceId, result })
return result
} catch (error) {
await logger.error('Patch config failed', { traceId, error: stringifyError(error) })
throw error
}
}

export const putConfig = async ({ traceId, data }): Promise<WebComponentConfig> => {
try {
logger.info('Updating config...', { traceId, data })
const itemToUpdate = generateSchemaItem(data)
const result = await dynamoDBMapper.put(itemToUpdate)
Copy link
Contributor

Choose a reason for hiding this comment

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

just wonder why we need both PUT, and PATCH to update ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@phmngocnghia please fix to the next PR

@duong-se duong-se merged commit e09eb0c into master Jun 19, 2020
@duong-se duong-se deleted the feat-#1039-the-web-components-config-api-should-store-config-by-app-id branch June 19, 2020 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The Web Components Config API should store config by appId
3 participants