mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 13:31:45 +03:00
parent
936ac4027a
commit
def1774bf0
@ -60,4 +60,26 @@ describe('validateObjectName', () => {
|
|||||||
validateObjectMetadataInputOrThrow(invalidObjectInput),
|
validateObjectMetadataInputOrThrow(invalidObjectInput),
|
||||||
).toThrow();
|
).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw if nameSingular is not camelCased', async () => {
|
||||||
|
const invalidObjectInput = {
|
||||||
|
...validObjectInput,
|
||||||
|
nameSingular: 'notACamelCase1a',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
validateObjectMetadataInputOrThrow(invalidObjectInput),
|
||||||
|
).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if namePlural is a not camelCased', async () => {
|
||||||
|
const invalidObjectInput = {
|
||||||
|
...validObjectInput,
|
||||||
|
namePlural: 'notACamelCase1b',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
validateObjectMetadataInputOrThrow(invalidObjectInput),
|
||||||
|
).toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,7 @@ import { InvalidStringException } from 'src/engine/metadata-modules/errors/Inval
|
|||||||
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
||||||
import { UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
|
import { UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
|
||||||
import { validateMetadataName } from 'src/engine/metadata-modules/utils/validate-metadata-name.utils';
|
import { validateMetadataName } from 'src/engine/metadata-modules/utils/validate-metadata-name.utils';
|
||||||
|
import { camelCase } from 'src/utils/camel-case';
|
||||||
|
|
||||||
const coreObjectNames = [
|
const coreObjectNames = [
|
||||||
'appToken',
|
'appToken',
|
||||||
@ -41,6 +42,9 @@ export const validateObjectMetadataInputOrThrow = <
|
|||||||
>(
|
>(
|
||||||
objectMetadataInput: T,
|
objectMetadataInput: T,
|
||||||
): void => {
|
): void => {
|
||||||
|
validateNameCamelCasedOrThrow(objectMetadataInput.nameSingular);
|
||||||
|
validateNameCamelCasedOrThrow(objectMetadataInput.namePlural);
|
||||||
|
|
||||||
validateNameCharactersOrThrow(objectMetadataInput.nameSingular);
|
validateNameCharactersOrThrow(objectMetadataInput.nameSingular);
|
||||||
validateNameCharactersOrThrow(objectMetadataInput.namePlural);
|
validateNameCharactersOrThrow(objectMetadataInput.namePlural);
|
||||||
|
|
||||||
@ -56,6 +60,14 @@ const validateNameIsNotReservedKeywordOrThrow = (name?: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const validateNameCamelCasedOrThrow = (name?: string) => {
|
||||||
|
if (name) {
|
||||||
|
if (name !== camelCase(name)) {
|
||||||
|
throw new ForbiddenException(`Name should be in camelCase: ${name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const validateNameCharactersOrThrow = (name?: string) => {
|
const validateNameCharactersOrThrow = (name?: string) => {
|
||||||
try {
|
try {
|
||||||
if (name) {
|
if (name) {
|
||||||
|
@ -416,8 +416,8 @@ export class RemoteTableService {
|
|||||||
: plural(localTableBaseName);
|
: plural(localTableBaseName);
|
||||||
|
|
||||||
const objectMetadata = await this.objectMetadataService.createOne({
|
const objectMetadata = await this.objectMetadataService.createOne({
|
||||||
nameSingular: localTableNameSingular,
|
nameSingular: camelCase(localTableNameSingular),
|
||||||
namePlural: localTableNamePlural,
|
namePlural: camelCase(localTableNamePlural),
|
||||||
labelSingular: camelToTitleCase(camelCase(localTableBaseName)),
|
labelSingular: camelToTitleCase(camelCase(localTableBaseName)),
|
||||||
labelPlural: camelToTitleCase(plural(camelCase(localTableBaseName))),
|
labelPlural: camelToTitleCase(plural(camelCase(localTableBaseName))),
|
||||||
description: 'Remote table',
|
description: 'Remote table',
|
||||||
|
Loading…
Reference in New Issue
Block a user