feat: Update task assignment logic to exclude admin users and enhance project page layout

This commit is contained in:
2025-09-29 19:25:15 +02:00
parent 5aac63dfde
commit e68b185aeb
4 changed files with 24 additions and 23 deletions

View File

@@ -47,10 +47,19 @@ async function createProjectTaskHandler(req) {
const taskData = {
...data,
created_by: req.user?.id || null,
// If no assigned_to is specified, default to the creator
assigned_to: data.assigned_to || req.user?.id || null,
};
// Set assigned_to: if specified, use it; otherwise default to creator only if they're not admin
if (data.assigned_to) {
taskData.assigned_to = data.assigned_to;
} else if (req.user?.id) {
// Check if the creator is an admin - if so, don't assign to them
const userRole = db.prepare('SELECT role FROM users WHERE id = ?').get(req.user.id);
taskData.assigned_to = userRole?.role === 'admin' ? null : req.user.id;
} else {
taskData.assigned_to = null;
}
const result = createProjectTask(taskData);
return NextResponse.json({ success: true, id: result.lastInsertRowid });
} catch (error) {