@tndhuy/create-app 1.2.6 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tndhuy/create-app",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "create-app": "dist/cli.js"
@@ -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(map((data) => ({ success: true, data })));
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
- return this.itemRepository.findAll();
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
  }
@@ -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(map((data) => ({ success: true, data })));
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
- return this.itemRepository.findAll();
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
  }