feat: Update to allow creation of remote tickets from cost center
parent
a6d800f17a
commit
5eac253549
|
@ -71,9 +71,9 @@ export const listQueues = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
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();
|
const io = getIO();
|
||||||
io.emit("queue", {
|
io.emit("queue", {
|
||||||
|
|
|
@ -77,6 +77,7 @@ import { botSendMessage } from "../services/WbotServices/wbotMessageListener";
|
||||||
import WhatsappQueue from "../models/WhatsappQueue";
|
import WhatsappQueue from "../models/WhatsappQueue";
|
||||||
import { get } from "../helpers/RedisClient";
|
import { get } from "../helpers/RedisClient";
|
||||||
import CountStatusChatEndService from "../services/StatusChatEndService/CountStatusChatEndService";
|
import CountStatusChatEndService from "../services/StatusChatEndService/CountStatusChatEndService";
|
||||||
|
import Queue from "../models/Queue";
|
||||||
|
|
||||||
export const index = async (req: Request, res: Response): Promise<Response> => {
|
export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const {
|
const {
|
||||||
|
@ -119,14 +120,15 @@ export const remoteTicketCreation = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<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;
|
let whatsappId: any;
|
||||||
|
|
||||||
if (!queueId && !contact_from) {
|
if (!queueId && !contact_from && !cc) {
|
||||||
return res
|
return res.status(400).json({
|
||||||
.status(400)
|
error: `Property 'queueId' or 'contact_from' or 'cc' is required.`
|
||||||
.json({ error: `Property 'queueId' or 'contact_from' is required.` });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const validate = ["contact_to", "msg"];
|
const validate = ["contact_to", "msg"];
|
||||||
|
@ -182,6 +184,25 @@ export const remoteTicketCreation = async (
|
||||||
|
|
||||||
queueId = queues[0].id;
|
queueId = queues[0].id;
|
||||||
whatsappId = 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);
|
// const validNumber = await CheckIsValidContact(contact_to, true);
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
};
|
|
@ -36,6 +36,9 @@ class Queue extends Model<Queue> {
|
||||||
@Column
|
@Column
|
||||||
greetingMessage: string;
|
greetingMessage: string;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
cc: string;
|
||||||
|
|
||||||
@CreatedAt
|
@CreatedAt
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ interface QueueData {
|
||||||
name: string;
|
name: string;
|
||||||
color: string;
|
color: string;
|
||||||
greetingMessage?: string;
|
greetingMessage?: string;
|
||||||
|
cc?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateQueueService = async (queueData: QueueData): Promise<Queue> => {
|
const CreateQueueService = async (queueData: QueueData): Promise<Queue> => {
|
||||||
|
|
|
@ -3,12 +3,13 @@ import * as Yup from "yup";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
import Queue from "../../models/Queue";
|
import Queue from "../../models/Queue";
|
||||||
import ShowQueueService from "./ShowQueueService";
|
import ShowQueueService from "./ShowQueueService";
|
||||||
import { set } from "../../helpers/RedisClient"
|
import { set } from "../../helpers/RedisClient";
|
||||||
|
|
||||||
interface QueueData {
|
interface QueueData {
|
||||||
name?: string;
|
name?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
greetingMessage?: string;
|
greetingMessage?: string;
|
||||||
|
cc?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpdateQueueService = async (
|
const UpdateQueueService = async (
|
||||||
|
|
|
@ -10,9 +10,9 @@ const ListWhatsAppsForQueueService = async (
|
||||||
queueId: number | string,
|
queueId: number | string,
|
||||||
status?: string
|
status?: string
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
let distinctWhatsapps: any;
|
let distinctWhatsapps: any[] = [];
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
distinctWhatsapps = await sequelize.query(
|
distinctWhatsapps = await sequelize.query(
|
||||||
`SELECT w.id, w.number, w.status, wq.whatsappId, wq.queueId FROM Whatsapps w
|
`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}'
|
JOIN WhatsappQueues wq ON w.id = wq.whatsappId AND wq.queueId = ${queueId} AND w.status = '${status}'
|
||||||
|
|
|
@ -70,6 +70,7 @@ const QueueModal = ({ open, onClose, queueId }) => {
|
||||||
name: "",
|
name: "",
|
||||||
color: "",
|
color: "",
|
||||||
greetingMessage: "",
|
greetingMessage: "",
|
||||||
|
cc:""
|
||||||
};
|
};
|
||||||
|
|
||||||
const [colorPickerModalOpen, setColorPickerModalOpen] = useState(false);
|
const [colorPickerModalOpen, setColorPickerModalOpen] = useState(false);
|
||||||
|
@ -94,6 +95,7 @@ const QueueModal = ({ open, onClose, queueId }) => {
|
||||||
name: "",
|
name: "",
|
||||||
color: "",
|
color: "",
|
||||||
greetingMessage: "",
|
greetingMessage: "",
|
||||||
|
cc: ""
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}, [queueId, open]);
|
}, [queueId, open]);
|
||||||
|
@ -213,6 +215,19 @@ const QueueModal = ({ open, onClose, queueId }) => {
|
||||||
margin="dense"
|
margin="dense"
|
||||||
/>
|
/>
|
||||||
</div>
|
</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>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
|
|
Loading…
Reference in New Issue