feat: rename tenant into workspace (#2553)

* feat: rename tenant into workspace

* fix: missing some files and reset not working

* fix: wrong import

* Use link in company seeds

* Use link in company seeds

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2023-11-17 11:26:33 +01:00
committed by GitHub
parent bc579d64a6
commit b86ada6d2b
239 changed files with 1603 additions and 1618 deletions

View File

@ -0,0 +1,69 @@
import { RelationMetadataInterface } from 'src/workspace/workspace-schema-builder/interfaces/relation-metadata.interface';
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
import {
deduceRelationDirection,
RelationDirection,
} from 'src/workspace/utils/deduce-relation-direction.util';
describe('deduceRelationDirection', () => {
it('should return FROM when the current object Metadata ID matches fromObjectMetadataId', () => {
const currentObjectId = 'from_object_id';
const relationMetadata = {
id: 'relation_id',
fromObjectMetadataId: currentObjectId,
toObjectMetadataId: 'to_object_id',
fromFieldMetadataId: 'from_field_id',
toFieldMetadataId: 'to_field_id',
relationType: RelationMetadataType.ONE_TO_ONE,
};
const result = deduceRelationDirection(
currentObjectId,
relationMetadata as RelationMetadataInterface,
);
expect(result).toBe(RelationDirection.FROM);
});
it('should return TO when the current object Metadata ID matches toObjectMetadataId', () => {
// Arrange
const currentObjectId = 'to_object_id';
const relationMetadata = {
id: 'relation_id',
fromObjectMetadataId: 'from_object_id',
toObjectMetadataId: currentObjectId,
fromFieldMetadataId: 'from_field_id',
toFieldMetadataId: 'to_field_id',
relationType: RelationMetadataType.ONE_TO_ONE,
};
const result = deduceRelationDirection(
currentObjectId,
relationMetadata as RelationMetadataInterface,
);
expect(result).toBe(RelationDirection.TO);
});
it('should throw an error when the current object Metadata ID does not match any object metadata ID', () => {
const currentObjectId = 'unrelated_object_id';
const relationMetadata = {
id: 'relation_id',
fromObjectMetadataId: 'from_object_id',
toObjectMetadataId: 'to_object_id',
fromFieldMetadataId: 'from_field_id',
toFieldMetadataId: 'to_field_id',
relationType: RelationMetadataType.ONE_TO_ONE,
};
expect(() =>
deduceRelationDirection(
currentObjectId,
relationMetadata as RelationMetadataInterface,
),
).toThrow(
`Relation metadata ${relationMetadata.id} is not related to object ${currentObjectId}`,
);
});
});

View File

@ -0,0 +1,33 @@
import { WorkspaceResolverBuilderMethodNames } from 'src/workspace/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
import { getResolverName } from 'src/workspace/utils/get-resolver-name.util';
describe('getResolverName', () => {
const metadata = {
nameSingular: 'entity',
namePlural: 'entities',
};
it.each([
['findMany', 'entities'],
['findOne', 'entity'],
['createMany', 'createEntities'],
['createOne', 'createEntity'],
['updateOne', 'updateEntity'],
['deleteOne', 'deleteEntity'],
])('should return correct name for %s resolver', (type, expectedResult) => {
expect(
getResolverName(metadata, type as WorkspaceResolverBuilderMethodNames),
).toBe(expectedResult);
});
it('should throw an error for an unknown resolver type', () => {
const unknownType = 'unknownType';
expect(() =>
getResolverName(
metadata,
unknownType as WorkspaceResolverBuilderMethodNames,
),
).toThrow(`Unknown resolver type: ${unknownType}`);
});
});

View File

@ -0,0 +1,23 @@
import { RelationMetadataInterface } from 'src/workspace/workspace-schema-builder/interfaces/relation-metadata.interface';
export enum RelationDirection {
FROM = 'from',
TO = 'to',
}
export const deduceRelationDirection = (
currentObjectId: string,
relationMetadata: RelationMetadataInterface,
): RelationDirection => {
if (relationMetadata.fromObjectMetadataId === currentObjectId) {
return RelationDirection.FROM;
}
if (relationMetadata.toObjectMetadataId === currentObjectId) {
return RelationDirection.TO;
}
throw new Error(
`Relation metadata ${relationMetadata.id} is not related to object ${currentObjectId}`,
);
};

View File

@ -0,0 +1,27 @@
import { WorkspaceResolverBuilderMethodNames } from 'src/workspace/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
import { ObjectMetadataInterface } from 'src/workspace/workspace-schema-builder/interfaces/object-metadata.interface';
import { camelCase } from 'src/utils/camel-case';
import { pascalCase } from 'src/utils/pascal-case';
export const getResolverName = (
objectMetadata: Pick<ObjectMetadataInterface, 'namePlural' | 'nameSingular'>,
type: WorkspaceResolverBuilderMethodNames,
) => {
switch (type) {
case 'findMany':
return `${camelCase(objectMetadata.namePlural)}`;
case 'findOne':
return `${camelCase(objectMetadata.nameSingular)}`;
case 'createMany':
return `create${pascalCase(objectMetadata.namePlural)}`;
case 'createOne':
return `create${pascalCase(objectMetadata.nameSingular)}`;
case 'updateOne':
return `update${pascalCase(objectMetadata.nameSingular)}`;
case 'deleteOne':
return `delete${pascalCase(objectMetadata.nameSingular)}`;
default:
throw new Error(`Unknown resolver type: ${type}`);
}
};

View File

@ -0,0 +1,5 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
export const isCompositeFieldMetadataType = (type: FieldMetadataType) => {
return type === FieldMetadataType.RELATION;
};