Skip to content

Commit

Permalink
feat(core): create option command & handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Jan 2, 2023
1 parent 89f891d commit 042fe53
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CreateOptionCommand, CreateOptionCommandHandler as DomainHandler, type ITableRepository } from '@egodb/core'
import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { InjectTableReposiory } from '../adapters'

@CommandHandler(CreateOptionCommand)
export class CreateOptionCommandHandler extends DomainHandler implements ICommandHandler<CreateOptionCommand> {
constructor(
@InjectTableReposiory()
protected readonly repo: ITableRepository,
) {
super(repo)
}
}
2 changes: 2 additions & 0 deletions apps/backend/src/modules/table/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CreateFieldCommandHandler } from './create-field.command.handler'
import { CreateOptionCommandHandler } from './create-option.command.handler'
import { CreateRecordCommandHandler } from './create-record.command.handler'
import { CreateTableCommandHandler } from './create-table.command.handler'
import { EditTableCommandHandler } from './edit-table.command.handler'
Expand All @@ -14,6 +15,7 @@ export const commandHandlers = [
CreateTableCommandHandler,
CreateRecordCommandHandler,
CreateFieldCommandHandler,
CreateOptionCommandHandler,
SetFiltersCommandHandler,
SetKanbanFieldCommandHandler,
SetFieldWidthCommandHandler,
Expand Down
9 changes: 9 additions & 0 deletions apps/web/components/kanban-ui/new-stack-lane.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Button, IconPlus } from '@egodb/ui'

export const NewStackLane: React.FC = () => {
return (
<Button w={300} variant="white" leftIcon={<IconPlus />}>
New Stack
</Button>
)
}
5 changes: 4 additions & 1 deletion apps/web/components/kanban-ui/select-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { trpc } from '../../trpc'
import type { ITableBaseProps } from '../table/table-base-props'
import { openKanbanEditFieldAtom } from './kanban-edit-field.atom'
import { KanbanLane, SortableKanbanLane } from './kanban-lane'
import { NewStackLane } from './new-stack-lane'
import { SelectKanbanField } from './select-kanban-field'

interface IProps extends ITableBaseProps {
Expand Down Expand Up @@ -67,7 +68,7 @@ export const SelectBoard: React.FC<IProps> = ({ table, field, records }) => {
</Modal>
)}

<Group>
<Group align="start">
<KanbanLane table={table} field={field} records={records} title="uncategorized" id={null} />

<DndContext
Expand Down Expand Up @@ -115,6 +116,8 @@ export const SelectBoard: React.FC<IProps> = ({ table, field, records }) => {
/>
</DragOverlay>
</DndContext>

<NewStackLane />
</Group>
</Container>
)
Expand Down
15 changes: 15 additions & 0 deletions packages/core/commands/create-option/create-option.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { CommandProps } from '@egodb/domain'
import { Command } from '@egodb/domain'
import type { ICreateOptionSchema } from '../../option'
import type { ICreateOptionCommandInput } from './create-table.command.interface'

export class CreateOptionCommand extends Command implements ICreateOptionCommandInput {
readonly tableId: string
readonly option: ICreateOptionSchema

constructor(props: CommandProps<ICreateOptionCommandInput>) {
super(props)
this.tableId = props.tableId
this.option = props.option
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type ICommandHandler } from '@egodb/domain'
import type { ITableRepository } from '../../table.repository'
import type { CreateOptionCommand } from './create-option.command'

type ICreateOptionCommandHandler = ICommandHandler<CreateOptionCommand, void>

export class CreateOptionCommandHandler implements ICreateOptionCommandHandler {
constructor(protected readonly repo: ITableRepository) {}

async execute(command: CreateOptionCommand): Promise<void> {
const table = (await this.repo.findOneById(command.tableId)).unwrap()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as z from 'zod'
import { createOptionSchema } from '../../option'
import { tableIdSchema } from '../../value-objects'

export const createOptionCommandInput = z.object({
tableId: tableIdSchema,
option: createOptionSchema,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type * as z from 'zod'
import type { createOptionCommandInput } from './create-table.command.input'

export type ICreateOptionCommandInput = z.infer<typeof createOptionCommandInput>
4 changes: 4 additions & 0 deletions packages/core/commands/create-option/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './create-option.command'
export * from './create-table.command.handler'
export * from './create-table.command.input'
export * from './create-table.command.interface'
1 change: 1 addition & 0 deletions packages/core/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './create-field'
export * from './create-option'
export * from './create-record'
export * from './create-table'
export * from './edit-table'
Expand Down

0 comments on commit 042fe53

Please sign in to comment.