Pular para o conteúdo

Corretores Worker

The corretores worker handles real estate agent (corretor) registration, approval workflow, and public listings of approved agents.

API Endpoints

MethodPathAuthDescription
POST/api/corretores—Register as a real estate agent
GET/api/corretores—List approved agents
GET/api/corretores/:id—Get single approved agent
PUT/api/corretores/:id✅Update own agent profile
DELETE/api/corretores/:id✅Delete own agent profile

POST /api/corretores

Register as a real estate agent. No auth required (anyone can apply).

Request body

{
"name": "Maria Souza",
"email": "maria@corretora.com",
"whatsapp": "11999999999",
"creci_estado": "SP",
"creci_numero": "123456",
"cidade": "São Paulo",
"estado": "SP",
"especializacao": "Imóveis Residenciais",
"mensagem": "Tenho 10 anos de experiência no mercado..."
}
FieldTypeRequiredRules
namestring✅2–200 characters
emailstring✅Valid email
whatsappstring✅10–13 digits
creci_estadostring✅2-letter Brazilian UF
creci_numerostring✅Max 20 characters
cidadestring✅Max 200 characters
estadostring✅2-letter UF
especializacaostring❌Must be one of the enum values below
mensagemstring❌Max 2000 characters

Valid especializacao values

ValueDescription
Imóveis ResidenciaisResidential properties
Imóveis ComerciaisCommercial properties
Imóveis de LuxoLuxury properties
Loteamentos e TerrenosLand and lots
Imóveis para TemporadaVacation rentals
Investimentos ImobiliáriosReal estate investments
Primeiro ImóvelFirst-time buyers
CorporativoCorporate clients
OutroOther

Business Rules

  • Status is stored as pending (requires admin approval)
  • Rate limits: 5 per IP / 15 min, 3 per email / 15 min

Response 201 Created

{
"id": "uuid",
"message": "Cadastro recebido com sucesso! Nossa equipe irá analisar seus dados."
}

GET /api/corretores

List approved real estate agents. No auth required.

Query params

ParamDescription
stateFilter by 2-letter UF (e.g. SP)
cityFilter by city name
limitMax 100
offsetPagination offset

Response 200 OK

{
"agents": [
{
"id": "uuid",
"name": "Maria Souza",
"email": "maria@corretora.com",
"whatsapp": "11999999999",
"creci_estado": "SP",
"creci_numero": "123456",
"cidade": "São Paulo",
"estado": "SP",
"especializacao": "Imóveis Residenciais",
"mensagem": "Tenho 10 anos...",
"status": "approved",
"created_at": "..."
}
]
}
  • Only returns agents with status = 'approved'

GET /api/corretores/:id

Get a single approved agent profile. No auth required.

Response 200 OK

Single agent object (same shape as list items).

  • Returns 404 if agent not found or not approved

PUT /api/corretores/:id

Update own agent profile. Requires auth + ownership (user_id must match).

Request body

Partial update — any subset of create fields plus:

FieldDescription
bioAgent biography
notesInternal notes
profile_imageURL to profile image

Response 200 OK

{
"message": "Cadastro atualizado com sucesso"
}

DELETE /api/corretores/:id

Delete own agent profile. Requires auth + ownership.

Response 204 No Content


Data Model

Corretores are stored in the corretores table in D1:

CREATE TABLE corretores (
id TEXT PRIMARY KEY,
user_id TEXT,
name TEXT NOT NULL,
email TEXT NOT NULL,
whatsapp TEXT,
creci_estado TEXT,
creci_numero TEXT,
cidade TEXT,
estado TEXT,
especializacao TEXT,
mensagem TEXT,
bio TEXT,
notes TEXT,
profile_image TEXT,
status TEXT DEFAULT 'pending',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
  • status values: pending, approved, rejected
  • Only approved agents appear in public listings

Development

Terminal window
cd corretores-worker
npm run dev

Deployment

Terminal window
cd corretores-worker && npm run deploy