-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
feat(api): create a layout change #2521
Conversation
export * from './create-change.command'; | ||
export * from './create-change.usecase'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
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, | ||
}) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
export * from './create-change.command'; | ||
export * from './create-change.usecase'; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
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, | ||
}) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree :)
f4d6d2d
to
8949d3d
Compare
@@ -14,6 +14,7 @@ export class PromoteChangeToEnvironment { | |||
constructor( | |||
private changeRepository: ChangeRepository, | |||
private environmentRepository: EnvironmentRepository, | |||
@Inject(forwardRef(() => PromoteNotificationTemplateChange)) |
There was a problem hiding this comment.
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
, LayoutModule
and NotificationTemplateModule
.
@@ -28,7 +28,7 @@ describe('Bulk invite members - /invites/bulk (POST)', async () => { | |||
.send({ | |||
invitees: [ | |||
{ | |||
email: 'asdasda', | |||
email: 'email@bad', |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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
.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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%.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
8949d3d
to
f755eff
Compare
Tests will go in the promote layout changes PR. |
await this.createChange(command); | ||
} | ||
|
||
private async createChange(command: DeleteLayoutCommand): Promise<void> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. 🙂
f755eff
to
d5b7959
Compare
d5b7959
to
a9b47e0
Compare
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)