@tndhuy/create-app 1.2.6 → 1.2.8

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.8",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "create-app": "dist/cli.js"
@@ -2,7 +2,6 @@ import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nes
2
2
  import { Reflector } from '@nestjs/core';
3
3
  import { Observable } from 'rxjs';
4
4
  import { map } from 'rxjs/operators';
5
- import { PUBLIC_API_KEY } from '../decorators/public-api.decorator';
6
5
 
7
6
  export const RAW_RESPONSE_KEY = 'raw_response';
8
7
 
@@ -20,17 +19,20 @@ export class TransformInterceptor<T> implements NestInterceptor<T, unknown> {
20
19
  return next.handle();
21
20
  }
22
21
 
23
- const isPublic = this.reflector.getAllAndOverride<boolean>(PUBLIC_API_KEY, [
24
- context.getHandler(),
25
- context.getClass(),
26
- ]);
27
-
28
- // Internal first: If not explicitly marked as Public API, return RAW data
29
- if (!isPublic) {
30
- return next.handle();
31
- }
22
+ // Wrap all responses in a standardized success object
23
+ return next.handle().pipe(
24
+ map((data) => {
25
+ // Handle paginated results: { items: [], meta: {} }
26
+ if (data && typeof data === 'object' && 'items' in data && 'meta' in data) {
27
+ return {
28
+ success: true,
29
+ data: data.items,
30
+ meta: data.meta,
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 { success: true, data };
35
+ }),
36
+ );
35
37
  }
36
38
  }
@@ -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
  }
@@ -2,7 +2,6 @@ import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nes
2
2
  import { Reflector } from '@nestjs/core';
3
3
  import { Observable } from 'rxjs';
4
4
  import { map } from 'rxjs/operators';
5
- import { PUBLIC_API_KEY } from '../decorators/public-api.decorator';
6
5
 
7
6
  export const RAW_RESPONSE_KEY = 'raw_response';
8
7
 
@@ -20,17 +19,20 @@ export class TransformInterceptor<T> implements NestInterceptor<T, unknown> {
20
19
  return next.handle();
21
20
  }
22
21
 
23
- const isPublic = this.reflector.getAllAndOverride<boolean>(PUBLIC_API_KEY, [
24
- context.getHandler(),
25
- context.getClass(),
26
- ]);
27
-
28
- // Internal first: If not explicitly marked as Public API, return RAW data
29
- if (!isPublic) {
30
- return next.handle();
31
- }
22
+ // Wrap all responses in a standardized success object
23
+ return next.handle().pipe(
24
+ map((data) => {
25
+ // Handle paginated results: { items: [], meta: {} }
26
+ if (data && typeof data === 'object' && 'items' in data && 'meta' in data) {
27
+ return {
28
+ success: true,
29
+ data: data.items,
30
+ meta: data.meta,
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 { success: true, data };
35
+ }),
36
+ );
35
37
  }
36
38
  }
@@ -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
  }