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,5 @@
const { Room, School } = require('../models');
const { cacheUtils } = require('../config/redis');
const { addDatabaseWriteJob } = require('../config/bullmq');
/**
* Room Controller - Quản lý phòng học
@@ -97,21 +96,20 @@ class RoomController {
}
/**
* Create new room (async via BullMQ)
* Create new room
*/
async createRoom(req, res, next) {
try {
const roomData = req.body;
const job = await addDatabaseWriteJob('create', 'Room', roomData);
const room = await Room.create(roomData);
await cacheUtils.deletePattern('rooms:list:*');
res.status(202).json({
res.status(201).json({
success: true,
message: 'Room creation job queued',
jobId: job.id,
data: roomData,
message: 'Room created successfully',
data: room,
});
} catch (error) {
next(error);
@@ -119,25 +117,31 @@ class RoomController {
}
/**
* Update room (async via BullMQ)
* Update room
*/
async updateRoom(req, res, next) {
try {
const { id } = req.params;
const updates = req.body;
const job = await addDatabaseWriteJob('update', 'Room', {
id,
updates,
});
const room = await Room.findByPk(id);
if (!room) {
return res.status(404).json({
success: false,
message: 'Room not found',
});
}
await room.update(updates);
await cacheUtils.delete(`room:${id}`);
await cacheUtils.deletePattern('rooms:list:*');
res.status(202).json({
res.json({
success: true,
message: 'Room update job queued',
jobId: job.id,
message: 'Room updated successfully',
data: room,
});
} catch (error) {
next(error);
@@ -145,21 +149,29 @@ class RoomController {
}
/**
* Delete room (async via BullMQ)
* Delete room
*/
async deleteRoom(req, res, next) {
try {
const { id } = req.params;
const job = await addDatabaseWriteJob('delete', 'Room', { id });
const room = await Room.findByPk(id);
if (!room) {
return res.status(404).json({
success: false,
message: 'Room not found',
});
}
await room.destroy();
await cacheUtils.delete(`room:${id}`);
await cacheUtils.deletePattern('rooms:list:*');
res.status(202).json({
res.json({
success: true,
message: 'Room deletion job queued',
jobId: job.id,
message: 'Room deleted successfully',
});
} catch (error) {
next(error);