DevByte-Community / DevByte-Community/Community-API-Backend

Partner CRUD operations

Abierto
#39 0 comentarios 0 reacciones 1 asignado Reclamado por @marrious11 Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
2
Forks
11
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Epic: Content Management (Backend)
Ticket ID: CMS-02
Priority: Medium

**Description**
Implement full CRUD operations for the partner entity as defined in the class diagram. This includes creating, reading, updating, and deleting partner records with proper validation for company details, logo storage via MinIO, and visibility control. Partners represent external collaborators/sponsors, so all operations require admin authentication (via roles), with public read access for display on the platform (e.g., sponsors page).

**Acceptance Criteria**

1. Database Setup
- [ ] Create partners table with fields:
```
id: STRING (PK, unique identifier like 'partner-001')
name: STRING (NOT NULL)
description: STRING (NOT NULL)
logo: STRING (MinIO URL)
email: STRING (NOT NULL, validated as email)
created_at: TIMESTAMPTZ
updated_at: TIMESTAMPTZ
```
- [ ] Add indexes:
- name (for quick search)
- email (unique, for contact lookups)

- [ ] Add unique constraint on name and email.

2. CRUD Endpoints

POST `/api/v1/partners` | Admin only | Create new partner
GET `/api/v1/partners` | Public | List partners (filterable)
GET `/api/v1/partners/:id` | Public | Get single partner
PATCH `/api/v1/partners/:id` | Admin only | Update partner
DELETE `/api/v1/partners/:id` | Admin only | Delete partner

3. Response Examples
Success (POST)
```
{
"success": true,
"message": "Partner created successfully",
"partner": {
"id": "partner-001",
"name": "TechCorp Inc.",
"description": "Leading tech innovator",
"logo": "http://minio:9000/partners/partner-001_logo.svg",
"email": "contact@techcorp.com",
"created_at": "2025-04-05T10:00:00Z",
"updated_at": "2025-04-05T10:00:00Z"
}
}
```

Success (GET List)
```
{
"success": true,
"data": [/* array of partners */],
"pagination": {
"page": 1,
"limit": 20,
"total": 15
}
}
```

Error (Duplicate Name)
```
{
"error": "Partner name must be unique",
"status": 409
}
```

4. Security & Logging

- [ ] Admin-only for POST/PUT/DELETE (check req.user.roles.includes('ADMIN')).
- [ ] Public read for GET endpoints.
- [ ] Validate email format and uniqueness.
- [ ] Validate logo: SVG/PNG, ≤2MB (logos are small).
- [ ] Log all actions: `adminUserId, partnerId, action, ip, timestamp`

5. Testing (Jest + Supertest)
- Unit Tests

- [ ] Admin authorization enforcement.
- [ ] Email/name uniqueness.
- [ ] Logo file validation.

- Integration Tests

- [ ] Full CRUD flow with MinIO.
- [ ] Pagination and search.
- [ ] Logo cleanup on delete/update.
- [ ] Public vs admin access (403 on non-admin write).

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.