feat(Task): implement user ownership for tasks and enhance related services
- Added ownerId field to Task model to associate tasks with users. - Updated TaskService methods to enforce user ownership in task operations. - Enhanced API routes to include user authentication and ownership checks. - Modified DailyService and analytics services to filter tasks by user. - Integrated user session handling in various components for personalized task management.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { tasksService } from '../src/services/task-management/tasks';
|
||||
import { TaskStatus, TaskPriority } from '../src/lib/types';
|
||||
import { prisma } from '../src/services/core/database';
|
||||
|
||||
/**
|
||||
* Script pour ajouter des données de test avec tags et variété
|
||||
@@ -8,6 +9,28 @@ async function seedTestData() {
|
||||
console.log('🌱 Ajout de données de test...');
|
||||
console.log('================================');
|
||||
|
||||
// Récupérer le premier user ou créer un user temporaire
|
||||
let userId: string;
|
||||
const firstUser = await prisma.user.findFirst({
|
||||
orderBy: { createdAt: 'asc' },
|
||||
});
|
||||
|
||||
if (firstUser) {
|
||||
userId = firstUser.id;
|
||||
console.log(`👤 Utilisation du user existant: ${firstUser.email}`);
|
||||
} else {
|
||||
// Créer un user temporaire pour les tests
|
||||
const tempUser = await prisma.user.create({
|
||||
data: {
|
||||
email: 'test@example.com',
|
||||
name: 'Test User',
|
||||
password: '$2b$10$temp', // Mot de passe temporaire
|
||||
},
|
||||
});
|
||||
userId = tempUser.id;
|
||||
console.log(`👤 User temporaire créé: ${tempUser.email}`);
|
||||
}
|
||||
|
||||
const testTasks = [
|
||||
{
|
||||
title: '🎨 Design System Implementation',
|
||||
@@ -58,7 +81,10 @@ async function seedTestData() {
|
||||
|
||||
for (const taskData of testTasks) {
|
||||
try {
|
||||
const task = await tasksService.createTask(taskData);
|
||||
const task = await tasksService.createTask({
|
||||
...taskData,
|
||||
ownerId: userId, // Ajouter l'ownerId
|
||||
});
|
||||
|
||||
const statusEmoji = {
|
||||
backlog: '📋',
|
||||
@@ -101,7 +127,7 @@ async function seedTestData() {
|
||||
console.log(` ❌ Erreurs: ${errorCount}`);
|
||||
|
||||
// Afficher les stats finales
|
||||
const stats = await tasksService.getTaskStats();
|
||||
const stats = await tasksService.getTaskStats(userId);
|
||||
console.log('');
|
||||
console.log('📈 Statistiques finales:');
|
||||
console.log(` Total: ${stats.total} tâches`);
|
||||
|
||||
Reference in New Issue
Block a user