Skip to content

Commit f48fc04

Browse files
authored
Merge pull request #44 from WorkTechDevelop/refactoring-rpc-lib
Refactoring rpc lib
2 parents 5d9ca2f + ec2d6b6 commit f48fc04

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

src/features/projects/api/use-get-projects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const useGetProjects = () => {
77
queryKey: ["projects"],
88
queryFn: async (): Promise<ShortProjectData[]> => {
99
try {
10-
const response = await client.getProjects();
10+
const response = await client.getAllUserProjects();
1111
return response;
1212
} catch (error) {
1313
console.error("Failed to fetch projects:", error);

src/lib/rpc.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { buildApiUrl } from "@/config";
2+
import { API_ENDPOINTS } from "@/config";
23
import {
34
LoginResponse,
45
UserData,
@@ -125,7 +126,7 @@ class WorkTechApiClient {
125126
if (!refreshToken) return false;
126127

127128
try {
128-
const response = await fetch(buildApiUrl('/auth/refresh'), {
129+
const response = await fetch(buildApiUrl(API_ENDPOINTS.AUTH.REFRESH_TOKEN), {
129130
method: 'POST',
130131
headers: {
131132
'Content-Type': 'application/json',
@@ -147,30 +148,31 @@ class WorkTechApiClient {
147148
return false;
148149
}
149150

151+
//User
152+
async getCurrentUser(): Promise<UserData> {
153+
return this.request<UserData>(API_ENDPOINTS.USERS.PROFILE);
154+
}
155+
150156
async login(email: string, password: string): Promise<LoginResponse> {
151-
return this.request<LoginResponse>('/auth/login', {
157+
return this.request<LoginResponse>(API_ENDPOINTS.AUTH.LOGIN, {
152158
method: 'POST',
153159
body: JSON.stringify({ email, password }),
154160
});
155161
}
156162

157163
async register(data: RegisterRequest): Promise<string> {
158-
return this.request<string>('/registration/registry', {
164+
return this.request<string>(API_ENDPOINTS.REGISTRATION.REGISTER, {
159165
method: 'POST',
160166
body: JSON.stringify(data),
161167
});
162168
}
163169

164-
async getCurrentUser(): Promise<UserData> {
165-
return this.request<UserData>('/users/profile');
166-
}
167-
168170
async getRoles(): Promise<{ roles: RoleDataDto[] }> {
169-
return this.request<{ roles: RoleDataDto[] }>('/roles');
171+
return this.request<{ roles: RoleDataDto[] }>(API_ENDPOINTS.ROLES.GET_ALL);
170172
}
171173

172-
async getProjects(): Promise<ShortProjectData[]> {
173-
return this.request<ShortProjectData[]>('/projects/all-user-project');
174+
async getAllUserProjects(): Promise<ShortProjectData[]> {
175+
return this.request<ShortProjectData[]>(API_ENDPOINTS.PROJECTS.GET_ALL_USER);
174176
}
175177

176178
async getProject(projectId: string): Promise<Project> {

src/lib/types.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
// WorkTech API Types based on OpenAPI Schema
2-
3-
export interface ErrorResponse {
4-
error: string;
5-
message: string;
6-
}
7-
8-
// Auth Types
1+
// ===== Auth Types =====
92
export interface LoginRequest {
103
email: string;
114
password: string;
@@ -32,7 +25,7 @@ export interface TokenRefreshRequest {
3225
refreshToken: string;
3326
}
3427

35-
// User Types
28+
// ===== User Types =====
3629
export interface UserShortData {
3730
id: string;
3831
email: string;
@@ -47,13 +40,26 @@ export interface RoleDataDto {
4740
roleName: string;
4841
}
4942

50-
export interface UserData extends UserShortData {
43+
export interface PermissionProject {
44+
projectId: string;
45+
projectName: string;
46+
owner: boolean;
47+
extendedPermission: boolean;
48+
}
49+
50+
export interface UserData {
5151
userId: string;
52+
lastProjectId: string | null;
53+
lastName: string;
54+
firstName: string;
5255
middleName?: string;
56+
email: string;
5357
phone?: string;
5458
birthDate?: string;
5559
active: boolean;
60+
gender?: string;
5661
roles: RoleDataDto[];
62+
permissionProjects: PermissionProject[];
5763
}
5864

5965
export interface UpdateUserRequest {
@@ -67,7 +73,7 @@ export interface UpdateUserRequest {
6773
confirmPassword: string;
6874
}
6975

70-
// Project Types
76+
// ===== Project Types =====
7177
export interface ShortProjectData {
7278
id: string;
7379
name: string;
@@ -110,7 +116,7 @@ export interface ProjectData {
110116
users: UserWithTasks[];
111117
}
112118

113-
// Task Types
119+
// ===== Task Types =====
114120
export type TaskPriority = 'BLOCKER' | 'HIGH' | 'MEDIUM' | 'LOW';
115121
export type TaskType = 'BUG' | 'TASK' | 'RESEARCH' | 'STORY';
116122

@@ -172,7 +178,7 @@ export interface TaskHistory {
172178
createdAt: string;
173179
}
174180

175-
// Sprint Types
181+
// ===== Sprint Types =====
176182
export interface SprintRequest {
177183
name: string;
178184
startDate?: string;
@@ -189,7 +195,7 @@ export interface Sprint {
189195
defaultSprint: boolean;
190196
}
191197

192-
// Status Types
198+
// ===== Status Types =====
193199
export interface TaskStatusRequest {
194200
id?: number;
195201
priority: number;
@@ -214,7 +220,7 @@ export interface UpdateRequestStatuses {
214220
statuses: TaskStatusRequest[];
215221
}
216222

217-
// Comment Types
223+
// ===== Comment Types =====
218224
export interface CommentRequest {
219225
taskId: string;
220226
projectId: string;
@@ -237,7 +243,7 @@ export interface AllTasksCommentsResponse {
237243
updatedAt: string;
238244
}
239245

240-
// Link Types
246+
// ===== Link Types =====
241247
export interface LinkRequest {
242248
taskIdSource: string;
243249
taskIdTarget: string;
@@ -253,14 +259,18 @@ export interface LinkResponse {
253259
description: string;
254260
}
255261

256-
// API Response wrapper
262+
// ===== Общие типы и утилиты =====
263+
export interface ErrorResponse {
264+
error: string;
265+
message: string;
266+
}
267+
257268
export interface ApiResponse<T = Record<string, unknown>> {
258269
data?: T;
259270
error?: string;
260271
message?: string;
261272
}
262273

263-
// Common ID list type
264274
export interface StringIds {
265275
ids: string[];
266276
}

0 commit comments

Comments
 (0)