@greatapps/common 1.1.494 → 1.1.495
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/navigation/ProjectSelectorPopover.mjs +0 -1
- package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs +10 -11
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -1
- package/dist/index.mjs +22 -0
- package/dist/index.mjs.map +1 -1
- package/dist/modules/projects/actions/create-project.action.mjs +10 -0
- package/dist/modules/projects/actions/create-project.action.mjs.map +1 -0
- package/dist/modules/projects/actions/delete-project.action.mjs +10 -0
- package/dist/modules/projects/actions/delete-project.action.mjs.map +1 -0
- package/dist/modules/projects/actions/list-projects.action.mjs +10 -0
- package/dist/modules/projects/actions/list-projects.action.mjs.map +1 -0
- package/dist/modules/projects/actions/update-project.action.mjs +10 -0
- package/dist/modules/projects/actions/update-project.action.mjs.map +1 -0
- package/dist/modules/projects/hooks/create-project.hook.mjs +20 -0
- package/dist/modules/projects/hooks/create-project.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/delete-project.hook.mjs +20 -0
- package/dist/modules/projects/hooks/delete-project.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +38 -0
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/list-projects.hook.mjs +22 -0
- package/dist/modules/projects/hooks/list-projects.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/update-project.hook.mjs +20 -0
- package/dist/modules/projects/hooks/update-project.hook.mjs.map +1 -0
- package/dist/modules/projects/services/projects.service.mjs +83 -0
- package/dist/modules/projects/services/projects.service.mjs.map +1 -0
- package/dist/modules/projects/types.mjs +15 -0
- package/dist/modules/projects/types.mjs.map +1 -1
- package/dist/server.mjs +10 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/navigation/ProjectSelectorPopover.tsx +5 -7
- package/src/components/navigation/subcomponents/ProjectSelector.tsx +14 -19
- package/src/index.ts +18 -1
- package/src/modules/projects/actions/create-project.action.ts +9 -0
- package/src/modules/projects/actions/delete-project.action.ts +8 -0
- package/src/modules/projects/actions/list-projects.action.ts +16 -0
- package/src/modules/projects/actions/update-project.action.ts +9 -0
- package/src/modules/projects/hooks/create-project.hook.ts +21 -0
- package/src/modules/projects/hooks/delete-project.hook.ts +20 -0
- package/src/modules/projects/hooks/list-infinite-projects.hook.ts +42 -0
- package/src/modules/projects/hooks/list-projects.hook.ts +23 -0
- package/src/modules/projects/hooks/update-project.hook.ts +21 -0
- package/src/modules/projects/services/projects.service.ts +123 -0
- package/src/modules/projects/types.ts +46 -0
- package/src/server.ts +7 -0
- package/dist/components/navigation/types.mjs +0 -1
- package/dist/components/navigation/types.mjs.map +0 -1
- package/src/components/navigation/types.ts +0 -6
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { api } from '../../../infra/api/client';
|
|
4
|
+
import { ApiError } from '../../../infra/api/types';
|
|
5
|
+
import { buildQueryParams } from '../../../infra/utils/params';
|
|
6
|
+
import { getUserContext } from '../../auth/utils/get-user-context';
|
|
7
|
+
import { assertManagementSubscription } from '../../auth/utils/assert-management-subscription';
|
|
8
|
+
import {
|
|
9
|
+
Project,
|
|
10
|
+
ProjectSchema,
|
|
11
|
+
ProjectsPage,
|
|
12
|
+
CreateProjectRequest,
|
|
13
|
+
UpdateProjectRequest,
|
|
14
|
+
} from '../types';
|
|
15
|
+
|
|
16
|
+
interface ApiListResponse<T> {
|
|
17
|
+
data: T[];
|
|
18
|
+
total: number;
|
|
19
|
+
status: number;
|
|
20
|
+
message?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ApiMutationResponse {
|
|
24
|
+
status: number;
|
|
25
|
+
message?: string;
|
|
26
|
+
data?: Project[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ListProjectsParams {
|
|
30
|
+
page?: number;
|
|
31
|
+
limit?: number;
|
|
32
|
+
sort?: string;
|
|
33
|
+
search?: string;
|
|
34
|
+
deleted?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class ProjectsService {
|
|
38
|
+
async list(params: ListProjectsParams = {}): Promise<ProjectsPage> {
|
|
39
|
+
const { id_account, id_user } = await getUserContext();
|
|
40
|
+
const query = buildQueryParams(params as Record<string, string | number | boolean | undefined>);
|
|
41
|
+
const url = `/account/${id_account}/user/${id_user}/projects${query ? `?${query}` : ''}`;
|
|
42
|
+
|
|
43
|
+
const response = await api.apps.get<ApiListResponse<Project>>(url);
|
|
44
|
+
|
|
45
|
+
if (response.status === 0) {
|
|
46
|
+
throw new ApiError(
|
|
47
|
+
response.message || 'Erro ao listar projetos',
|
|
48
|
+
'LIST_PROJECTS_FAILED',
|
|
49
|
+
400
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
data: (response.data || []).map((item) => ProjectSchema.parse(item)),
|
|
55
|
+
total: response.total || 0,
|
|
56
|
+
page: params.page ?? 1,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async create(data: CreateProjectRequest): Promise<Project> {
|
|
61
|
+
await assertManagementSubscription();
|
|
62
|
+
const { id_account, id_user } = await getUserContext();
|
|
63
|
+
const url = `/account/${id_account}/user/${id_user}/projects`;
|
|
64
|
+
|
|
65
|
+
const response = await api.apps.post<ApiMutationResponse>(url, data);
|
|
66
|
+
|
|
67
|
+
if (response.status === 0) {
|
|
68
|
+
throw new ApiError(
|
|
69
|
+
response.message || 'Erro ao criar projeto',
|
|
70
|
+
'CREATE_PROJECT_FAILED',
|
|
71
|
+
400
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!response.data || response.data.length === 0) {
|
|
76
|
+
throw new ApiError('Resposta inválida ao criar projeto', 'INVALID_RESPONSE', 500);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return ProjectSchema.parse(response.data[0]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async update(projectId: number, data: UpdateProjectRequest): Promise<Project> {
|
|
83
|
+
await assertManagementSubscription();
|
|
84
|
+
const { id_account, id_user } = await getUserContext();
|
|
85
|
+
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
|
|
86
|
+
|
|
87
|
+
const response = await api.apps.put<ApiMutationResponse>(url, data);
|
|
88
|
+
|
|
89
|
+
if (response.status === 0) {
|
|
90
|
+
throw new ApiError(
|
|
91
|
+
response.message || 'Erro ao atualizar projeto',
|
|
92
|
+
'UPDATE_PROJECT_FAILED',
|
|
93
|
+
400
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!response.data || response.data.length === 0) {
|
|
98
|
+
throw new ApiError('Resposta inválida ao atualizar projeto', 'INVALID_RESPONSE', 500);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return ProjectSchema.parse(response.data[0]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async delete(projectId: number, moveToProjectId: number): Promise<void> {
|
|
105
|
+
await assertManagementSubscription();
|
|
106
|
+
const { id_account, id_user } = await getUserContext();
|
|
107
|
+
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
|
|
108
|
+
|
|
109
|
+
const response = await api.apps.delete<ApiMutationResponse>(url, {
|
|
110
|
+
body: JSON.stringify({ id_project_to_move: moveToProjectId }),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (response.status === 0) {
|
|
114
|
+
throw new ApiError(
|
|
115
|
+
response.message || 'Erro ao deletar projeto',
|
|
116
|
+
'DELETE_PROJECT_FAILED',
|
|
117
|
+
400
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const projectsService = new ProjectsService();
|
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// Project
|
|
5
|
+
// ============================================================================
|
|
6
|
+
|
|
7
|
+
export const ProjectSchema = z.object({
|
|
8
|
+
id: z.union([z.number(), z.string()]).transform(Number),
|
|
9
|
+
id_wl: z.union([z.number(), z.string()]).transform(Number),
|
|
10
|
+
id_account: z.union([z.number(), z.string()]).transform(Number),
|
|
11
|
+
title: z.string(),
|
|
12
|
+
photo: z.string().nullable().optional(),
|
|
13
|
+
id_api: z.union([z.number(), z.string()]).nullable().optional(),
|
|
14
|
+
id_form_integration: z.union([z.number(), z.string()]).nullable().optional(),
|
|
15
|
+
total_users: z.string().optional(),
|
|
16
|
+
deleted: z
|
|
17
|
+
.union([z.boolean(), z.number()])
|
|
18
|
+
.transform((v) => Boolean(v))
|
|
19
|
+
.default(false),
|
|
20
|
+
datetime_add: z.string().nullable().optional(),
|
|
21
|
+
datetime_alt: z.string().nullable().optional(),
|
|
22
|
+
datetime_del: z.string().nullable().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Project = z.infer<typeof ProjectSchema>;
|
|
26
|
+
|
|
27
|
+
export interface ProjectsPage {
|
|
28
|
+
data: Project[];
|
|
29
|
+
total: number;
|
|
30
|
+
page: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CreateProjectRequest {
|
|
34
|
+
title: string;
|
|
35
|
+
photo?: string;
|
|
36
|
+
id_api?: number;
|
|
37
|
+
users?: number[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UpdateProjectRequest {
|
|
41
|
+
title: string;
|
|
42
|
+
photo?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Project Users
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
3
49
|
export const ProjectUserSchema = z.object({
|
|
4
50
|
id_user: z.union([z.number(), z.string()]).transform(Number),
|
|
5
51
|
id_account: z.union([z.number(), z.string()]).transform(Number),
|
package/src/server.ts
CHANGED
|
@@ -32,6 +32,13 @@ export { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-p
|
|
|
32
32
|
export { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';
|
|
33
33
|
export { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';
|
|
34
34
|
|
|
35
|
+
// Project Services & Actions (server-only)
|
|
36
|
+
export { projectsService } from './modules/projects/services/projects.service';
|
|
37
|
+
export { listProjectsAction } from './modules/projects/actions/list-projects.action';
|
|
38
|
+
export { createProjectAction } from './modules/projects/actions/create-project.action';
|
|
39
|
+
export { updateProjectAction } from './modules/projects/actions/update-project.action';
|
|
40
|
+
export { deleteProjectAction } from './modules/projects/actions/delete-project.action';
|
|
41
|
+
|
|
35
42
|
// Project Users Services & Actions (server-only)
|
|
36
43
|
export { projectUsersService } from './modules/projects/services/project-users.service';
|
|
37
44
|
export { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|