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

Partner CRUD operations

未關閉
#39 0 則留言 0 個 reaction 已指派 1 人 已被 @marrious11 認領 在 GitHub 檢視
主要語言
JavaScript
星號
2
分支
11
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。