@greatapps/common 1.1.523 → 1.1.525
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/components/account/ConfigurationsMyAccountModal.mjs +4 -10
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -1
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs +1 -3
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs.map +1 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs +1 -3
- package/dist/components/account/sections/ChangeEmailModal.mjs.map +1 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs +1 -3
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +1 -2
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/embeds/EmbedWidgets.mjs +1 -3
- package/dist/components/embeds/EmbedWidgets.mjs.map +1 -1
- package/dist/components/layouts/AppMobileNavBar.mjs +1 -3
- package/dist/components/layouts/AppMobileNavBar.mjs.map +1 -1
- package/dist/components/layouts/AppNavBar.mjs +8 -4
- package/dist/components/layouts/AppNavBar.mjs.map +1 -1
- package/dist/components/layouts/NavBar.mjs +9 -10
- package/dist/components/layouts/NavBar.mjs.map +1 -1
- package/dist/components/layouts/NotificationsPopover.mjs +2 -5
- package/dist/components/layouts/NotificationsPopover.mjs.map +1 -1
- package/dist/components/layouts/ProfilePopover.mjs +2 -4
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/components/layouts/SideBarNavigation.mjs +1 -4
- package/dist/components/layouts/SideBarNavigation.mjs.map +1 -1
- package/dist/components/modals/BuyCreditsModal.mjs +9 -26
- package/dist/components/modals/BuyCreditsModal.mjs.map +1 -1
- package/dist/components/modals/cards/AddCardModal.mjs +1 -3
- package/dist/components/modals/cards/AddCardModal.mjs.map +1 -1
- package/dist/components/navigation/CancelledSubscriptionBanner.mjs +1 -1
- package/dist/components/navigation/CancelledSubscriptionBanner.mjs.map +1 -1
- package/dist/components/navigation/ProjectSelectorPopover.mjs +6 -7
- package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs +19 -39
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -1
- package/dist/components/navigation/types.mjs +1 -0
- package/dist/components/navigation/types.mjs.map +1 -0
- package/dist/components/pages/NotFoundPage.mjs +2 -2
- package/dist/components/pages/NotFoundPage.mjs.map +1 -1
- package/dist/components/ui/buttons/Button.mjs +2 -7
- package/dist/components/ui/buttons/Button.mjs.map +1 -1
- package/dist/components/ui/data-display/CardItem.mjs +1 -1
- package/dist/components/ui/data-display/CardItem.mjs.map +1 -1
- package/dist/components/ui/data-display/PaymentInfoCard.mjs +2 -4
- package/dist/components/ui/data-display/PaymentInfoCard.mjs.map +1 -1
- package/dist/components/ui/data-display/UserAvatar.mjs +2 -6
- package/dist/components/ui/data-display/UserAvatar.mjs.map +1 -1
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs +1 -4
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs.map +1 -1
- package/dist/components/ui/feedback/Toast.mjs +2 -7
- package/dist/components/ui/feedback/Toast.mjs.map +1 -1
- package/dist/components/ui/form/FormField.mjs +1 -1
- package/dist/components/ui/form/FormField.mjs.map +1 -1
- package/dist/components/ui/form/Select.mjs +1 -1
- package/dist/components/ui/form/Select.mjs.map +1 -1
- package/dist/components/ui/overlay/Popover.mjs +1 -1
- package/dist/components/ui/overlay/Popover.mjs.map +1 -1
- package/dist/components/ui/overlay/Sheet.mjs +6 -8
- package/dist/components/ui/overlay/Sheet.mjs.map +1 -1
- package/dist/components/widgets/ImageUpload/ImageUpload.mjs +1 -2
- package/dist/components/widgets/ImageUpload/ImageUpload.mjs.map +1 -1
- package/dist/components/widgets/notifications/NotificationCard.mjs +1 -4
- package/dist/components/widgets/notifications/NotificationCard.mjs.map +1 -1
- package/dist/enums/AccountSectionType.mjs +0 -1
- package/dist/enums/AccountSectionType.mjs.map +1 -1
- package/dist/index.mjs +8 -90
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs +2 -5
- package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +9 -19
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs +1 -3
- package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs +1 -3
- package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +6 -15
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/cards/hooks/cards.hook.mjs +3 -11
- package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/create-card.hook.mjs +2 -13
- package/dist/modules/cards/hooks/create-card.hook.mjs.map +1 -1
- package/dist/modules/cards/services/cards.service.mjs +4 -45
- package/dist/modules/cards/services/cards.service.mjs.map +1 -1
- package/dist/modules/cards/types.mjs +3 -11
- package/dist/modules/cards/types.mjs.map +1 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +1 -3
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/list-plans.hook.mjs +1 -3
- package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +2 -4
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/dist/modules/plans/services/plans.service.mjs +2 -4
- package/dist/modules/plans/services/plans.service.mjs.map +1 -1
- package/dist/modules/plans/types/plan.type.mjs.map +1 -1
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs +10 -20
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs.map +1 -1
- package/dist/modules/projects/hooks/add-project-user.hook.mjs +12 -15
- package/dist/modules/projects/hooks/add-project-user.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +1 -3
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +1 -3
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +1 -3
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/remove-project-user.hook.mjs +12 -15
- package/dist/modules/projects/hooks/remove-project-user.hook.mjs.map +1 -1
- package/dist/modules/projects/types.mjs +4 -19
- package/dist/modules/projects/types.mjs.map +1 -1
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs +0 -2
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +2 -5
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +1 -3
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs +3 -6
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/types/calculate-subscription.type.mjs +2 -29
- package/dist/modules/subscriptions/types/calculate-subscription.type.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/periodicity.mjs +0 -7
- package/dist/modules/subscriptions/utils/periodicity.mjs.map +1 -1
- package/dist/modules/users/action/list-messages.action.mjs +2 -14
- package/dist/modules/users/action/list-messages.action.mjs.map +1 -1
- package/dist/modules/users/hooks/messages.hook.mjs +4 -9
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/modules/users/services/messages.service.mjs.map +1 -1
- package/dist/providers/auth.provider.mjs +4 -6
- package/dist/providers/auth.provider.mjs.map +1 -1
- package/dist/providers/query.provider.mjs +2 -2
- package/dist/providers/query.provider.mjs.map +1 -1
- package/dist/providers/whitelabel.provider.mjs +0 -5
- package/dist/providers/whitelabel.provider.mjs.map +1 -1
- package/dist/server.mjs +0 -14
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/widgets/ImageUpload/ImageCropModal.tsx +10 -37
- package/dist/components/account/sections/TokenSection.mjs +0 -72
- package/dist/components/account/sections/TokenSection.mjs.map +0 -1
- package/dist/components/embeds/ClarityEmbed.mjs +0 -55
- package/dist/components/embeds/ClarityEmbed.mjs.map +0 -1
- package/dist/hooks/useAuthQueryKey.mjs +0 -23
- package/dist/hooks/useAuthQueryKey.mjs.map +0 -1
- package/dist/infra/utils/array.mjs +0 -34
- package/dist/infra/utils/array.mjs.map +0 -1
- package/dist/modules/accounts/actions/get-account-token.action.mjs +0 -10
- package/dist/modules/accounts/actions/get-account-token.action.mjs.map +0 -1
- package/dist/modules/accounts/hooks/use-account-token.hook.mjs +0 -15
- package/dist/modules/accounts/hooks/use-account-token.hook.mjs.map +0 -1
- package/dist/modules/accounts/services/account-token.service.mjs +0 -32
- package/dist/modules/accounts/services/account-token.service.mjs.map +0 -1
- package/dist/modules/cards/actions/delete-card.action.mjs +0 -10
- package/dist/modules/cards/actions/delete-card.action.mjs.map +0 -1
- package/dist/modules/cards/actions/find-card-by-id.action.mjs +0 -10
- package/dist/modules/cards/actions/find-card-by-id.action.mjs.map +0 -1
- package/dist/modules/cards/actions/set-default-card.action.mjs +0 -10
- package/dist/modules/cards/actions/set-default-card.action.mjs.map +0 -1
- package/dist/modules/cards/hooks/card-by-id.hook.mjs +0 -22
- package/dist/modules/cards/hooks/card-by-id.hook.mjs.map +0 -1
- package/dist/modules/cards/hooks/delete-card.hook.mjs +0 -50
- package/dist/modules/cards/hooks/delete-card.hook.mjs.map +0 -1
- package/dist/modules/cards/hooks/set-default-card.hook.mjs +0 -51
- package/dist/modules/cards/hooks/set-default-card.hook.mjs.map +0 -1
- package/dist/modules/projects/actions/create-project.action.mjs +0 -10
- package/dist/modules/projects/actions/create-project.action.mjs.map +0 -1
- package/dist/modules/projects/actions/delete-project.action.mjs +0 -10
- package/dist/modules/projects/actions/delete-project.action.mjs.map +0 -1
- package/dist/modules/projects/actions/find-project.action.mjs +0 -10
- package/dist/modules/projects/actions/find-project.action.mjs.map +0 -1
- package/dist/modules/projects/actions/list-projects.action.mjs +0 -10
- package/dist/modules/projects/actions/list-projects.action.mjs.map +0 -1
- package/dist/modules/projects/actions/update-project.action.mjs +0 -10
- package/dist/modules/projects/actions/update-project.action.mjs.map +0 -1
- package/dist/modules/projects/hooks/create-project.hook.mjs +0 -71
- package/dist/modules/projects/hooks/create-project.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/delete-project.hook.mjs +0 -53
- package/dist/modules/projects/hooks/delete-project.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/find-project.hook.mjs +0 -19
- package/dist/modules/projects/hooks/find-project.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +0 -39
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/list-projects.hook.mjs +0 -22
- package/dist/modules/projects/hooks/list-projects.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/update-project.hook.mjs +0 -70
- package/dist/modules/projects/hooks/update-project.hook.mjs.map +0 -1
- package/dist/modules/projects/services/projects.service.mjs +0 -99
- package/dist/modules/projects/services/projects.service.mjs.map +0 -1
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { updateProjectAction } from "../actions/update-project.action";
|
|
4
|
-
import { withAction } from "../../../utils/withAction";
|
|
5
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
6
|
-
import { PROJECTS_BASE_KEY } from "./list-projects.hook";
|
|
7
|
-
import { insertSorted, buildCompareFn } from "../../../infra/utils/array";
|
|
8
|
-
function extractSort(query) {
|
|
9
|
-
const key = query.queryKey;
|
|
10
|
-
for (let i = key.length - 1; i >= 0; i--) {
|
|
11
|
-
const segment = key[i];
|
|
12
|
-
if (segment && typeof segment === "object" && "sort" in segment) {
|
|
13
|
-
return segment.sort;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return void 0;
|
|
17
|
-
}
|
|
18
|
-
function useUpdateProject() {
|
|
19
|
-
const queryClient = useQueryClient();
|
|
20
|
-
const projectsKey = useAuthQueryKey([...PROJECTS_BASE_KEY]);
|
|
21
|
-
return useMutation({
|
|
22
|
-
mutationFn: ({ projectId, data }) => withAction(updateProjectAction)(projectId, data),
|
|
23
|
-
onSuccess: (updatedProject, { projectId }) => {
|
|
24
|
-
const cache = queryClient.getQueryCache();
|
|
25
|
-
const queries = cache.findAll({ queryKey: projectsKey });
|
|
26
|
-
for (const query of queries) {
|
|
27
|
-
const sort = extractSort(query);
|
|
28
|
-
const isInfinite = query.queryKey.includes("infinite");
|
|
29
|
-
if (isInfinite) {
|
|
30
|
-
queryClient.setQueryData(
|
|
31
|
-
query.queryKey,
|
|
32
|
-
(old) => {
|
|
33
|
-
if (!old?.pages.length) return old;
|
|
34
|
-
const pageSize = old.pages[0].data.length || 20;
|
|
35
|
-
const allItems = old.pages.flatMap((page) => page.data);
|
|
36
|
-
const without = allItems.filter((p) => p.id !== projectId);
|
|
37
|
-
const withUpdated = sort ? insertSorted(without, updatedProject, buildCompareFn(sort)) : [updatedProject, ...without];
|
|
38
|
-
return {
|
|
39
|
-
...old,
|
|
40
|
-
pages: old.pages.map((page, i) => ({
|
|
41
|
-
...page,
|
|
42
|
-
data: withUpdated.slice(i * pageSize, (i + 1) * pageSize)
|
|
43
|
-
}))
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
} else {
|
|
48
|
-
queryClient.setQueryData(
|
|
49
|
-
query.queryKey,
|
|
50
|
-
(old) => {
|
|
51
|
-
if (!old) return old;
|
|
52
|
-
const pageSize = old.data.length || 20;
|
|
53
|
-
const without = old.data.filter((p) => p.id !== projectId);
|
|
54
|
-
const withUpdated = sort ? insertSorted(without, updatedProject, buildCompareFn(sort)) : [updatedProject, ...without];
|
|
55
|
-
return {
|
|
56
|
-
...old,
|
|
57
|
-
data: withUpdated.slice(0, pageSize)
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
queryClient.invalidateQueries({ queryKey: projectsKey });
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
useUpdateProject
|
|
69
|
-
};
|
|
70
|
-
//# sourceMappingURL=update-project.hook.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/hooks/update-project.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient, InfiniteData, Query } from '@tanstack/react-query';\nimport { updateProjectAction } from '../actions/update-project.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { PROJECTS_BASE_KEY } from './list-projects.hook';\nimport { insertSorted, buildCompareFn } from '../../../infra/utils/array';\nimport type { Project, ProjectsPage, UpdateProjectRequest } from '../types';\n\nfunction extractSort(query: Query): string | undefined {\n const key = query.queryKey;\n for (let i = key.length - 1; i >= 0; i--) {\n const segment = key[i];\n if (segment && typeof segment === 'object' && 'sort' in segment) {\n return (segment as Record<string, unknown>).sort as string | undefined;\n }\n }\n return undefined;\n}\n\nexport function useUpdateProject() {\n const queryClient = useQueryClient();\n const projectsKey = useAuthQueryKey([...PROJECTS_BASE_KEY]);\n\n return useMutation({\n mutationFn: ({ projectId, data }: { projectId: number; data: UpdateProjectRequest }) =>\n withAction(updateProjectAction)(projectId, data),\n\n onSuccess: (updatedProject: Project, { projectId }) => {\n const cache = queryClient.getQueryCache();\n const queries = cache.findAll({ queryKey: projectsKey });\n\n for (const query of queries) {\n const sort = extractSort(query);\n const isInfinite = query.queryKey.includes('infinite');\n\n if (isInfinite) {\n queryClient.setQueryData<InfiniteData<ProjectsPage>>(\n query.queryKey,\n (old) => {\n if (!old?.pages.length) return old;\n\n const pageSize = old.pages[0].data.length || 20;\n const allItems = old.pages.flatMap((page) => page.data);\n const without = allItems.filter((p) => p.id !== projectId);\n\n const withUpdated = sort\n ? insertSorted(without, updatedProject, buildCompareFn<Project>(sort))\n : [updatedProject, ...without];\n\n return {\n ...old,\n pages: old.pages.map((page, i) => ({\n ...page,\n data: withUpdated.slice(i * pageSize, (i + 1) * pageSize),\n })),\n };\n },\n );\n } else {\n queryClient.setQueryData<ProjectsPage>(\n query.queryKey,\n (old) => {\n if (!old) return old;\n\n const pageSize = old.data.length || 20;\n const without = old.data.filter((p) => p.id !== projectId);\n\n const withUpdated = sort\n ? insertSorted(without, updatedProject, buildCompareFn<Project>(sort))\n : [updatedProject, ...without];\n\n return {\n ...old,\n data: withUpdated.slice(0, pageSize),\n };\n },\n );\n }\n }\n\n queryClient.invalidateQueries({ queryKey: projectsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAA2C;AACjE,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAClC,SAAS,cAAc,sBAAsB;AAG7C,SAAS,YAAY,OAAkC;AACrD,QAAM,MAAM,MAAM;AAClB,WAAS,IAAI,IAAI,SAAS,GAAG,KAAK,GAAG,KAAK;AACxC,UAAM,UAAU,IAAI,CAAC;AACrB,QAAI,WAAW,OAAO,YAAY,YAAY,UAAU,SAAS;AAC/D,aAAQ,QAAoC;AAAA,IAC9C;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,mBAAmB;AACjC,QAAM,cAAc,eAAe;AACnC,QAAM,c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a,SAAS,gBAAgB,eAAwB,IAAI,CAAC,IACnE,CAAC,gBAAgB,GAAG,OAAO;AAE/B,qBAAO;AAAA,gBACL,GAAG;AAAA,gBACH,MAAM,YAAY,MAAM,GAAG,QAAQ;AAAA,cACrC;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import "server-only";
|
|
2
|
-
import { api } from "../../../infra/api/client";
|
|
3
|
-
import { ApiError } from "../../../infra/api/types";
|
|
4
|
-
import { buildQueryParams } from "../../../infra/utils/params";
|
|
5
|
-
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
6
|
-
import { assertManagementSubscription } from "../../auth/utils/assert-management-subscription";
|
|
7
|
-
import {
|
|
8
|
-
ProjectSchema
|
|
9
|
-
} from "../types";
|
|
10
|
-
class ProjectsService {
|
|
11
|
-
async list(params = {}) {
|
|
12
|
-
const { id_account, id_user } = await getUserContext();
|
|
13
|
-
const query = buildQueryParams(params);
|
|
14
|
-
const url = `/account/${id_account}/user/${id_user}/projects${query ? `?${query}` : ""}`;
|
|
15
|
-
const response = await api.apps.get(url);
|
|
16
|
-
if (response.status === 0) {
|
|
17
|
-
throw new ApiError(
|
|
18
|
-
response.message || "Erro ao listar projetos",
|
|
19
|
-
"LIST_PROJECTS_FAILED",
|
|
20
|
-
400
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
data: (response.data || []).map((item) => ProjectSchema.parse(item)),
|
|
25
|
-
total: response.total || 0,
|
|
26
|
-
page: params.page ?? 1
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
async findById(projectId) {
|
|
30
|
-
const { id_account, id_user } = await getUserContext();
|
|
31
|
-
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
|
|
32
|
-
const response = await api.apps.get(url);
|
|
33
|
-
if (response.status === 0) {
|
|
34
|
-
throw new ApiError(
|
|
35
|
-
response.message || "Erro ao buscar projeto",
|
|
36
|
-
"FIND_PROJECT_FAILED",
|
|
37
|
-
400
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
if (!response.data || response.data.length === 0) {
|
|
41
|
-
throw new ApiError("Projeto n\xE3o encontrado", "PROJECT_NOT_FOUND", 404);
|
|
42
|
-
}
|
|
43
|
-
return ProjectSchema.parse(response.data[0]);
|
|
44
|
-
}
|
|
45
|
-
async create(data) {
|
|
46
|
-
await assertManagementSubscription();
|
|
47
|
-
const { id_account, id_user } = await getUserContext();
|
|
48
|
-
const url = `/account/${id_account}/user/${id_user}/projects`;
|
|
49
|
-
const response = await api.apps.post(url, data);
|
|
50
|
-
if (response.status === 0) {
|
|
51
|
-
throw new ApiError(
|
|
52
|
-
response.message || "Erro ao criar projeto",
|
|
53
|
-
"CREATE_PROJECT_FAILED",
|
|
54
|
-
400
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
if (!response.data || response.data.length === 0) {
|
|
58
|
-
throw new ApiError("Resposta inv\xE1lida ao criar projeto", "INVALID_RESPONSE", 500);
|
|
59
|
-
}
|
|
60
|
-
return ProjectSchema.parse(response.data[0]);
|
|
61
|
-
}
|
|
62
|
-
async update(projectId, data) {
|
|
63
|
-
await assertManagementSubscription();
|
|
64
|
-
const { id_account, id_user } = await getUserContext();
|
|
65
|
-
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
|
|
66
|
-
const response = await api.apps.put(url, data);
|
|
67
|
-
if (response.status === 0) {
|
|
68
|
-
throw new ApiError(
|
|
69
|
-
response.message || "Erro ao atualizar projeto",
|
|
70
|
-
"UPDATE_PROJECT_FAILED",
|
|
71
|
-
400
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
if (!response.data || response.data.length === 0) {
|
|
75
|
-
throw new ApiError("Resposta inv\xE1lida ao atualizar projeto", "INVALID_RESPONSE", 500);
|
|
76
|
-
}
|
|
77
|
-
return ProjectSchema.parse(response.data[0]);
|
|
78
|
-
}
|
|
79
|
-
async delete(projectId, moveToProjectId) {
|
|
80
|
-
await assertManagementSubscription();
|
|
81
|
-
const { id_account, id_user } = await getUserContext();
|
|
82
|
-
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
|
|
83
|
-
const response = await api.apps.delete(url, {
|
|
84
|
-
body: JSON.stringify({ id_project_to_move: moveToProjectId })
|
|
85
|
-
});
|
|
86
|
-
if (response.status === 0) {
|
|
87
|
-
throw new ApiError(
|
|
88
|
-
response.message || "Erro ao deletar projeto",
|
|
89
|
-
"DELETE_PROJECT_FAILED",
|
|
90
|
-
400
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const projectsService = new ProjectsService();
|
|
96
|
-
export {
|
|
97
|
-
projectsService
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=projects.service.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/services/projects.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { ApiError } from '../../../infra/api/types';\nimport { buildQueryParams } from '../../../infra/utils/params';\nimport { getUserContext } from '../../auth/utils/get-user-context';\nimport { assertManagementSubscription } from '../../auth/utils/assert-management-subscription';\nimport {\n Project,\n ProjectSchema,\n ProjectsPage,\n CreateProjectRequest,\n UpdateProjectRequest,\n} from '../types';\n\ninterface ApiListResponse<T> {\n data: T[];\n total: number;\n status: number;\n message?: string;\n}\n\ninterface ApiMutationResponse {\n status: number;\n message?: string;\n data?: Project[];\n}\n\ninterface ListProjectsParams {\n page?: number;\n limit?: number;\n sort?: string;\n search?: string;\n deleted?: number;\n}\n\nclass ProjectsService {\n async list(params: ListProjectsParams = {}): Promise<ProjectsPage> {\n const { id_account, id_user } = await getUserContext();\n const query = buildQueryParams(params as Record<string, string | number | boolean | undefined>);\n const url = `/account/${id_account}/user/${id_user}/projects${query ? `?${query}` : ''}`;\n\n const response = await api.apps.get<ApiListResponse<Project>>(url);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao listar projetos',\n 'LIST_PROJECTS_FAILED',\n 400\n );\n }\n\n return {\n data: (response.data || []).map((item) => ProjectSchema.parse(item)),\n total: response.total || 0,\n page: params.page ?? 1,\n };\n }\n\n async findById(projectId: number): Promise<Project> {\n const { id_account, id_user } = await getUserContext();\n const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;\n\n const response = await api.apps.get<ApiMutationResponse>(url);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao buscar projeto',\n 'FIND_PROJECT_FAILED',\n 400\n );\n }\n\n if (!response.data || response.data.length === 0) {\n throw new ApiError('Projeto não encontrado', 'PROJECT_NOT_FOUND', 404);\n }\n\n return ProjectSchema.parse(response.data[0]);\n }\n\n async create(data: CreateProjectRequest): Promise<Project> {\n await assertManagementSubscription();\n const { id_account, id_user } = await getUserContext();\n const url = `/account/${id_account}/user/${id_user}/projects`;\n\n const response = await api.apps.post<ApiMutationResponse>(url, data);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao criar projeto',\n 'CREATE_PROJECT_FAILED',\n 400\n );\n }\n\n if (!response.data || response.data.length === 0) {\n throw new ApiError('Resposta inválida ao criar projeto', 'INVALID_RESPONSE', 500);\n }\n\n return ProjectSchema.parse(response.data[0]);\n }\n\n async update(projectId: number, data: UpdateProjectRequest): Promise<Project> {\n await assertManagementSubscription();\n const { id_account, id_user } = await getUserContext();\n const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;\n\n const response = await api.apps.put<ApiMutationResponse>(url, data);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar projeto',\n 'UPDATE_PROJECT_FAILED',\n 400\n );\n }\n\n if (!response.data || response.data.length === 0) {\n throw new ApiError('Resposta inválida ao atualizar projeto', 'INVALID_RESPONSE', 500);\n }\n\n return ProjectSchema.parse(response.data[0]);\n }\n\n async delete(projectId: number, moveToProjectId: number): Promise<void> {\n await assertManagementSubscription();\n const { id_account, id_user } = await getUserContext();\n const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;\n\n const response = await api.apps.delete<ApiMutationResponse>(url, {\n body: JSON.stringify({ id_project_to_move: moveToProjectId }),\n });\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao deletar projeto',\n 'DELETE_PROJECT_FAILED',\n 400\n );\n }\n }\n}\n\nexport const projectsService = new ProjectsService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,oCAAoC;AAC7C;AAAA,EAEE;AAAA,OAIK;AAuBP,MAAM,gBAAgB;AAAA,EACpB,MAAM,KAAK,SAA6B,CAAC,GAA0B;AACjE,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AACrD,UAAM,QAAQ,iBAAiB,MAA+D;AAC9F,UAAM,MAAM,YAAY,UAAU,SAAS,OAAO,YAAY,QAAQ,IAAI,KAAK,KAAK,EAAE;AAEtF,UAAM,WAAW,MAAM,IAAI,KAAK,IAA8B,GAAG;AAEjE,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,OAAO,SAAS,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,cAAc,MAAM,IAAI,CAAC;AAAA,MACnE,OAAO,SAAS,SAAS;AAAA,MACzB,MAAM,OAAO,QAAQ;AAAA,IACvB;AAAA,EACF;AAAA,EAEA,MAAM,SAAS,WAAqC;AAClD,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AACrD,UAAM,MAAM,YAAY,UAAU,SAAS,OAAO,aAAa,SAAS;AAExE,UAAM,W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