Skip to content

Commit bedc66b

Browse files
committed
WIP implements projection type
1 parent 5c871ff commit bedc66b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

service/src/_common/helpers/pick-projection.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export function PickProjectionHelper<T, K extends keyof T>(
77
[key in keyof T]?: number | 1 | 0
88
},
99
): Type<Pick<T, (readonly K[])[number]>> {
10-
const keys = Object.keys(projection)
10+
const keys = Object.keys(projection).filter((key) => projection[key] === 1)
1111
return PickType(classRef, keys as K[])
1212
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type PartialProjectionType<T> = {
2+
[key in keyof T]?: number | 1 | 0
3+
}

service/src/core/categories/categories.controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator'
1818
import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator'
1919
import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator'
2020
import { PickProjectionHelper } from '~/_common/helpers/pick-projection.helper'
21+
import { PartialProjectionType } from '~/_common/types/partial-projection.type'
2122

2223
@Controller('categories')
2324
export class CategoriesController extends AbstractController {
24-
protected static readonly projection = {
25+
26+
protected static readonly projection: PartialProjectionType<CategoriesDto> = {
2527
name: 1,
2628
parentId: 1,
2729
description: 1,
2830
color: 1,
29-
icon: 1,
31+
icon: 0,
3032
}
3133

3234
constructor(private readonly _service: CategoriesService) {

0 commit comments

Comments
 (0)