Отслеживание просмотров задач: task_views, POST /api/tasks/:id/view и обновление /api/home/recent

This commit is contained in:
2026-08-24 15:40:30 +03:00
parent 74abd8fad5
commit a4eaf65915
7 changed files with 107 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { users, forms, tasks, taskMessages, messageReads, bots, roles, type User, type Form, type FormTab, type FormField, type FormStatus, type StatusTransition, type Task, type TaskFieldValue, type TaskMessage, type TaskMessageWithAuthor, type MessageRead, type DataTableRow } from "@shared/schema";
import { users, forms, tasks, taskMessages, messageReads, bots, roles, taskViews, type User, type Form, type FormTab, type FormField, type FormStatus, type StatusTransition, type Task, type TaskFieldValue, type TaskMessage, type TaskMessageWithAuthor, type MessageRead, type DataTableRow } from "@shared/schema";
import { taskRelations } from "@shared/schema";
import { taskAssignees, type TaskAssignee } from "@shared/schema";
import { db } from "../db";
@@ -614,4 +614,24 @@ export class TasksStorage extends TasksCoreStorage {
.where(and(eq(taskAssignees.taskId, taskId), eq(taskAssignees.organizationId, organizationId)));
return rows;
}
// =====================
// Task Views (recently viewed tasks for the home "Recent" tab)
// =====================
async recordTaskView(taskId: number, userId: number, organizationId: number): Promise<void> {
await db
.insert(taskViews)
.values({
taskId,
userId,
organizationId,
})
.onConflictDoUpdate({
target: [taskViews.organizationId, taskViews.userId, taskViews.taskId],
set: {
viewedAt: sql`CURRENT_TIMESTAMP`,
},
});
}
}