@greatapps/common 1.1.621 → 1.1.623
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/dist/modules/cards/hooks/cards.hook.mjs +5 -1
- package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/delete-card.hook.mjs +1 -3
- package/dist/modules/cards/hooks/delete-card.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/list-plans.hook.mjs +2 -2
- package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +2 -2
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/dist/modules/plans/services/plans.service.mjs +3 -1
- package/dist/modules/plans/services/plans.service.mjs.map +1 -1
- package/package.json +1 -1
- package/src/modules/cards/hooks/cards.hook.ts +4 -0
- package/src/modules/cards/hooks/delete-card.hook.ts +1 -3
- package/src/modules/plans/hooks/list-plans.hook.ts +2 -2
- package/src/modules/plans/hooks/use-plan-by-id.hook.ts +2 -2
- package/src/modules/plans/services/plans.service.ts +3 -1
|
@@ -10,7 +10,11 @@ function useCards() {
|
|
|
10
10
|
queryFn: async () => {
|
|
11
11
|
const { listCardsAction } = await import("../actions/list-cards.action");
|
|
12
12
|
return withAction(listCardsAction)();
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
select: (result) => ({
|
|
15
|
+
...result,
|
|
16
|
+
data: result.data.filter((card) => !card.deleted)
|
|
17
|
+
})
|
|
14
18
|
});
|
|
15
19
|
}
|
|
16
20
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/cards/hooks/cards.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const CARDS_QUERY_KEY = ['cards'] as const;\n\nexport function useCards() {\n const queryKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: async () => {\n const { listCardsAction } = await import('../actions/list-cards.action');\n return withAction(listCardsAction)();\n },\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEzB,MAAM,kBAAkB,CAAC,OAAO;AAEhC,SAAS,WAAW;AACzB,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,YAAY;AACnB,YAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,8BAA8B;AACvE,aAAO,WAAW,eAAe,EAAE;AAAA,IACrC;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/cards.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const CARDS_QUERY_KEY = ['cards'] as const;\n\nexport function useCards() {\n const queryKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: async () => {\n const { listCardsAction } = await import('../actions/list-cards.action');\n return withAction(listCardsAction)();\n },\n select: (result) => ({\n ...result,\n data: result.data.filter((card) => !card.deleted),\n }),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEzB,MAAM,kBAAkB,CAAC,OAAO;AAEhC,SAAS,WAAW;AACzB,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,YAAY;AACnB,YAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,8BAA8B;AACvE,aAAO,WAAW,eAAe,EAAE;AAAA,IACrC;AAAA,IACA,QAAQ,CAAC,YAAY;AAAA,MACnB,GAAG;AAAA,MACH,MAAM,OAAO,KAAK,OAAO,CAAC,SAAS,CAAC,KAAK,OAAO;AAAA,IAClD;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -23,9 +23,7 @@ function useDeleteCard() {
|
|
|
23
23
|
if (!old?.data) return old;
|
|
24
24
|
return {
|
|
25
25
|
...old,
|
|
26
|
-
data: old.data.
|
|
27
|
-
(card) => card.id.toString() === id ? { ...card, deleted: true } : card
|
|
28
|
-
)
|
|
26
|
+
data: old.data.filter((card) => card.id.toString() !== id)
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
29
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/cards/hooks/delete-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport type { Card } from '../types';\n\nexport function useDeleteCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n const cardKey = useAuthQueryKey(['card']);\n\n return useMutation({\n mutationFn: async (id: string) => {\n const { deleteCardAction } = await import('../actions/delete-card.action');\n return withAction(deleteCardAction)(id);\n },\n onMutate: async (id: string) => {\n await queryClient.cancelQueries({ queryKey: cardsKey });\n\n const previousQueries = queryClient.getQueriesData<PaginatedSuccessResult<Card>>({\n queryKey: cardsKey,\n });\n\n queryClient.setQueriesData<PaginatedSuccessResult<Card>>(\n { queryKey: cardsKey },\n (old) => {\n if (!old?.data) return old;\n return {\n ...old,\n data: old.data.
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/delete-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport type { Card } from '../types';\n\nexport function useDeleteCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n const cardKey = useAuthQueryKey(['card']);\n\n return useMutation({\n mutationFn: async (id: string) => {\n const { deleteCardAction } = await import('../actions/delete-card.action');\n return withAction(deleteCardAction)(id);\n },\n onMutate: async (id: string) => {\n await queryClient.cancelQueries({ queryKey: cardsKey });\n\n const previousQueries = queryClient.getQueriesData<PaginatedSuccessResult<Card>>({\n queryKey: cardsKey,\n });\n\n queryClient.setQueriesData<PaginatedSuccessResult<Card>>(\n { queryKey: cardsKey },\n (old) => {\n if (!old?.data) return old;\n return {\n ...old,\n data: old.data.filter((card) => card.id.toString() !== id),\n };\n }\n );\n\n return { previousQueries };\n },\n onError: (_err, _id, context) => {\n if (context?.previousQueries) {\n for (const [queryKey, data] of context.previousQueries) {\n queryClient.setQueryData(queryKey, data);\n }\n }\n },\n onSettled: () => {\n queryClient.invalidateQueries({ queryKey: cardsKey });\n queryClient.invalidateQueries({ queryKey: cardKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAIzB,SAAS,gBAAgB;AAC9B,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AACrD,QAAM,UAAU,gBAAgB,CAAC,MAAM,CAAC;AAExC,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,OAAe;AAChC,YAAM,EAAE,iBAAiB,IAAI,MAAM,OAAO,+BAA+B;AACzE,aAAO,WAAW,gBAAgB,EAAE,EAAE;AAAA,IACxC;AAAA,IACA,UAAU,OAAO,OAAe;AAC9B,YAAM,YAAY,cAAc,EAAE,UAAU,SAAS,CAAC;AAEtD,YAAM,kBAAkB,YAAY,eAA6C;AAAA,QAC/E,UAAU;AAAA,MACZ,CAAC;AAED,kBAAY;AAAA,QACV,EAAE,UAAU,SAAS;AAAA,QACrB,CAAC,QAAQ;AACP,cAAI,CAAC,KAAK,KAAM,QAAO;AACvB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,MAAM,IAAI,KAAK,OAAO,CAAC,SAAS,KAAK,GAAG,SAAS,MAAM,EAAE;AAAA,UAC3D;AAAA,QACF;AAAA,MACF;AAEA,aAAO,EAAE,gBAAgB;AAAA,IAC3B;AAAA,IACA,SAAS,CAAC,MAAM,KAAK,YAAY;AAC/B,UAAI,SAAS,iBAAiB;AAC5B,mBAAW,CAAC,UAAU,IAAI,KAAK,QAAQ,iBAAiB;AACtD,sBAAY,aAAa,UAAU,IAAI;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,SAAS,CAAC;AACpD,kBAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AAAA,IACrD;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { withAction } from "@greatapps/common";
|
|
4
4
|
import { listPlansAction } from "../actions/list-plans.action";
|
|
5
|
-
import {
|
|
5
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
6
6
|
const PLANS_QUERY_KEY = ["plans"];
|
|
7
7
|
function usePlans() {
|
|
8
|
-
const queryKey =
|
|
8
|
+
const queryKey = useAuthQueryKey([...PLANS_QUERY_KEY]);
|
|
9
9
|
return useQuery({
|
|
10
10
|
queryKey,
|
|
11
11
|
queryFn: withAction(listPlansAction),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/plans/hooks/list-plans.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '@greatapps/common';\nimport { listPlansAction } from '../actions/list-plans.action';\nimport type { Plan } from '../types/plan.type';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/plans/hooks/list-plans.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '@greatapps/common';\nimport { listPlansAction } from '../actions/list-plans.action';\nimport type { Plan } from '../types/plan.type';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const PLANS_QUERY_KEY = ['plans'] as const;\n\nexport function usePlans() {\n const queryKey = useAuthQueryKey([...PLANS_QUERY_KEY]);\n\n return useQuery<Plan[]>({\n queryKey,\n queryFn: withAction(listPlansAction),\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n refetchOnMount: false,\n retry: 1,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEhC,SAAS,uBAAuB;AAEzB,MAAM,kBAAkB,CAAC,OAAO;AAEhC,SAAS,WAAW;AACzB,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,SAAiB;AAAA,IACtB;AAAA,IACA,SAAS,WAAW,eAAe;AAAA,IACnC,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,sBAAsB;AAAA,IACtB,oBAAoB;AAAA,IACpB,gBAAgB;AAAA,IAChB,OAAO;AAAA,EACT,CAAC;AACH;","names":[]}
|
|
@@ -3,10 +3,10 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
3
3
|
import { withAction } from "../../../utils/withAction";
|
|
4
4
|
import { findPlanByIdAction } from "../actions/find-plan-by-id.action";
|
|
5
5
|
import { PLANS_QUERY_KEY } from "./list-plans.hook";
|
|
6
|
-
import {
|
|
6
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
7
7
|
function usePlanById(idPlan) {
|
|
8
8
|
const queryClient = useQueryClient();
|
|
9
|
-
const plansKey =
|
|
9
|
+
const plansKey = useAuthQueryKey([...PLANS_QUERY_KEY]);
|
|
10
10
|
return useQuery({
|
|
11
11
|
queryKey: [...plansKey, idPlan],
|
|
12
12
|
queryFn: withAction(() => findPlanByIdAction(idPlan)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/plans/hooks/use-plan-by-id.hook.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { withAction } from \"../../../utils/withAction\";\nimport { findPlanByIdAction } from \"../actions/find-plan-by-id.action\";\nimport type { Plan } from \"../types/plan.type\";\nimport { PLANS_QUERY_KEY } from \"./list-plans.hook\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/plans/hooks/use-plan-by-id.hook.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { withAction } from \"../../../utils/withAction\";\nimport { findPlanByIdAction } from \"../actions/find-plan-by-id.action\";\nimport type { Plan } from \"../types/plan.type\";\nimport { PLANS_QUERY_KEY } from \"./list-plans.hook\";\nimport { useAuthQueryKey } from \"../../../hooks/useAuthQueryKey\";\n\nexport function usePlanById(idPlan?: number | string | null) {\n const queryClient = useQueryClient();\n const plansKey = useAuthQueryKey([...PLANS_QUERY_KEY]);\n\n return useQuery({\n queryKey: [...plansKey, idPlan],\n queryFn: withAction(() => findPlanByIdAction(idPlan!)),\n initialData: () => {\n const queries = queryClient.getQueriesData<Plan[]>({\n queryKey: plansKey,\n });\n\n for (const [, data] of queries) {\n if (!data || !Array.isArray(data)) continue;\n const numericId = Number(idPlan);\n const plan = data.find(\n (p) => p.id === numericId || p.id_plan === numericId\n );\n if (plan) {\n return { success: true as const, data: plan };\n }\n }\n\n return undefined;\n },\n initialDataUpdatedAt: 0,\n enabled: !!idPlan,\n });\n}\n"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AACzC,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAEzB,SAAS,YAAY,QAAiC;AAC3D,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,UAAU,MAAM;AAAA,IAC9B,SAAS,WAAW,MAAM,mBAAmB,MAAO,CAAC;AAAA,IACrD,aAAa,MAAM;AACjB,YAAM,UAAU,YAAY,eAAuB;AAAA,QACjD,UAAU;AAAA,MACZ,CAAC;AAED,iBAAW,CAAC,EAAE,IAAI,KAAK,SAAS;AAC9B,YAAI,CAAC,QAAQ,CAAC,MAAM,QAAQ,IAAI,EAAG;AACnC,cAAM,YAAY,OAAO,MAAM;AAC/B,cAAM,OAAO,KAAK;AAAA,UAChB,CAAC,MAAM,EAAE,OAAO,aAAa,EAAE,YAAY;AAAA,QAC7C;AACA,YAAI,MAAM;AACR,iBAAO,EAAE,SAAS,MAAe,MAAM,KAAK;AAAA,QAC9C;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,sBAAsB;AAAA,IACtB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -11,10 +11,12 @@ class PlansService {
|
|
|
11
11
|
ambient: process.env.NODE_ENV || "development"
|
|
12
12
|
});
|
|
13
13
|
buildCacheKey(key, params) {
|
|
14
|
+
const idWl = params?.id_wl ?? "";
|
|
15
|
+
const idAccount = params?.id_account ?? "";
|
|
14
16
|
const sort = params?.sort ?? "id:ASC";
|
|
15
17
|
const active = params?.active ?? "";
|
|
16
18
|
const search = params?.search ?? "";
|
|
17
|
-
return `${key}-${sort}-${active}-${search}-
|
|
19
|
+
return `${key}-${idWl}-${idAccount}-${sort}-${active}-${search}-v3`;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Lista planos do whitelabel.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/plans/services/plans.service.ts"],"sourcesContent":["import \"server-only\";\n\nimport { api, apiClient, getUserContext } from \"@greatapps/common/server\";\nimport { ApiError, buildQueryParams, PlanSchema } from \"@greatapps/common\";\nimport type {\n ApiPaginatedActionResult,\n PaginatedSuccessResult,\n Plan,\n SuccessResult,\n} from \"@greatapps/common\";\nimport greatCache from \"@greatapps/cache\";\n\nexport type ListPlansParams = {\n sort?: string;\n active?: boolean;\n search?: string;\n};\n\nconst PLANS_CACHE_TTL = 604800;\n\nclass PlansService {\n private cache = new greatCache({\n service: \"plans\",\n version: \"1.0\",\n domain: \"whitelabel-cache.greatapps.com.br\",\n ambient: process.env.NODE_ENV || \"development\",\n });\n\n private buildCacheKey(key: string, params?: Record<string, unknown>): string {\n const sort = params?.sort ?? \"id:ASC\";\n const active = params?.active ?? \"\";\n const search = params?.search ?? \"\";\n return `${key}-${sort}-${active}-${search}-
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/plans/services/plans.service.ts"],"sourcesContent":["import \"server-only\";\n\nimport { api, apiClient, getUserContext } from \"@greatapps/common/server\";\nimport { ApiError, buildQueryParams, PlanSchema } from \"@greatapps/common\";\nimport type {\n ApiPaginatedActionResult,\n PaginatedSuccessResult,\n Plan,\n SuccessResult,\n} from \"@greatapps/common\";\nimport greatCache from \"@greatapps/cache\";\n\nexport type ListPlansParams = {\n sort?: string;\n active?: boolean;\n search?: string;\n};\n\nconst PLANS_CACHE_TTL = 604800;\n\nclass PlansService {\n private cache = new greatCache({\n service: \"plans\",\n version: \"1.0\",\n domain: \"whitelabel-cache.greatapps.com.br\",\n ambient: process.env.NODE_ENV || \"development\",\n });\n\n private buildCacheKey(key: string, params?: Record<string, unknown>): string {\n const idWl = params?.id_wl ?? \"\";\n const idAccount = params?.id_account ?? \"\";\n const sort = params?.sort ?? \"id:ASC\";\n const active = params?.active ?? \"\";\n const search = params?.search ?? \"\";\n return `${key}-${idWl}-${idAccount}-${sort}-${active}-${search}-v3`;\n }\n\n /**\n * Lista planos do whitelabel.\n * Exemplo:\n * GET /{id_wl}/plans?active=true&search=client&sort=id:ASC\n */\n async listPlans(\n params?: ListPlansParams,\n ): Promise<PaginatedSuccessResult<Plan>> {\n const { id_wl, id_account } = await getUserContext();\n const cacheKey = this.buildCacheKey(\"plans\", {\n ...params,\n id_wl,\n id_account,\n });\n\n const cachedData = await this.cache.select(cacheKey);\n\n if (cachedData.status == 1 && \"data\" in cachedData && cachedData.data) {\n const data = JSON.parse(cachedData.data) as Plan[];\n return { data, total: data.length, success: true };\n }\n\n const query = buildQueryParams({\n sort: params?.sort ?? \"id:ASC\",\n active: params?.active,\n search: params?.search,\n id_account: id_account,\n });\n const url = `/plans${query ? `?${query}` : \"\"}`;\n\n const response = await api.apps.get<ApiPaginatedActionResult<Plan[]>>(url);\n\n if (response.status === 0) {\n throw new ApiError(\n (response as { message?: string }).message || \"Erro ao listar planos\",\n \"LIST_PLANS_FAILED\",\n 400,\n );\n }\n\n const rawData = (response as { data?: unknown }).data;\n const data = Array.isArray(rawData)\n ? rawData.map((item) => PlanSchema.parse(item))\n : [];\n\n await this.cache.insert(cacheKey, JSON.stringify(data), PLANS_CACHE_TTL);\n\n return {\n data,\n total: response.total,\n success: true,\n } satisfies PaginatedSuccessResult<Plan>;\n }\n\n async findById(idPlan: number | string): Promise<SuccessResult<Plan>> {\n const { id_wl, id_account } = await getUserContext();\n const cacheKey = this.buildCacheKey(`plan-${idPlan}`, {\n id_wl,\n id_account: String(id_account),\n });\n\n const cachedData = await this.cache.select(cacheKey);\n\n if (cachedData.status == 1 && \"data\" in cachedData && cachedData.data) {\n const data = JSON.parse(cachedData.data) as Plan;\n return { data, success: true };\n }\n\n const query = buildQueryParams({ type: \"client\", id_account });\n\n const response = await api.apps.get<ApiPaginatedActionResult<Plan>>(\n `/plans/${idPlan}?${query}`,\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao buscar plano\",\n \"FIND_PLAN_FAILED\",\n 400,\n );\n }\n\n if (!response.data?.length) {\n throw new ApiError(\"Plano não encontrado\", \"PLAN_NOT_FOUND\", 404);\n }\n\n const plan = PlanSchema.parse(response.data[0]);\n\n await this.cache.insert(cacheKey, JSON.stringify(plan), PLANS_CACHE_TTL);\n\n return {\n success: true,\n data: plan,\n };\n }\n}\n\nexport const plansService = new PlansService();\n"],"mappings":"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","names":["data"]}
|
package/package.json
CHANGED
|
@@ -15,5 +15,9 @@ export function useCards() {
|
|
|
15
15
|
const { listCardsAction } = await import('../actions/list-cards.action');
|
|
16
16
|
return withAction(listCardsAction)();
|
|
17
17
|
},
|
|
18
|
+
select: (result) => ({
|
|
19
|
+
...result,
|
|
20
|
+
data: result.data.filter((card) => !card.deleted),
|
|
21
|
+
}),
|
|
18
22
|
});
|
|
19
23
|
}
|
|
@@ -30,9 +30,7 @@ export function useDeleteCard() {
|
|
|
30
30
|
if (!old?.data) return old;
|
|
31
31
|
return {
|
|
32
32
|
...old,
|
|
33
|
-
data: old.data.
|
|
34
|
-
card.id.toString() === id ? { ...card, deleted: true } : card
|
|
35
|
-
),
|
|
33
|
+
data: old.data.filter((card) => card.id.toString() !== id),
|
|
36
34
|
};
|
|
37
35
|
}
|
|
38
36
|
);
|
|
@@ -4,12 +4,12 @@ import { useQuery } from '@tanstack/react-query';
|
|
|
4
4
|
import { withAction } from '@greatapps/common';
|
|
5
5
|
import { listPlansAction } from '../actions/list-plans.action';
|
|
6
6
|
import type { Plan } from '../types/plan.type';
|
|
7
|
-
import {
|
|
7
|
+
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
8
8
|
|
|
9
9
|
export const PLANS_QUERY_KEY = ['plans'] as const;
|
|
10
10
|
|
|
11
11
|
export function usePlans() {
|
|
12
|
-
const queryKey =
|
|
12
|
+
const queryKey = useAuthQueryKey([...PLANS_QUERY_KEY]);
|
|
13
13
|
|
|
14
14
|
return useQuery<Plan[]>({
|
|
15
15
|
queryKey,
|
|
@@ -5,11 +5,11 @@ import { withAction } from "../../../utils/withAction";
|
|
|
5
5
|
import { findPlanByIdAction } from "../actions/find-plan-by-id.action";
|
|
6
6
|
import type { Plan } from "../types/plan.type";
|
|
7
7
|
import { PLANS_QUERY_KEY } from "./list-plans.hook";
|
|
8
|
-
import {
|
|
8
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
9
9
|
|
|
10
10
|
export function usePlanById(idPlan?: number | string | null) {
|
|
11
11
|
const queryClient = useQueryClient();
|
|
12
|
-
const plansKey =
|
|
12
|
+
const plansKey = useAuthQueryKey([...PLANS_QUERY_KEY]);
|
|
13
13
|
|
|
14
14
|
return useQuery({
|
|
15
15
|
queryKey: [...plansKey, idPlan],
|
|
@@ -27,10 +27,12 @@ class PlansService {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
private buildCacheKey(key: string, params?: Record<string, unknown>): string {
|
|
30
|
+
const idWl = params?.id_wl ?? "";
|
|
31
|
+
const idAccount = params?.id_account ?? "";
|
|
30
32
|
const sort = params?.sort ?? "id:ASC";
|
|
31
33
|
const active = params?.active ?? "";
|
|
32
34
|
const search = params?.search ?? "";
|
|
33
|
-
return `${key}-${sort}-${active}-${search}-
|
|
35
|
+
return `${key}-${idWl}-${idAccount}-${sort}-${active}-${search}-v3`;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|