feat(Tags): implement user-specific tag management and enhance related services

- Added ownerId field to Tag model to associate tags with users.
- Updated tagsService methods to enforce user ownership in tag operations.
- Enhanced API routes to include user authentication and ownership checks for tag retrieval and management.
- Modified seeding script to assign tags to the first user found in the database.
- Updated various components and services to ensure user-specific tag handling throughout the application.
This commit is contained in:
Julien Froidefond
2025-10-11 15:03:59 +02:00
parent 583efaa8c5
commit 7952459b42
17 changed files with 329 additions and 177 deletions

View File

@@ -1,7 +1,22 @@
import { PrismaClient } from '@prisma/client';
import { tagsService } from '../src/services/task-management/tags';
const prisma = new PrismaClient();
async function seedTags() {
console.log('🏷️ Création des tags de test...');
console.log('🌱 Début du seeding des tags...');
// Récupérer le premier utilisateur pour assigner les tags
const firstUser = await prisma.user.findFirst({
orderBy: { createdAt: 'asc' },
});
if (!firstUser) {
console.log("❌ Aucun utilisateur trouvé. Créez d'abord un utilisateur.");
return;
}
console.log(`👤 Assignation des tags à: ${firstUser.email}`);
const testTags = [
{ name: 'frontend', color: '#3B82F6' },
@@ -19,9 +34,15 @@ async function seedTags() {
for (const tagData of testTags) {
try {
const existing = await tagsService.getTagByName(tagData.name);
const existing = await tagsService.getTagByName(
tagData.name,
firstUser.id
);
if (!existing) {
const tag = await tagsService.createTag(tagData);
const tag = await tagsService.createTag({
...tagData,
userId: firstUser.id,
});
console.log(`✅ Tag créé: ${tag.name} (${tag.color})`);
} else {
console.log(`⚠️ Tag existe déjà: ${tagData.name}`);