# Introduction
Added a `WorkspaceRelated` and `AllNonWorkspaceRelatedEntity` to
simplify the `FlatEntityFrom` that now do not expect a string literal to
omit and itself builds the related many to one entities foreign key
aggregators
We now have the type grain over relation to syncable or just workspace
related entities
Added a migrations that sets the fk on missing entities
## Next
In upcoming PR we will be able to introduce such below type
```ts
import { type CastRecordTypeOrmDatePropertiesToString } from 'src/engine/metadata-modules/flat-entity/types/cast-record-typeorm-date-properties-to-string.type';
import { type ExtractEntityManyToOneEntityRelationProperties } from 'src/engine/metadata-modules/flat-entity/types/extract-entity-many-to-one-entity-relation-properties.type';
import { type ExtractEntityOneToManyEntityRelationProperties } from 'src/engine/metadata-modules/flat-entity/types/extract-entity-one-to-many-entity-relation-properties.type';
import { type ExtractEntityRelatedEntityProperties } from 'src/engine/metadata-modules/flat-entity/types/extract-entity-related-entity-properties.type';
import { type RemoveSuffix } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/remove-suffix.type';
import { type SyncableEntity } from 'src/engine/workspace-manager/workspace-sync/types/syncable-entity.interface';
export type UniversalFlatEntityFrom<TEntity extends SyncableEntity> = Omit<
TEntity,
| `${ExtractEntityManyToOneEntityRelationProperties<TEntity> & string}Id`
| ExtractEntityRelatedEntityProperties<TEntity>
| 'application'
| 'workspaceId'
| 'applicationId'
| keyof CastRecordTypeOrmDatePropertiesToString<TEntity>
> &
CastRecordTypeOrmDatePropertiesToString<TEntity> & {
[P in ExtractEntityManyToOneEntityRelationProperties<TEntity> &
string as `${RemoveSuffix<P, 's'>}UniversalIdentifier`]: string;
} & {
[P in ExtractEntityOneToManyEntityRelationProperties<
TEntity,
SyncableEntity
> &
string as `${RemoveSuffix<P, 's'>}UniversalIdentifiers`]: string[];
};
```
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import gql from 'graphql-tag';
|
|
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
|
|
import { type CommonResponseBody } from 'test/integration/metadata/types/common-response-body.type';
|
|
import { warnIfErrorButNotExpectedToFail } from 'test/integration/metadata/utils/warn-if-error-but-not-expected-to-fail.util';
|
|
import { warnIfNoErrorButExpectedToFail } from 'test/integration/metadata/utils/warn-if-no-error-but-expected-to-fail.util';
|
|
|
|
import { type UserEntity } from 'src/engine/core-modules/user/user.entity';
|
|
|
|
type CurrentUserUtilArgs = {
|
|
accessToken: string;
|
|
expectToFail?: boolean;
|
|
};
|
|
|
|
export const getCurrentUser = async ({
|
|
accessToken,
|
|
expectToFail,
|
|
}: CurrentUserUtilArgs): CommonResponseBody<{
|
|
currentUser: UserEntity;
|
|
}> => {
|
|
const query = gql`
|
|
query CurrentUser {
|
|
currentUser {
|
|
id
|
|
email
|
|
firstName
|
|
lastName
|
|
defaultAvatarUrl
|
|
isEmailVerified
|
|
disabled
|
|
canImpersonate
|
|
canAccessFullAdminPanel
|
|
locale
|
|
createdAt
|
|
updatedAt
|
|
deletedAt
|
|
currentWorkspace {
|
|
id
|
|
displayName
|
|
subdomain
|
|
activationStatus
|
|
logo
|
|
workspaceCustomApplicationId
|
|
}
|
|
currentUserWorkspace {
|
|
id
|
|
userId
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const response = await makeGraphqlAPIRequest(
|
|
{
|
|
query,
|
|
variables: {},
|
|
},
|
|
accessToken,
|
|
);
|
|
|
|
if (expectToFail === true) {
|
|
warnIfNoErrorButExpectedToFail({
|
|
response,
|
|
errorMessage: 'Get current user should have failed but did not',
|
|
});
|
|
}
|
|
|
|
if (expectToFail === false) {
|
|
warnIfErrorButNotExpectedToFail({
|
|
response,
|
|
errorMessage: 'Get current user has failed but should not',
|
|
});
|
|
}
|
|
|
|
return { data: response.body.data, errors: response.body.errors };
|
|
};
|