Files
frontend/src/services/agents.service.ts

119 lines
2.9 KiB
TypeScript
Raw Normal View History

import api from './api';
// Types
export interface AgentType {
id: string;
name: string;
slug: string;
description: string | null;
}
export interface AgentProfile {
id: string;
userId: string;
firstName: string;
lastName: string;
slug: string;
email: string | null;
phone: string | null;
bio: string | null;
avatar: string | null;
licenseNumber: string | null;
experience: number | null;
specializations: string[];
languages: string[];
serviceAreas: string[];
rating: number | null;
reviewCount: number;
isVerified: boolean;
isFeatured: boolean;
isActive: boolean;
agentTypeId: string | null;
agentType: AgentType | null;
user?: {
id: string;
email: string;
avatar: string | null;
};
}
interface ApiResponse<T> {
success: boolean;
data: T;
message?: string;
}
2026-01-24 21:06:13 +05:30
export interface FieldValueInput {
fieldSlug: string;
2026-01-24 21:36:37 +05:30
value: string | number | boolean | string[] | Record<string, unknown> | Record<string, unknown>[] | null;
2026-01-24 21:06:13 +05:30
}
export interface FieldValueResponse {
fieldSlug: string;
fieldName: string;
fieldType: string;
sectionSlug: string;
sectionName: string;
value: unknown;
}
export interface GetFieldValuesResponse {
agentProfileId: string;
fieldValues: FieldValueResponse[];
}
export interface SaveFieldValuesResponse {
message: string;
savedCount: number;
data: unknown[];
}
// Agents Service for Web
class AgentsService {
private basePath = '/agents';
async getMyProfile(): Promise<AgentProfile> {
const response = await api.get<ApiResponse<AgentProfile>>(`${this.basePath}/profile/me`);
return response.data.data;
}
async getAgentById(id: string): Promise<AgentProfile> {
const response = await api.get<ApiResponse<AgentProfile>>(`${this.basePath}/${id}`);
return response.data.data;
}
async updateProfile(data: Partial<AgentProfile>): Promise<AgentProfile> {
const response = await api.put<ApiResponse<AgentProfile>>(`${this.basePath}/profile`, data);
return response.data.data;
}
2026-01-24 21:06:13 +05:30
async saveFieldValues(fieldValues: FieldValueInput[]): Promise<SaveFieldValuesResponse> {
const response = await api.put<ApiResponse<SaveFieldValuesResponse>>(
`${this.basePath}/profile/field-values`,
{ fieldValues }
);
return response.data.data;
}
async getFieldValues(): Promise<GetFieldValuesResponse> {
const response = await api.get<ApiResponse<GetFieldValuesResponse>>(
`${this.basePath}/profile/field-values`
);
return response.data.data;
}
2026-01-24 23:10:02 +05:30
async getFieldValuesByAgentId(id: string): Promise<GetFieldValuesResponse> {
const response = await api.get<ApiResponse<GetFieldValuesResponse>>(
`${this.basePath}/${id}/field-values`
);
return response.data.data;
}
2026-01-24 23:52:09 +05:30
async getAgentTypes(): Promise<AgentType[]> {
const response = await api.get<ApiResponse<AgentType[]>>('/agent-types');
return response.data.data;
}
}
export const agentsService = new AgentsService();