Corretores Worker
The corretores worker handles real estate agent (corretor) registration, approval workflow, and public listings of approved agents.
API Endpoints
| Method | Path | Auth | Description |
|---|---|---|---|
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..."}| Field | Type | Required | Rules |
|---|---|---|---|
name | string | ✅ | 2–200 characters |
email | string | ✅ | Valid email |
whatsapp | string | ✅ | 10–13 digits |
creci_estado | string | ✅ | 2-letter Brazilian UF |
creci_numero | string | ✅ | Max 20 characters |
cidade | string | ✅ | Max 200 characters |
estado | string | ✅ | 2-letter UF |
especializacao | string | ❌ | Must be one of the enum values below |
mensagem | string | ❌ | Max 2000 characters |
Valid especializacao values
| Value | Description |
|---|---|
Imóveis Residenciais | Residential properties |
Imóveis Comerciais | Commercial properties |
Imóveis de Luxo | Luxury properties |
Loteamentos e Terrenos | Land and lots |
Imóveis para Temporada | Vacation rentals |
Investimentos Imobiliários | Real estate investments |
Primeiro Imóvel | First-time buyers |
Corporativo | Corporate clients |
Outro | Other |
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
| Param | Description |
|---|---|
state | Filter by 2-letter UF (e.g. SP) |
city | Filter by city name |
limit | Max 100 |
offset | Pagination 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
404if 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:
| Field | Description |
|---|---|
bio | Agent biography |
notes | Internal notes |
profile_image | URL 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);statusvalues:pending,approved,rejected- Only
approvedagents appear in public listings
Development
cd corretores-workernpm run devDeployment
cd corretores-worker && npm run deploy