2025-12-22 11:53:38 +05:30
|
|
|
import api, { ApiResponse } from './api';
|
|
|
|
|
|
|
|
|
|
// Types
|
2026-01-28 13:48:02 +05:30
|
|
|
export type VerificationStatus = 'NONE' | 'PENDING_REVIEW' | 'APPROVED' | 'REJECTED';
|
|
|
|
|
|
2026-01-26 23:12:04 +05:30
|
|
|
export interface AgentType {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 13:48:02 +05:30
|
|
|
export interface VerificationDocument {
|
2026-01-29 00:02:45 +05:30
|
|
|
id?: string; // S3 key is stored in id field from upload service
|
|
|
|
|
key?: string; // Alternative S3 key field
|
2026-01-28 13:48:02 +05:30
|
|
|
name: string;
|
|
|
|
|
size: number;
|
|
|
|
|
type: string;
|
|
|
|
|
url?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 23:12:04 +05:30
|
|
|
export interface AgentProfileDetails {
|
|
|
|
|
id: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
bio?: string | null;
|
|
|
|
|
headline?: string | null;
|
|
|
|
|
companyName?: string | null;
|
|
|
|
|
licenseNumber?: string | null;
|
|
|
|
|
yearsOfExperience?: number | null;
|
|
|
|
|
isProfileComplete: boolean;
|
|
|
|
|
profileCompleteness: number;
|
|
|
|
|
agentTypeId?: string | null;
|
|
|
|
|
agentType?: AgentType | null;
|
2026-01-28 13:48:02 +05:30
|
|
|
// Verification fields
|
|
|
|
|
isVerified?: boolean;
|
|
|
|
|
verificationStatus?: VerificationStatus;
|
|
|
|
|
verificationNote?: string | null;
|
|
|
|
|
verifiedAt?: string | null;
|
|
|
|
|
verifiedBy?: string | null;
|
2026-01-26 23:12:04 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 11:53:38 +05:30
|
|
|
export interface User {
|
|
|
|
|
id: string;
|
|
|
|
|
email: string;
|
|
|
|
|
role: string;
|
|
|
|
|
status: string;
|
|
|
|
|
emailVerified: boolean;
|
2026-01-26 23:12:04 +05:30
|
|
|
emailVerifiedAt?: string | null;
|
2025-12-22 11:53:38 +05:30
|
|
|
authProvider: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
lastLoginAt: string | null;
|
|
|
|
|
profile: {
|
|
|
|
|
firstName: string;
|
|
|
|
|
lastName: string;
|
|
|
|
|
avatar: string | null;
|
|
|
|
|
phone: string | null;
|
|
|
|
|
city: string | null;
|
|
|
|
|
state: string | null;
|
|
|
|
|
country: string | null;
|
|
|
|
|
} | null;
|
2026-01-26 23:12:04 +05:30
|
|
|
agentProfile?: AgentProfileDetails | null;
|
2025-12-22 11:53:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UsersListResponse {
|
|
|
|
|
users: User[];
|
|
|
|
|
total: number;
|
|
|
|
|
page: number;
|
|
|
|
|
limit: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UserFilters {
|
|
|
|
|
page?: number;
|
|
|
|
|
limit?: number;
|
|
|
|
|
role?: string;
|
|
|
|
|
status?: string;
|
|
|
|
|
search?: string;
|
2026-03-27 11:59:17 +05:30
|
|
|
verificationStatus?: string;
|
2025-12-22 11:53:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Users Service
|
|
|
|
|
class UsersService {
|
|
|
|
|
private basePath = '/users';
|
|
|
|
|
|
|
|
|
|
async getUsers(filters: UserFilters = {}): Promise<UsersListResponse> {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
|
|
|
|
|
if (filters.page) params.append('page', filters.page.toString());
|
|
|
|
|
if (filters.limit) params.append('limit', filters.limit.toString());
|
|
|
|
|
if (filters.role) params.append('role', filters.role);
|
|
|
|
|
if (filters.status) params.append('status', filters.status);
|
|
|
|
|
if (filters.search) params.append('search', filters.search);
|
|
|
|
|
|
|
|
|
|
const queryString = params.toString();
|
|
|
|
|
const url = queryString ? `${this.basePath}?${queryString}` : this.basePath;
|
|
|
|
|
|
|
|
|
|
const response = await api.get<ApiResponse<UsersListResponse>>(url);
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getUserById(id: string): Promise<User> {
|
|
|
|
|
const response = await api.get<ApiResponse<User>>(`${this.basePath}/${id}`);
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateUser(id: string, data: Partial<User>): Promise<User> {
|
|
|
|
|
const response = await api.patch<ApiResponse<User>>(`${this.basePath}/${id}`, data);
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteUser(id: string): Promise<void> {
|
|
|
|
|
await api.delete(`${this.basePath}/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateUserStatus(id: string, status: string): Promise<User> {
|
|
|
|
|
const response = await api.patch<ApiResponse<User>>(`${this.basePath}/${id}/status`, { status });
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
2026-01-26 23:12:04 +05:30
|
|
|
|
|
|
|
|
async updateAgentType(userId: string, agentTypeId: string): Promise<{ id: string; agentTypeId: string; agentType: AgentType; message: string }> {
|
|
|
|
|
const response = await api.patch<ApiResponse<{ id: string; agentTypeId: string; agentType: AgentType; message: string }>>(`${this.basePath}/${userId}/agent-type`, { agentTypeId });
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
2026-01-28 13:48:02 +05:30
|
|
|
|
|
|
|
|
async getVerificationDocuments(userId: string): Promise<VerificationDocument[]> {
|
|
|
|
|
const response = await api.get<ApiResponse<VerificationDocument[]>>(`${this.basePath}/${userId}/verification-documents`);
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateVerification(
|
|
|
|
|
userId: string,
|
|
|
|
|
data: { status: VerificationStatus; note?: string }
|
|
|
|
|
): Promise<{
|
|
|
|
|
id: string;
|
|
|
|
|
agentProfileId: string;
|
|
|
|
|
isVerified: boolean;
|
|
|
|
|
verificationStatus: VerificationStatus;
|
|
|
|
|
verificationNote: string | null;
|
|
|
|
|
verifiedAt: string | null;
|
|
|
|
|
verifiedBy: string | null;
|
|
|
|
|
message: string;
|
|
|
|
|
}> {
|
|
|
|
|
const response = await api.patch<ApiResponse<{
|
|
|
|
|
id: string;
|
|
|
|
|
agentProfileId: string;
|
|
|
|
|
isVerified: boolean;
|
|
|
|
|
verificationStatus: VerificationStatus;
|
|
|
|
|
verificationNote: string | null;
|
|
|
|
|
verifiedAt: string | null;
|
|
|
|
|
verifiedBy: string | null;
|
|
|
|
|
message: string;
|
|
|
|
|
}>>(`${this.basePath}/${userId}/verification`, data);
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
2026-03-21 08:56:17 +05:30
|
|
|
|
|
|
|
|
async getVerificationHistory(userId: string): Promise<VerificationHistoryEntry[]> {
|
|
|
|
|
const response = await api.get<ApiResponse<VerificationHistoryEntry[]>>(`${this.basePath}/${userId}/verification-history`);
|
|
|
|
|
return response.data.data;
|
|
|
|
|
}
|
2026-03-31 22:39:02 +05:30
|
|
|
|
|
|
|
|
async getAgentFieldValues(agentProfileId: string): Promise<AgentFieldValue[]> {
|
|
|
|
|
const response = await api.get<ApiResponse<{ agentProfileId: string; fieldValues: AgentFieldValue[] }>>(`/agents/${agentProfileId}/field-values`);
|
|
|
|
|
return response.data.data.fieldValues;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AgentFieldValue {
|
|
|
|
|
fieldSlug: string;
|
|
|
|
|
fieldName: string;
|
|
|
|
|
fieldType: string;
|
|
|
|
|
sectionSlug: string;
|
|
|
|
|
sectionName: string;
|
|
|
|
|
value: unknown;
|
2026-03-21 08:56:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VerificationHistoryEntry {
|
|
|
|
|
id: string;
|
|
|
|
|
agentProfileId: string;
|
|
|
|
|
status: VerificationStatus;
|
|
|
|
|
note: string | null;
|
|
|
|
|
adminId: string | null;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
admin: { id: string; email: string } | null;
|
2026-03-31 22:39:02 +05:30
|
|
|
submittedData: Record<string, any> | null;
|
2025-12-22 11:53:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const usersService = new UsersService();
|