feat: added socket io to queues page

This commit is contained in:
canove
2021-01-11 06:53:59 -03:00
parent be320fa34b
commit f642f2c788
2 changed files with 86 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { Request, Response } from "express";
import { getIO } from "../libs/socket";
import CreateQueueService from "../services/QueueService/CreateQueueService";
import DeleteQueueService from "../services/QueueService/DeleteQueueService";
import ListQueuesService from "../services/QueueService/ListQueuesService";
@@ -16,6 +17,12 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
const queue = await CreateQueueService({ name, color, greetingMessage });
const io = getIO();
io.emit("queue", {
action: "update",
queue
});
return res.status(200).json(queue);
};
@@ -35,6 +42,12 @@ export const update = async (
const queue = await UpdateQueueService(queueId, req.body);
const io = getIO();
io.emit("queue", {
action: "update",
queue
});
return res.status(201).json(queue);
};
@@ -46,5 +59,11 @@ export const remove = async (
await DeleteQueueService(queueId);
const io = getIO();
io.emit("queue", {
action: "delete",
queueId: +queueId
});
return res.status(200).send();
};