feat: Update to allow creation of remote tickets from cost center

feat-scaling-ticket-remote-creation
adriano 2024-04-03 18:38:56 -03:00
parent a6d800f17a
commit 5eac253549
8 changed files with 65 additions and 10 deletions

View File

@ -71,9 +71,9 @@ export const listQueues = async (
};
export const store = async (req: Request, res: Response): Promise<Response> => {
const { name, color, greetingMessage } = req.body;
const { name, color, greetingMessage, cc } = req.body;
const queue = await CreateQueueService({ name, color, greetingMessage });
const queue = await CreateQueueService({ name, color, greetingMessage, cc });
const io = getIO();
io.emit("queue", {

View File

@ -77,6 +77,7 @@ import { botSendMessage } from "../services/WbotServices/wbotMessageListener";
import WhatsappQueue from "../models/WhatsappQueue";
import { get } from "../helpers/RedisClient";
import CountStatusChatEndService from "../services/StatusChatEndService/CountStatusChatEndService";
import Queue from "../models/Queue";
export const index = async (req: Request, res: Response): Promise<Response> => {
const {
@ -119,14 +120,15 @@ export const remoteTicketCreation = async (
req: Request,
res: Response
): Promise<Response> => {
let { queueId, contact_from, contact_to, msg, contact_name }: any = req.body;
let { queueId, contact_from, cc, contact_to, msg, contact_name }: any =
req.body;
let whatsappId: any;
if (!queueId && !contact_from) {
return res
.status(400)
.json({ error: `Property 'queueId' or 'contact_from' is required.` });
if (!queueId && !contact_from && !cc) {
return res.status(400).json({
error: `Property 'queueId' or 'contact_from' or 'cc' is required.`
});
}
const validate = ["contact_to", "msg"];
@ -182,6 +184,25 @@ export const remoteTicketCreation = async (
queueId = queues[0].id;
whatsappId = id;
} else if (cc) {
const queue = await Queue.findOne({ where: { cc } });
if (!queue) {
return res.status(404).json({
msg: `Queue with cc ${cc} not found! `
});
}
queueId = queue.id;
const whatsapps = await ListWhatsAppsForQueueService(queueId, "CONNECTED");
if ( whatsapps.length === 0) {
return res.status(500).json({
msg: `No WhatsApp found for this cc ${cc} or the WhatsApp number is disconnected! `
});
}
whatsappId = whatsapps[0].id;
}
// const validNumber = await CheckIsValidContact(contact_to, true);

View File

@ -0,0 +1,14 @@
import { QueryInterface, DataTypes } from "sequelize";
module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.addColumn("Queues", "cc", {
type: DataTypes.STRING,
allowNull: true
});
},
down: (queryInterface: QueryInterface) => {
return queryInterface.removeColumn("Queues", "cc");
}
};

View File

@ -36,6 +36,9 @@ class Queue extends Model<Queue> {
@Column
greetingMessage: string;
@Column
cc: string;
@CreatedAt
createdAt: Date;

View File

@ -7,6 +7,7 @@ interface QueueData {
name: string;
color: string;
greetingMessage?: string;
cc?: string;
}
const CreateQueueService = async (queueData: QueueData): Promise<Queue> => {

View File

@ -3,12 +3,13 @@ import * as Yup from "yup";
import AppError from "../../errors/AppError";
import Queue from "../../models/Queue";
import ShowQueueService from "./ShowQueueService";
import { set } from "../../helpers/RedisClient"
import { set } from "../../helpers/RedisClient";
interface QueueData {
name?: string;
color?: string;
greetingMessage?: string;
cc?: string;
}
const UpdateQueueService = async (

View File

@ -10,9 +10,9 @@ const ListWhatsAppsForQueueService = async (
queueId: number | string,
status?: string
): Promise<any> => {
let distinctWhatsapps: any;
let distinctWhatsapps: any[] = [];
if (status) {
if (status) {
distinctWhatsapps = await sequelize.query(
`SELECT w.id, w.number, w.status, wq.whatsappId, wq.queueId FROM Whatsapps w
JOIN WhatsappQueues wq ON w.id = wq.whatsappId AND wq.queueId = ${queueId} AND w.status = '${status}'

View File

@ -70,6 +70,7 @@ const QueueModal = ({ open, onClose, queueId }) => {
name: "",
color: "",
greetingMessage: "",
cc:""
};
const [colorPickerModalOpen, setColorPickerModalOpen] = useState(false);
@ -94,6 +95,7 @@ const QueueModal = ({ open, onClose, queueId }) => {
name: "",
color: "",
greetingMessage: "",
cc: ""
});
};
}, [queueId, open]);
@ -213,6 +215,19 @@ const QueueModal = ({ open, onClose, queueId }) => {
margin="dense"
/>
</div>
<div>
<Field
as={TextField}
label="CC"
autoFocus
name="cc"
error={touched.cc && Boolean(errors.cc)}
helperText={touched.cc && errors.cc}
variant="outlined"
margin="dense"
className={classes.textField}
/>
</div>
</DialogContent>
<DialogActions>
<Button