70 lines
1.3 KiB
TypeScript
70 lines
1.3 KiB
TypeScript
import { apiRequest } from "@/lib/api/api-service";
|
|
import { ApiResponse } from "@/types/api-response";
|
|
|
|
/**
|
|
* Users Service
|
|
* Backend: /api/users/*
|
|
*/
|
|
|
|
export interface UpdateProfileDto {
|
|
firstName?: string;
|
|
lastName?: string;
|
|
}
|
|
|
|
export interface ChangePasswordDto {
|
|
currentPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export interface UsageLimitDto {
|
|
analysisCount: number;
|
|
couponCount: number;
|
|
maxAnalyses: number;
|
|
maxCoupons: number;
|
|
lastResetDate: string;
|
|
}
|
|
|
|
export interface UserResponseDto {
|
|
id: string;
|
|
email: string;
|
|
firstName: string | null;
|
|
lastName: string | null;
|
|
role: string;
|
|
isActive: boolean;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
usageLimit?: UsageLimitDto;
|
|
}
|
|
|
|
const getMe = () => {
|
|
return apiRequest<ApiResponse<UserResponseDto>>({
|
|
url: "/users/me",
|
|
client: "core",
|
|
method: "get",
|
|
});
|
|
};
|
|
|
|
const updateMe = (dto: UpdateProfileDto) => {
|
|
return apiRequest<ApiResponse<UserResponseDto>>({
|
|
url: "/users/me",
|
|
client: "core",
|
|
method: "put",
|
|
data: dto,
|
|
});
|
|
};
|
|
|
|
const changePassword = (dto: ChangePasswordDto) => {
|
|
return apiRequest<ApiResponse<null>>({
|
|
url: "/users/me/password",
|
|
client: "core",
|
|
method: "patch",
|
|
data: dto,
|
|
});
|
|
};
|
|
|
|
export const usersService = {
|
|
getMe,
|
|
updateMe,
|
|
changePassword,
|
|
};
|