@greatapps/common 1.1.274 → 1.1.276

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.
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import { withAction } from '../../../utils/withAction';
5
+ import { createCardAction } from '../actions/create-card.action';
6
+ import { CreateCardRequest } from '../types';
7
+ import { CARDS_QUERY_KEY } from './cards.hook';
8
+
9
+ export function useCreateCard() {
10
+ const queryClient = useQueryClient();
11
+
12
+ return useMutation({
13
+ mutationFn: (data: CreateCardRequest) => withAction(createCardAction)(data),
14
+ onSuccess: () => {
15
+ queryClient.invalidateQueries({ queryKey: CARDS_QUERY_KEY });
16
+ },
17
+ });
18
+ }
@@ -1,10 +1,10 @@
1
1
  import 'server-only';
2
2
 
3
3
  import { api } from '../../../infra/api/client';
4
- import { ApiError, ApiPaginatedActionResult, PaginatedSuccessResult } from '../../../infra/api/types';
4
+ import { ApiError, ApiPaginatedActionResult, PaginatedSuccessResult, SuccessResult } from '../../../infra/api/types';
5
5
  import { buildQueryParams } from '../../../infra/utils/params';
6
6
  import { getUserContext } from '../../auth/utils/get-user-context';
7
- import { Card, CardSchema } from '../types';
7
+ import { Card, CardSchema, CreateCardRequest } from '../types';
8
8
 
9
9
  class CardsService {
10
10
  async listCards(): Promise<PaginatedSuccessResult<Card>> {
@@ -27,6 +27,25 @@ class CardsService {
27
27
 
28
28
  return { data, total: response.total, success: true };
29
29
  }
30
+ async createCard(data: CreateCardRequest): Promise<SuccessResult<Card>> {
31
+ const { id_account } = await getUserContext();
32
+
33
+ const response = await api.apps.post<ApiPaginatedActionResult<Card>>(
34
+ `/accounts/${id_account}/cards`,
35
+ data
36
+ );
37
+
38
+ if (response.status === 0) {
39
+ throw new ApiError(response.message || 'Erro ao criar cartão', 'CREATE_CARD_FAILED', 400);
40
+ }
41
+
42
+ const cardData = CardSchema.parse(response.data[0]);
43
+
44
+ return {
45
+ success: true,
46
+ data: cardData,
47
+ } satisfies SuccessResult<Card>;
48
+ }
30
49
  }
31
50
 
32
51
  export const cardsService = new CardsService();
package/src/server.ts CHANGED
@@ -22,6 +22,7 @@ export { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.acti
22
22
  export { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';
23
23
  export { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';
24
24
  export { listCardsAction } from './modules/cards/actions/list-cards.action';
25
+ export { createCardAction } from './modules/cards/actions/create-card.action';
25
26
  export { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';
26
27
  export { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';
27
28