-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Remove number from label identifier list #12831
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
Merged
prastoin
merged 13 commits into
main
from
field-metadata-identifier-should-be-text-or-name
Jun 24, 2025
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4e094bb
fix(front): remove number from label identifier list
prastoin 94fba1a
feat(front,server,shared): wip centralizing and validating type
prastoin bc16d97
refactor(server): identifier fields validation
prastoin 62c175d
lint(server): fix
prastoin a13fe17
fix(server): input validation class validator
prastoin b05a97f
refactor(server): AHA
prastoin 9976d9c
refactor(server): simplify
prastoin c76b66e
test(server): remove unit failing tests
prastoin 1d984a9
lint(server): fix
prastoin 36e84a5
review(server): greptile
prastoin 731b830
test(server): update snapshots
prastoin f4e7745
fixup
prastoin 22da0ef
test: zzzz
prastoin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...src/engine/metadata-modules/utils/validate-metadata-identifier-field-metadata-id.utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { | ||
isDefined, | ||
isLabelIdentifierFieldMetadataTypes, | ||
} from 'twenty-shared/utils'; | ||
|
||
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface'; | ||
|
||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; | ||
import { | ||
ObjectMetadataException, | ||
ObjectMetadataExceptionCode, | ||
} from 'src/engine/metadata-modules/object-metadata/object-metadata.exception'; | ||
|
||
type Validator = { | ||
validator: (args: { | ||
fieldMetadataId: string; | ||
matchingFieldMetadata?: FieldMetadataEntity | FieldMetadataInterface; | ||
}) => boolean; | ||
label: string; | ||
}; | ||
|
||
type ValidateMetadataIdentifierFieldMetadataIdOrThrowArgs = { | ||
fieldMetadataId: string; | ||
fieldMetadataItems: FieldMetadataEntity[] | FieldMetadataInterface[]; | ||
validators: Validator[]; | ||
}; | ||
const validatorRunner = ({ | ||
fieldMetadataId, | ||
fieldMetadataItems, | ||
validators, | ||
}: ValidateMetadataIdentifierFieldMetadataIdOrThrowArgs): void => { | ||
const matchingFieldMetadata = fieldMetadataItems.find( | ||
(fieldMetadata) => fieldMetadata.id === fieldMetadataId, | ||
); | ||
|
||
validators.forEach(({ label, validator }) => { | ||
if (validator({ fieldMetadataId, matchingFieldMetadata })) { | ||
throw new ObjectMetadataException( | ||
label, | ||
ObjectMetadataExceptionCode.INVALID_OBJECT_INPUT, | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
type ValidateMetadataIdentifierFieldMetadataIdsArgs = { | ||
labelIdentifierFieldMetadataId: string | undefined; | ||
imageIdentifierFieldMetadataId: string | undefined; | ||
fieldMetadataItems: FieldMetadataEntity[] | FieldMetadataInterface[]; | ||
}; | ||
export const validateMetadataIdentifierFieldMetadataIds = ({ | ||
imageIdentifierFieldMetadataId, | ||
labelIdentifierFieldMetadataId, | ||
fieldMetadataItems, | ||
}: ValidateMetadataIdentifierFieldMetadataIdsArgs) => { | ||
const isMatchingFieldMetadataDefined: Validator['validator'] = ({ | ||
matchingFieldMetadata, | ||
}) => !isDefined(matchingFieldMetadata); | ||
|
||
if (isDefined(labelIdentifierFieldMetadataId)) { | ||
validatorRunner({ | ||
fieldMetadataId: labelIdentifierFieldMetadataId, | ||
fieldMetadataItems, | ||
validators: [ | ||
{ | ||
validator: isMatchingFieldMetadataDefined, | ||
label: | ||
'labelIdentifierFieldMetadataId validation failed: related field metadata not found', | ||
}, | ||
{ | ||
validator: ({ matchingFieldMetadata }) => | ||
isDefined(matchingFieldMetadata) && | ||
!isLabelIdentifierFieldMetadataTypes(matchingFieldMetadata.type), | ||
label: | ||
'labelIdentifierFieldMetadataId validation failed: it must be a TEXT or FULL_NAME field metadata type id', | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
if (isDefined(imageIdentifierFieldMetadataId)) { | ||
validatorRunner({ | ||
fieldMetadataId: imageIdentifierFieldMetadataId, | ||
fieldMetadataItems, | ||
validators: [ | ||
{ | ||
validator: isMatchingFieldMetadataDefined, | ||
label: | ||
'imageIdentifierFieldMetadataId validation failed: related field metadata not found', | ||
}, | ||
], | ||
}); | ||
} | ||
}; |
34 changes: 34 additions & 0 deletions
34
...object-metadata/__snapshots__/failing-update-one-object-metadata.integration-spec.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Object metadata creation should fail when labelIdentifier is not a TEXT or NAME field 1`] = ` | ||
[ | ||
{ | ||
"extensions": { | ||
"code": "BAD_USER_INPUT", | ||
}, | ||
"message": "labelIdentifierFieldMetadataId validation failed: it must be a TEXT or FULL_NAME field metadata type id", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Object metadata creation should fail when labelIdentifier is not a known field metadata id 1`] = ` | ||
[ | ||
{ | ||
"extensions": { | ||
"code": "BAD_USER_INPUT", | ||
}, | ||
"message": "labelIdentifierFieldMetadataId validation failed: related field metadata not found", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Object metadata creation should fail when labelIdentifier is not a uuid 1`] = ` | ||
[ | ||
{ | ||
"extensions": { | ||
"code": "BAD_USER_INPUT", | ||
}, | ||
"message": "labelIdentifierFieldMetadataId must be a UUID", | ||
}, | ||
] | ||
`; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.