update
All checks were successful
Deploy to Production / deploy (push) Successful in 21s

This commit is contained in:
silverpro89
2026-01-28 11:21:21 +07:00
parent 57c45d27a3
commit 3791b7cae1
23 changed files with 1033 additions and 317 deletions

View File

@@ -1,6 +1,6 @@
const { ParentAssignedTask, GradeItem, StudentDetail, UsersAuth, ParentStudentMap } = require('../models');
const { cacheUtils } = require('../config/redis');
const { addDatabaseWriteJob, addNotificationJob } = require('../config/bullmq');
const { addNotificationJob } = require('../config/bullmq');
const { v4: uuidv4 } = require('uuid');
/**
@@ -64,8 +64,8 @@ class ParentTaskController {
priority: priority || 'normal',
};
// Async write to DB via BullMQ
await addDatabaseWriteJob('create', 'ParentAssignedTask', taskData);
// Create task directly in database
const task = await ParentAssignedTask.create(taskData);
// Gửi notification cho học sinh
await addNotificationJob({
@@ -80,10 +80,10 @@ class ParentTaskController {
await cacheUtils.del(`parent:tasks:${parent_id}`);
await cacheUtils.del(`student:tasks:${student_id}`);
res.status(202).json({
res.status(201).json({
success: true,
message: 'Task assignment request queued',
data: taskData,
message: 'Task assigned successfully',
data: task,
});
} catch (error) {
next(error);
@@ -138,11 +138,7 @@ class ParentTaskController {
for (const task of tasks) {
if (task.status !== 'completed' && new Date(task.due_date) < now) {
if (task.status !== 'overdue') {
await addDatabaseWriteJob('update', 'ParentAssignedTask', {
id: task.id,
status: 'overdue',
});
task.status = 'overdue';
await task.update({ status: 'overdue' });
}
}
}
@@ -235,8 +231,7 @@ class ParentTaskController {
});
}
await addDatabaseWriteJob('update', 'ParentAssignedTask', {
id,
await task.update({
status: 'completed',
completion_date: new Date(),
student_notes: student_notes || null,
@@ -255,9 +250,10 @@ class ParentTaskController {
await cacheUtils.del(`parent:tasks:${task.parent_id}:*`);
await cacheUtils.del(`student:tasks:${task.student_id}:*`);
res.status(202).json({
res.status(200).json({
success: true,
message: 'Task completion request queued',
message: 'Task completed successfully',
data: task,
});
} catch (error) {
next(error);
@@ -288,18 +284,16 @@ class ParentTaskController {
});
}
await addDatabaseWriteJob('update', 'ParentAssignedTask', {
id,
status,
});
await task.update({ status });
// Clear cache
await cacheUtils.del(`parent:tasks:${task.parent_id}:*`);
await cacheUtils.del(`student:tasks:${task.student_id}:*`);
res.status(202).json({
res.status(200).json({
success: true,
message: 'Task status update queued',
message: 'Task status updated successfully',
data: task,
});
} catch (error) {
next(error);
@@ -330,15 +324,15 @@ class ParentTaskController {
});
}
await addDatabaseWriteJob('delete', 'ParentAssignedTask', { id });
await task.destroy();
// Clear cache
await cacheUtils.del(`parent:tasks:${task.parent_id}:*`);
await cacheUtils.del(`student:tasks:${task.student_id}:*`);
res.status(202).json({
res.status(200).json({
success: true,
message: 'Task deletion request queued',
message: 'Task deleted successfully',
});
} catch (error) {
next(error);