-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add get record query handler
- Loading branch information
Chenqin Nee
authored and
Chenqin Nee
committed
Dec 15, 2022
1 parent
3d10a49
commit 628108e
Showing
8 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/core/queries/get-record/get-record.query.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,18 @@ | ||
import type { IQueryHandler } from '@egodb/domain' | ||
import type { IRecordQueryModel } from '../../record' | ||
import { WithRecordId } from '../../record' | ||
import type { ITableRepository } from '../../table.repository' | ||
import type { GetRecordQuery } from './get-record.query' | ||
import type { IGetRecordOutput } from './get-record.query.interface' | ||
|
||
export class GetRecordQueryHandler implements IQueryHandler<GetRecordQuery, IGetRecordOutput> { | ||
constructor(protected readonly tableRepo: ITableRepository, protected readonly rm: IRecordQueryModel) {} | ||
|
||
async execute(query: GetRecordQuery): Promise<IGetRecordOutput> { | ||
const spec = WithRecordId.fromString(query.id) | ||
|
||
const record = (await this.rm.findOne(spec)).unwrap() | ||
|
||
return record | ||
} | ||
} |
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,6 @@ | ||
import * as z from 'zod' | ||
import { recordIdSchema } from '../../record' | ||
|
||
export const getRecordQueryInput = z.object({ | ||
id: recordIdSchema, | ||
}) |
6 changes: 6 additions & 0 deletions
6
packages/core/queries/get-record/get-record.query.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,6 @@ | ||
import type * as z from 'zod' | ||
import type { getRecordQueryInput } from './get-record.query.input' | ||
import type { getRecordQueryOutput } from './get-record.query.output' | ||
|
||
export type IGetRecordQuery = z.infer<typeof getRecordQueryInput> | ||
export type IGetRecordOutput = z.infer<typeof getRecordQueryOutput> |
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 @@ | ||
import { queryRecordSchema } from '../../record' | ||
|
||
export const getRecordQueryOutput = queryRecordSchema.optional() |
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,10 @@ | ||
import { Query } from '@egodb/domain' | ||
import type { IGetRecordQuery } from './get-record.query.interface' | ||
|
||
export class GetRecordQuery extends Query implements IGetRecordQuery { | ||
readonly id: string | ||
constructor(query: IGetRecordQuery) { | ||
super() | ||
this.id = query.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './get-record.query' | ||
export * from './get-record.query.handler' | ||
export * from './get-record.query.input' | ||
export * from './get-record.query.interface' | ||
export * from './get-record.query.output' |
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,3 +1,4 @@ | ||
export * from './get-record' | ||
export * from './get-records' | ||
export * from './get-table' | ||
export * from './get-tables' |
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