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 field creation #7547

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
);
}

this.validateFieldMetadataInput<CreateFieldInput>(
fieldMetadataInput.type,
fieldMetadataInput,
objectMetadata,
);

console.time('createOne save');
const createdFieldMetadata = await fieldMetadataRepository.save({
const fieldMetadataForCreate = {
id: v4(),
createdAt: new Date(),
updatedAt: new Date(),
Expand All @@ -187,7 +180,18 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
: undefined,
isActive: true,
isCustom: true,
});
};

this.validateFieldMetadataInput<CreateFieldInput>(
Copy link
Member

Choose a reason for hiding this comment

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

It's not really a fieldMetadataInput anymore though 😄

fieldMetadataForCreate.type,
fieldMetadataForCreate,
objectMetadata,
);

console.time('createOne save');
const createdFieldMetadata = await fieldMetadataRepository.save(
fieldMetadataForCreate,
);

console.timeEnd('createOne save');

Expand Down Expand Up @@ -394,12 +398,6 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
}
}

this.validateFieldMetadataInput<UpdateFieldInput>(
existingFieldMetadata.type,
fieldMetadataInput,
objectMetadata,
);

const updatableFieldInput =
existingFieldMetadata.isCustom === false
? this.buildUpdatableStandardFieldInput(
Expand All @@ -408,8 +406,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
)
: fieldMetadataInput;

// We're running field update under a transaction, so we can rollback if migration fails
await fieldMetadataRepository.update(id, {
const fieldMetadataForUpdate = {
...updatableFieldInput,
defaultValue:
// Todo: we handle default value for all field types.
Expand All @@ -422,7 +419,16 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
: updatableFieldInput.defaultValue !== null
? updatableFieldInput.defaultValue
: null,
});
};

this.validateFieldMetadataInput<UpdateFieldInput>(
existingFieldMetadata.type,
fieldMetadataForUpdate,
objectMetadata,
);

// We're running field update under a transaction, so we can rollback if migration fails
await fieldMetadataRepository.update(id, fieldMetadataForUpdate);

const updatedFieldMetadata = await fieldMetadataRepository.findOne({
where: { id },
Expand Down
Loading