mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
improvement: block open another ticket from same contact when already a open / pending ticket
This commit is contained in:
17
backend/src/helpers/CheckContactOpenTickets.ts
Normal file
17
backend/src/helpers/CheckContactOpenTickets.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Op } from "sequelize";
|
||||
import AppError from "../errors/AppError";
|
||||
import Ticket from "../models/Ticket";
|
||||
|
||||
const CheckContactOpenTickets = async (contactId: number): Promise<void> => {
|
||||
const ticket = await Ticket.findOne({
|
||||
where: { contactId, status: { [Op.or]: ["open", "pending"] } }
|
||||
});
|
||||
|
||||
if (ticket) {
|
||||
throw new AppError(
|
||||
"There's already an open or pending ticket for this contact."
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default CheckContactOpenTickets;
|
||||
Reference in New Issue
Block a user