@tndhuy/create-app 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/mongo/src/common/interceptors/transform.interceptor.ts +14 -1
- package/templates/mongo/src/modules/example/application/queries/list-items.handler.ts +13 -2
- package/templates/mongo/src/modules/example/presenter/item.controller.ts +1 -2
- package/templates/postgres/src/common/interceptors/transform.interceptor.ts +14 -1
- package/templates/postgres/src/modules/example/application/queries/list-items.handler.ts +13 -2
- package/templates/postgres/src/modules/example/presenter/item.controller.ts +1 -2
package/package.json
CHANGED
|
@@ -31,6 +31,19 @@ export class TransformInterceptor<T> implements NestInterceptor<T, unknown> {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Public API: Wrap response in a standardized success object
|
|
34
|
-
return next.handle().pipe(
|
|
34
|
+
return next.handle().pipe(
|
|
35
|
+
map((data) => {
|
|
36
|
+
// Handle paginated results: { items: [], meta: {} }
|
|
37
|
+
if (data && typeof data === 'object' && 'items' in data && 'meta' in data) {
|
|
38
|
+
return {
|
|
39
|
+
success: true,
|
|
40
|
+
data: data.items,
|
|
41
|
+
meta: data.meta,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { success: true, data };
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
35
48
|
}
|
|
36
49
|
}
|
|
@@ -3,6 +3,7 @@ import { Inject } from '@nestjs/common';
|
|
|
3
3
|
import { ListItemsQuery } from './list-items.query';
|
|
4
4
|
import { ITEM_REPOSITORY, IItemRepository } from '../../domain/item.repository.interface';
|
|
5
5
|
import { Item } from '../../domain/item.entity';
|
|
6
|
+
import { PaginationMeta } from '../../../shared/dto/pagination.dto';
|
|
6
7
|
|
|
7
8
|
@QueryHandler(ListItemsQuery)
|
|
8
9
|
export class ListItemsHandler implements IQueryHandler<ListItemsQuery> {
|
|
@@ -10,7 +11,17 @@ export class ListItemsHandler implements IQueryHandler<ListItemsQuery> {
|
|
|
10
11
|
@Inject(ITEM_REPOSITORY) private readonly itemRepository: IItemRepository,
|
|
11
12
|
) {}
|
|
12
13
|
|
|
13
|
-
async execute(_query: ListItemsQuery): Promise<Item[]> {
|
|
14
|
-
|
|
14
|
+
async execute(_query: ListItemsQuery): Promise<{ items: Item[]; meta: PaginationMeta }> {
|
|
15
|
+
const items = await this.itemRepository.findAll();
|
|
16
|
+
|
|
17
|
+
// Example metadata — in a real app, these values would come from the database query
|
|
18
|
+
const meta: PaginationMeta = {
|
|
19
|
+
total: items.length,
|
|
20
|
+
page: 1,
|
|
21
|
+
limit: 20,
|
|
22
|
+
totalPages: Math.ceil(items.length / 20) || 1,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return { items, meta };
|
|
15
26
|
}
|
|
16
27
|
}
|
|
@@ -11,6 +11,7 @@ import { ListItemsQuery } from '../application/queries/list-items.query';
|
|
|
11
11
|
import { PaginationDto } from '../../../shared';
|
|
12
12
|
|
|
13
13
|
@ApiTags('example')
|
|
14
|
+
@PublicApi()
|
|
14
15
|
@Controller('items')
|
|
15
16
|
export class ItemController {
|
|
16
17
|
constructor(
|
|
@@ -35,7 +36,6 @@ export class ItemController {
|
|
|
35
36
|
return this.commandBus.execute(new DeleteItemCommand(id));
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
@PublicApi()
|
|
39
39
|
@Get(':id')
|
|
40
40
|
@ApiOperation({ summary: 'Get an item by ID' })
|
|
41
41
|
@ApiParam({ name: 'id', description: 'Item UUID' })
|
|
@@ -45,7 +45,6 @@ export class ItemController {
|
|
|
45
45
|
return this.queryBus.execute(new GetItemQuery(id));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
@PublicApi()
|
|
49
48
|
@Get()
|
|
50
49
|
@ApiOperation({ summary: 'List all items with pagination' })
|
|
51
50
|
@ApiResponse({ status: 200, description: 'List of items', type: [ItemResponseDto] })
|
|
@@ -31,6 +31,19 @@ export class TransformInterceptor<T> implements NestInterceptor<T, unknown> {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Public API: Wrap response in a standardized success object
|
|
34
|
-
return next.handle().pipe(
|
|
34
|
+
return next.handle().pipe(
|
|
35
|
+
map((data) => {
|
|
36
|
+
// Handle paginated results: { items: [], meta: {} }
|
|
37
|
+
if (data && typeof data === 'object' && 'items' in data && 'meta' in data) {
|
|
38
|
+
return {
|
|
39
|
+
success: true,
|
|
40
|
+
data: data.items,
|
|
41
|
+
meta: data.meta,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { success: true, data };
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
35
48
|
}
|
|
36
49
|
}
|
|
@@ -3,6 +3,7 @@ import { Inject } from '@nestjs/common';
|
|
|
3
3
|
import { ListItemsQuery } from './list-items.query';
|
|
4
4
|
import { ITEM_REPOSITORY, IItemRepository } from '../../domain/item.repository.interface';
|
|
5
5
|
import { Item } from '../../domain/item.entity';
|
|
6
|
+
import { PaginationMeta } from '../../../shared/dto/pagination.dto';
|
|
6
7
|
|
|
7
8
|
@QueryHandler(ListItemsQuery)
|
|
8
9
|
export class ListItemsHandler implements IQueryHandler<ListItemsQuery> {
|
|
@@ -10,7 +11,17 @@ export class ListItemsHandler implements IQueryHandler<ListItemsQuery> {
|
|
|
10
11
|
@Inject(ITEM_REPOSITORY) private readonly itemRepository: IItemRepository,
|
|
11
12
|
) {}
|
|
12
13
|
|
|
13
|
-
async execute(_query: ListItemsQuery): Promise<Item[]> {
|
|
14
|
-
|
|
14
|
+
async execute(_query: ListItemsQuery): Promise<{ items: Item[]; meta: PaginationMeta }> {
|
|
15
|
+
const items = await this.itemRepository.findAll();
|
|
16
|
+
|
|
17
|
+
// Example metadata — in a real app, these values would come from the database query
|
|
18
|
+
const meta: PaginationMeta = {
|
|
19
|
+
total: items.length,
|
|
20
|
+
page: 1,
|
|
21
|
+
limit: 20,
|
|
22
|
+
totalPages: Math.ceil(items.length / 20) || 1,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return { items, meta };
|
|
15
26
|
}
|
|
16
27
|
}
|
|
@@ -11,6 +11,7 @@ import { ListItemsQuery } from '../application/queries/list-items.query';
|
|
|
11
11
|
import { PaginationDto } from '../../../shared';
|
|
12
12
|
|
|
13
13
|
@ApiTags('example')
|
|
14
|
+
@PublicApi()
|
|
14
15
|
@Controller('items')
|
|
15
16
|
export class ItemController {
|
|
16
17
|
constructor(
|
|
@@ -35,7 +36,6 @@ export class ItemController {
|
|
|
35
36
|
return this.commandBus.execute(new DeleteItemCommand(id));
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
@PublicApi()
|
|
39
39
|
@Get(':id')
|
|
40
40
|
@ApiOperation({ summary: 'Get an item by ID' })
|
|
41
41
|
@ApiParam({ name: 'id', description: 'Item UUID' })
|
|
@@ -45,7 +45,6 @@ export class ItemController {
|
|
|
45
45
|
return this.queryBus.execute(new GetItemQuery(id));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
@PublicApi()
|
|
49
48
|
@Get()
|
|
50
49
|
@ApiOperation({ summary: 'List all items with pagination' })
|
|
51
50
|
@ApiResponse({ status: 200, description: 'List of items', type: [ItemResponseDto] })
|