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

feat(api): create a layout change #2521

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

p-fernandez
Copy link
Contributor

What change does this PR introduce?

Adds functionality for creating a layout change

Why was this change needed?

To be able to promote the layouts for the production environment, first we need to create said change in order to be able to apply the changes in production, either individually or in bulk.

Other information (Screenshots)

@p-fernandez p-fernandez self-assigned this Jan 18, 2023
@linear
Copy link

linear bot commented Jan 18, 2023

Comment on lines +1 to +2
export * from './create-change.command';
export * from './create-change.usecase';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the same pattern of the use case we apply everywhere, I moved to dedicated folder to easier export.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment on lines 16 to 32
const item = await this.layoutRepository.findById(command.layoutId, command.environmentId);

if (item) {
const changeId = LayoutRepository.createObjectId();

await this.createChange.execute(
CreateChangeCommand.create({
organizationId: command.organizationId,
environmentId: command.environmentId,
userId: command.userId,
type: ChangeEntityTypeEnum.LAYOUT,
item,
changeId,
})
);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To review. I assume we don't need any parentChangeId as the layout changes are not based on another change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree :)

import { CreateChange, CreateChangeCommand } from '../../../change/usecases';

@Injectable()
export class CreateLayoutChangeUseCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dedicate use case for layout so it can be used in the needed use cases of the layout feature.

Copy link
Contributor

@ainouzgali ainouzgali left a comment

Choose a reason for hiding this comment

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

Looks good.

Comment on lines +1 to +2
export * from './create-change.command';
export * from './create-change.usecase';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -1,6 +1,7 @@
export enum ChangeEntityTypeEnum {
Copy link
Contributor

Choose a reason for hiding this comment

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

Its also in the first pr. Notice for conflicts

Comment on lines 16 to 32
const item = await this.layoutRepository.findById(command.layoutId, command.environmentId);

if (item) {
const changeId = LayoutRepository.createObjectId();

await this.createChange.execute(
CreateChangeCommand.create({
organizationId: command.organizationId,
environmentId: command.environmentId,
userId: command.userId,
type: ChangeEntityTypeEnum.LAYOUT,
item,
changeId,
})
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree :)

@p-fernandez p-fernandez force-pushed the nv-1502-changes-create-a-layout-change branch 4 times, most recently from f4d6d2d to 8949d3d Compare January 22, 2023 16:32
@@ -14,6 +14,7 @@ export class PromoteChangeToEnvironment {
constructor(
private changeRepository: ChangeRepository,
private environmentRepository: EnvironmentRepository,
@Inject(forwardRef(() => PromoteNotificationTemplateChange))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a circular dependency for PromoteNotificationTemplateChange. It tells me that we probably we would need to rethink some of the dependencies between the ChangeModule, LayoutModuleand NotificationTemplateModule.

@@ -28,7 +28,7 @@ describe('Bulk invite members - /invites/bulk (POST)', async () => {
.send({
invitees: [
{
email: 'asdasda',
email: 'email@bad',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid CSpell to complain.

import { MessageTemplateModule } from '../message-template/message-template.module';
import { SharedModule } from '../shared/shared.module';

@Module({
imports: [SharedModule, MessageTemplateModule],
imports: [SharedModule, ChangeModule, MessageTemplateModule],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need CreateChange use case inside Layout module for being able to create all the changes through CreateLayoutChange.

Comment on lines 12 to 16
export class CreateLayoutChangeUseCase {
constructor(private createChange: CreateChange, private layoutRepository: LayoutRepository) {}

async execute(command: CreateLayoutChangeCommand): Promise<void> {
const item = await this.layoutRepository.findById(command.layoutId, command.environmentId);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generic use case to be reused in all the Layout use cases where we need to track a change.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the case of create change after delete-layout, this will not find the deleted one @p-fernandez

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do we handle deletions? With the soft delete should be able to pick it up. Don't know how mongo-delete works 100%.

Copy link
Contributor

Choose a reason for hiding this comment

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

I made a suggestion in this pr for a find soft deleted layouts. Let me know what you think :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the change creation for a deletion would need to use that new method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe if he doesn't find the item like this, then do the findDeleted

@@ -19,6 +21,7 @@ export class SetDefaultLayoutUseCase {
try {
if (defaultLayoutId) {
await this.setIsDefaultForLayout(defaultLayoutId, command.environmentId, command.organizationId, false);
await this.createLayoutChangeForPreviousDefault(command, defaultLayoutId);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we make non default the default layout, we need to keep track of that change. Not totally happy as this could be easily overlooked in a change of logic. Worth discuss it.

@p-fernandez p-fernandez marked this pull request as ready for review January 22, 2023 16:40
@p-fernandez p-fernandez force-pushed the nv-1502-changes-create-a-layout-change branch from 8949d3d to f755eff Compare January 22, 2023 16:41
@p-fernandez
Copy link
Contributor Author

Tests will go in the promote layout changes PR.

await this.createChange(command);
}

private async createChange(command: DeleteLayoutCommand): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this function needed? Doesn't it do the same thing by creating the command?
Maybe you meant to remove the first CreateLayoutChangeCommand in line 39?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just holds the create layout change logic to not clutter the execute method. Nothing else. 🙂

@p-fernandez p-fernandez force-pushed the nv-1502-changes-create-a-layout-change branch from f755eff to d5b7959 Compare January 23, 2023 11:39
@p-fernandez p-fernandez force-pushed the nv-1502-changes-create-a-layout-change branch from d5b7959 to a9b47e0 Compare January 23, 2023 11:41
@p-fernandez p-fernandez merged commit 23b7425 into feat-layouts Jan 23, 2023
@p-fernandez p-fernandez deleted the nv-1502-changes-create-a-layout-change branch January 23, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants