-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): update record command & handler
- Loading branch information
Showing
9 changed files
with
86 additions
and
9 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
22 changes: 22 additions & 0 deletions
22
apps/backend/src/modules/table/commands/update-record.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 { | ||
IRecordRepository, | ||
ITableRepository, | ||
UpdateRecordCommand, | ||
UpdateRecordCommandHandler as DomainHandler, | ||
} from '@egodb/core' | ||
import type { ICommandHandler } from '@nestjs/cqrs' | ||
import { CommandHandler } from '@nestjs/cqrs' | ||
import { InjectRecordReposiory, InjectTableReposiory } from '../adapters' | ||
|
||
@CommandHandler(UpdateRecordCommand) | ||
export class UpdateRecordCommandHandler extends DomainHandler implements ICommandHandler<UpdateRecordCommand> { | ||
constructor( | ||
@InjectTableReposiory() | ||
protected readonly tableRepo: ITableRepository, | ||
|
||
@InjectRecordReposiory() | ||
protected readonly recordRepo: IRecordRepository, | ||
) { | ||
super(tableRepo, recordRepo) | ||
} | ||
} |
11 changes: 2 additions & 9 deletions
11
packages/core/commands/create-record/create-record.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 |
---|---|---|
@@ -1,18 +1,11 @@ | ||
import * as z from 'zod' | ||
import { createFieldValueSchema, fieldNameSchema } from '../../field' | ||
import { mutateRecordValueSchema } from '../../record/record.schema' | ||
import { recordIdSchema } from '../../record/value-objects/record-id.vo' | ||
import { tableIdSchema } from '../../value-objects' | ||
|
||
export const createRecordCommandInput = z.object({ | ||
tableId: tableIdSchema, | ||
id: recordIdSchema.optional(), | ||
value: z | ||
.array( | ||
z.object({ | ||
name: fieldNameSchema, | ||
value: createFieldValueSchema, | ||
}), | ||
) | ||
.min(1), | ||
value: mutateRecordValueSchema, | ||
}) | ||
export type ICreateRecordInput = z.infer<typeof createRecordCommandInput> |
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,3 @@ | ||
export * from './update-record.comand' | ||
export * from './update-record.command.handler' | ||
export * from './update-record.command.input' |
17 changes: 17 additions & 0 deletions
17
packages/core/commands/update-record/update-record.comand.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,17 @@ | ||
import type { CommandProps } from '@egodb/domain' | ||
import { Command } from '@egodb/domain' | ||
import type { IMutateRecordValueSchema } from '../../record/record.schema' | ||
import type { IUpdateRecordCommandInput } from './update-record.command.input' | ||
|
||
export class UpdateRecordCommand extends Command implements IUpdateRecordCommandInput { | ||
readonly id?: string | ||
readonly tableId: string | ||
readonly value: IMutateRecordValueSchema | ||
|
||
constructor(props: CommandProps<IUpdateRecordCommandInput>) { | ||
super(props) | ||
this.tableId = props.tableId | ||
this.id = props.id | ||
this.value = props.value | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/core/commands/update-record/update-record.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 '@egodb/domain' | ||
import type { IRecordRepository } from '../../record/repository' | ||
import type { ITableRepository } from '../../table.repository' | ||
import type { UpdateRecordCommand } from './update-record.comand' | ||
|
||
export class UpdateRecordCommandHandler implements ICommandHandler<UpdateRecordCommand, void> { | ||
constructor(protected readonly tableRepo: ITableRepository, protected readonly recordRepo: IRecordRepository) {} | ||
|
||
async execute(command: UpdateRecordCommand): Promise<void> { | ||
const table = (await this.tableRepo.findOneById(command.tableId)).unwrap() | ||
|
||
// const record = table.createRecord(command) | ||
// await this.recordRepo.insert(record) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/core/commands/update-record/update-record.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,11 @@ | ||
import * as z from 'zod' | ||
import { mutateRecordValueSchema } from '../../record/record.schema' | ||
import { recordIdSchema } from '../../record/value-objects/record-id.vo' | ||
import { tableIdSchema } from '../../value-objects' | ||
|
||
export const updateRecordCommandInput = z.object({ | ||
tableId: tableIdSchema, | ||
id: recordIdSchema.optional(), | ||
value: mutateRecordValueSchema, | ||
}) | ||
export type IUpdateRecordCommandInput = z.infer<typeof updateRecordCommandInput> |
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,13 @@ | ||
import { z } from 'zod' | ||
import { createFieldValueSchema } from '../field' | ||
import { fieldNameSchema } from '../field/value-objects/field-name.vo' | ||
|
||
export const mutateRecordValueSchema = z | ||
.array( | ||
z.object({ | ||
name: fieldNameSchema, | ||
value: createFieldValueSchema, | ||
}), | ||
) | ||
.min(1) | ||
export type IMutateRecordValueSchema = z.infer<typeof mutateRecordValueSchema> |