-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from "@undb/zod" | ||
import { baseIdSchema } from "../value-objects" | ||
|
||
export const deleteBaseDTO = z.object({ | ||
id: baseIdSchema, | ||
}) | ||
|
||
export type IDeleteBaseDTO = z.infer<typeof deleteBaseDTO> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from "./base.dto" | ||
export * from "./create-base.dto" | ||
export * from "./delete-base.dto" | ||
export * from "./duplicate-base.dto" | ||
export * from "./update-base.dto" |
22 changes: 22 additions & 0 deletions
22
packages/command-handlers/src/handlers/delete-base.command-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { injectBaseRepository, type IBaseRepository } from "@undb/base" | ||
import { DeleteBaseCommand } from "@undb/commands" | ||
import { commandHandler } from "@undb/cqrs" | ||
import { singleton } from "@undb/di" | ||
import { type ICommandHandler } from "@undb/domain" | ||
|
||
@commandHandler(DeleteBaseCommand) | ||
@singleton() | ||
export class DeleteBaseCommandHandler implements ICommandHandler<DeleteBaseCommand, any> { | ||
constructor( | ||
@injectBaseRepository() | ||
private readonly repository: IBaseRepository, | ||
) {} | ||
|
||
async execute(command: DeleteBaseCommand): Promise<any> { | ||
const base = (await this.repository.findOneById(command.id)).expect("base not found") | ||
|
||
await this.repository.deleteOneById(base.id.value) | ||
|
||
return base.id.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { deleteBaseDTO } from "@undb/base" | ||
import { Command, type CommandProps } from "@undb/domain" | ||
import { z } from "@undb/zod" | ||
|
||
export const deleteBaseCommand = deleteBaseDTO | ||
|
||
export type IDeleteBaseCommand = z.infer<typeof deleteBaseCommand> | ||
|
||
export class DeleteBaseCommand extends Command implements IDeleteBaseCommand { | ||
public readonly id: string | ||
|
||
constructor(props: CommandProps<IDeleteBaseCommand>) { | ||
super(props) | ||
this.id = props.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters