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

fix: FieldMetadata default value and options better validation #2785

Merged
merged 9 commits into from
Dec 6, 2023

Conversation

magrinj
Copy link
Member

@magrinj magrinj commented Dec 1, 2023

This PR, in how defaultValue and options were validated.
It nos use asynchronous validators to support create and update validation based on the type of the field.

@magrinj magrinj force-pushed the fix/fieldmetadata-validation branch 2 times, most recently from 4a2b3fa to 6a3d351 Compare December 5, 2023 16:16
Copy link

github-actions bot commented Dec 5, 2023

TODOs/FIXMEs:

  • // TODO: Add validation for this but we don't have the type actually: server/src/metadata/field-metadata/dtos/update-field.input.ts

Generated by 🚫 dangerJS against 53b6a4d

@magrinj magrinj changed the title fix: wip better field metadata validation fix: FieldMetadata default value and options better validation Dec 5, 2023
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't generate something smaller for now... As it's map file and bundled sources

@magrinj magrinj marked this pull request as ready for review December 5, 2023 16:33
@magrinj magrinj linked an issue Dec 5, 2023 that may be closed by this pull request
Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

Left a few comments, LGTM 👏

.vscode/launch.json Show resolved Hide resolved
server/src/filters/exception.filter.ts Show resolved Hide resolved
@Args('input') input: UpdateOneFieldMetadataInput,
@AuthWorkspace() { id: workspaceId }: Workspace,
) {
return this.fieldMetadataService.updateOne(input.id, {
Copy link
Member

Choose a reason for hiding this comment

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

It seems we lost a few checks such as rejecting updates on standard fields (except for isActive) + updates on certain fields for custom or am I missed something?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Weiko I'll take a look on that

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I've fix the issue

@magrinj magrinj force-pushed the fix/fieldmetadata-validation branch from ac2161e to a0fc109 Compare December 6, 2023 11:21
Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -159,6 +159,15 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
throw new NotFoundException('Field does not exist');
}

if (existingFieldMetadata.isCustom === false) {
// We can only update the isActive field for standard fields
Copy link
Member

Choose a reason for hiding this comment

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

Nit: not a blocker but it could be a bit deceiving for the api user since we transform the input and not throw any error if something else than isActive is changed

Copy link
Member Author

Choose a reason for hiding this comment

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

@Weiko Yes it's a quick change, we can maybe create another default validator for isCustom properties, but you told me that the front-end send all the input informations and I didn't want to break it

@magrinj magrinj merged commit 93decac into main Dec 6, 2023
9 of 13 checks passed
@magrinj magrinj deleted the fix/fieldmetadata-validation branch December 6, 2023 14:19
@charlesBochet charlesBochet mentioned this pull request Dec 8, 2023
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.

Set, retrieve and update default currencyCode for Currency Field
3 participants