-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1514 from undb-xyz/feature/set-field-display
feat: set field display handler
- Loading branch information
Showing
14 changed files
with
137 additions
and
4 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
15 changes: 15 additions & 0 deletions
15
apps/backend/src/core/table/commands/set-field-display.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,15 @@ | ||
import type { ICommandHandler } from '@nestjs/cqrs' | ||
import { CommandHandler } from '@nestjs/cqrs' | ||
import { type ITableRepository } from '@undb/core' | ||
import { SetFieldDisplayCommandHandler as DomainHandler, SetFieldDisplayCommand } from '@undb/cqrs' | ||
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js' | ||
|
||
@CommandHandler(SetFieldDisplayCommand) | ||
export class SetFieldDisplayCommandHandler extends DomainHandler implements ICommandHandler<SetFieldDisplayCommand> { | ||
constructor( | ||
@InjectTableRepository() | ||
protected readonly repo: ITableRepository, | ||
) { | ||
super(repo) | ||
} | ||
} |
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
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,4 @@ | ||
export * from './set-field-display.command.handler.js' | ||
export * from './set-field-display.command.input.js' | ||
export * from './set-field-display.command.interface.js' | ||
export * from './set-field-display.command.js' |
19 changes: 19 additions & 0 deletions
19
packages/cqrs/src/commands/set-field-display/set-field-display.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,19 @@ | ||
import type { ITableRepository } from '@undb/core' | ||
import type { ICommandHandler } from '@undb/domain' | ||
import type { SetFieldDisplayCommand } from './set-field-display.command.js' | ||
|
||
type ISetFieldDisplayCommandHandler = ICommandHandler<SetFieldDisplayCommand, void> | ||
|
||
export class SetFieldDisplayCommandHandler implements ISetFieldDisplayCommandHandler { | ||
constructor(protected readonly repo: ITableRepository) {} | ||
|
||
async execute(command: SetFieldDisplayCommand): Promise<void> { | ||
const table = (await this.repo.findOneById(command.tableId)).unwrap() | ||
|
||
const spec = table.setFieldDisplay(command.fieldId, command.display) | ||
|
||
if (spec.isSome()) { | ||
await this.repo.updateOneById(command.tableId, spec.unwrap()) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/cqrs/src/commands/set-field-display/set-field-display.command.input.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,8 @@ | ||
import { fieldIdSchema, tableIdSchema } from '@undb/core' | ||
import { z } from 'zod' | ||
|
||
export const setFieldDisplaysCommandInput = z.object({ | ||
tableId: tableIdSchema, | ||
fieldId: fieldIdSchema, | ||
display: z.boolean(), | ||
}) |
4 changes: 4 additions & 0 deletions
4
packages/cqrs/src/commands/set-field-display/set-field-display.command.interface.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,4 @@ | ||
import type { z } from 'zod' | ||
import type { setFieldDisplaysCommandInput } from './set-field-display.command.input.js' | ||
|
||
export type ISetFieldDisplayCommandInput = z.infer<typeof setFieldDisplaysCommandInput> |
16 changes: 16 additions & 0 deletions
16
packages/cqrs/src/commands/set-field-display/set-field-display.command.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,16 @@ | ||
import type { CommandProps } from '@undb/domain' | ||
import { Command } from '@undb/domain' | ||
import type { ISetFieldDisplayCommandInput } from './set-field-display.command.interface.js' | ||
|
||
export class SetFieldDisplayCommand extends Command implements ISetFieldDisplayCommandInput { | ||
readonly tableId: string | ||
readonly fieldId: string | ||
readonly display: boolean | ||
|
||
constructor(props: CommandProps<ISetFieldDisplayCommandInput>) { | ||
super(props) | ||
this.tableId = props.tableId | ||
this.fieldId = props.fieldId | ||
this.display = props.display | ||
} | ||
} |
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