cre-sync/lib/ghl/services/custom-fields.ts
BusyBee3333 4e6467ffb0 Add CRESync CRM application with Setup page
- Build complete Next.js CRM for commercial real estate
- Add authentication with JWT sessions and role-based access
- Add GoHighLevel API integration for contacts, conversations, opportunities
- Add AI-powered Control Center with tool calling
- Add Setup page with onboarding checklist (/setup)
- Add sidebar navigation with Setup menu item
- Fix type errors in onboarding API, GHL services, and control center tools
- Add Prisma schema with SQLite for local development
- Add UI components with clay morphism design system

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:30:55 -05:00

71 lines
2.3 KiB
TypeScript

import { GHLClient } from '../client';
import { GHLCustomField } from '@/types/ghl';
export interface CustomValue {
id: string;
name: string;
value: string;
}
export class CustomFieldsService {
constructor(
private client: GHLClient,
private locationId: string
) {}
// Get all custom fields for a location
async getCustomFields(): Promise<GHLCustomField[]> {
const response = await this.client.get(`/locations/${this.locationId}/customFields`);
return (response as any).customFields || [];
}
// Create a new custom field
async createCustomField(data: {
name: string;
dataType: 'TEXT' | 'NUMBER' | 'DATE' | 'CHECKBOX' | 'LIST';
position?: number;
}): Promise<GHLCustomField> {
return this.client.post(`/locations/${this.locationId}/customFields`, data);
}
// Update a custom field
async updateCustomField(fieldId: string, data: { name?: string; position?: number }): Promise<GHLCustomField> {
return this.client.put(`/locations/${this.locationId}/customFields/${fieldId}`, data);
}
// Delete a custom field
async deleteCustomField(fieldId: string): Promise<void> {
await this.client.delete(`/locations/${this.locationId}/customFields/${fieldId}`);
}
// Get all custom values (for message templates)
async getCustomValues(): Promise<CustomValue[]> {
const response = await this.client.get(`/locations/${this.locationId}/customValues`);
return (response as any).customValues || [];
}
// Update a custom value
async updateCustomValue(valueId: string, value: string): Promise<CustomValue> {
return this.client.put(`/locations/${this.locationId}/customValues/${valueId}`, { value });
}
// Create a custom value
async createCustomValue(name: string, value: string): Promise<CustomValue> {
return this.client.post(`/locations/${this.locationId}/customValues`, { name, value });
}
// Bulk update custom values (useful for onboarding)
async bulkUpdateCustomValues(values: { name: string; value: string }[]): Promise<void> {
const existingValues = await this.getCustomValues();
for (const { name, value } of values) {
const existing = existingValues.find(v => v.name === name);
if (existing) {
await this.updateCustomValue(existing.id, value);
} else {
await this.createCustomValue(name, value);
}
}
}
}