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

Partner CRUD operations

Đang mở
#39 0 bình luận 0 reaction 1 người được giao Được @marrious11 nhận Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
2
Fork
11
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.