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 摘要。