mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
changed find to show services
This commit is contained in:
@@ -2,7 +2,7 @@ import { Request, Response } from "express";
|
|||||||
|
|
||||||
import ListContactsService from "../services/ContactServices/ListContactsService";
|
import ListContactsService from "../services/ContactServices/ListContactsService";
|
||||||
import CreateContactService from "../services/ContactServices/CreateContactService";
|
import CreateContactService from "../services/ContactServices/CreateContactService";
|
||||||
import FindContactService from "../services/ContactServices/FindContactService";
|
import ShowContactService from "../services/ContactServices/ShowContactService";
|
||||||
import UpdateContactService from "../services/ContactServices/UpdateContactService";
|
import UpdateContactService from "../services/ContactServices/UpdateContactService";
|
||||||
import DeleteContactService from "../services/ContactServices/DeleteContactService";
|
import DeleteContactService from "../services/ContactServices/DeleteContactService";
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
export const show = async (req: Request, res: Response): Promise<Response> => {
|
export const show = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { contactId } = req.params;
|
const { contactId } = req.params;
|
||||||
|
|
||||||
const contact = await FindContactService(contactId);
|
const contact = await ShowContactService(contactId);
|
||||||
|
|
||||||
return res.status(200).json(contact);
|
return res.status(200).json(contact);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import AppError from "../errors/AppError";
|
|||||||
import CreateUserService from "../services/UserServices/CreateUserService";
|
import CreateUserService from "../services/UserServices/CreateUserService";
|
||||||
import ListUsersService from "../services/UserServices/ListUsersService";
|
import ListUsersService from "../services/UserServices/ListUsersService";
|
||||||
import UpdateUserService from "../services/UserServices/UpdateUserService";
|
import UpdateUserService from "../services/UserServices/UpdateUserService";
|
||||||
import FindUserService from "../services/UserServices/FindUserService";
|
import ShowUserService from "../services/UserServices/ShowUserService";
|
||||||
import DeleteUserService from "../services/UserServices/DeleteUserService";
|
import DeleteUserService from "../services/UserServices/DeleteUserService";
|
||||||
|
|
||||||
type IndexQuery = {
|
type IndexQuery = {
|
||||||
@@ -53,7 +53,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
export const show = async (req: Request, res: Response): Promise<Response> => {
|
export const show = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { userId } = req.params;
|
const { userId } = req.params;
|
||||||
|
|
||||||
const user = await FindUserService(userId);
|
const user = await ShowUserService(userId);
|
||||||
|
|
||||||
return res.status(200).json(user);
|
return res.status(200).json(user);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Request, Response } from "express";
|
|||||||
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
||||||
import DeleteWhatsAppService from "../services/WhatsappService/DeleteWhatsAppService";
|
import DeleteWhatsAppService from "../services/WhatsappService/DeleteWhatsAppService";
|
||||||
import ListWhatsAppsService from "../services/WhatsappService/ListWhatsAppsService";
|
import ListWhatsAppsService from "../services/WhatsappService/ListWhatsAppsService";
|
||||||
import FindWhatsAppService from "../services/WhatsappService/FindWhatsAppService";
|
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
|
||||||
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
|
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
|
||||||
// import Yup from "yup";
|
// import Yup from "yup";
|
||||||
// import Whatsapp from "../models/Whatsapp";
|
// import Whatsapp from "../models/Whatsapp";
|
||||||
@@ -53,9 +53,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
export const show = async (req: Request, res: Response): Promise<Response> => {
|
export const show = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { whatsappId } = req.params;
|
const { whatsappId } = req.params;
|
||||||
|
|
||||||
console.log(whatsappId);
|
const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||||
|
|
||||||
const whatsapp = await FindWhatsAppService(whatsappId);
|
|
||||||
|
|
||||||
return res.status(200).json(whatsapp);
|
return res.status(200).json(whatsapp);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import AppError from "../errors/AppError";
|
import AppError from "../errors/AppError";
|
||||||
import Whatsapp from "../models/Whatsapp";
|
import Whatsapp from "../models/Whatsapp";
|
||||||
import FindWhatsAppService from "../services/WhatsappService/FindWhatsAppService";
|
|
||||||
|
|
||||||
const GetDefaultWhatsapp = async (): Promise<Whatsapp> => {
|
const GetDefaultWhatsApp = async (): Promise<Whatsapp> => {
|
||||||
const defaultWhatsapp = await FindWhatsAppService({
|
const defaultWhatsapp = await Whatsapp.findOne({
|
||||||
where: { isDefault: true }
|
where: { isDefault: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -14,4 +13,4 @@ const GetDefaultWhatsapp = async (): Promise<Whatsapp> => {
|
|||||||
return defaultWhatsapp;
|
return defaultWhatsapp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default GetDefaultWhatsapp;
|
export default GetDefaultWhatsApp;
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import Contact from "../../models/Contact";
|
|
||||||
import AppError from "../../errors/AppError";
|
|
||||||
|
|
||||||
const FindContactService = async (id: string): Promise<Contact> => {
|
|
||||||
const user = await Contact.findOne({
|
|
||||||
where: { id },
|
|
||||||
attributes: ["id", "name", "number", "email"]
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new AppError("No contact found with this ID.", 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
return user;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FindContactService;
|
|
||||||
14
backend/src/services/ContactServices/ShowContactService.ts
Normal file
14
backend/src/services/ContactServices/ShowContactService.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import Contact from "../../models/Contact";
|
||||||
|
import AppError from "../../errors/AppError";
|
||||||
|
|
||||||
|
const ShowContactService = async (id: string | number): Promise<Contact> => {
|
||||||
|
const user = await Contact.findByPk(id);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw new AppError("No contact found with this ID.", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ShowContactService;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import Message from "../../models/Message";
|
import Message from "../../models/Message";
|
||||||
import FindTicketService from "../TicketServices/FindTicketService";
|
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
ticketId: string;
|
ticketId: string;
|
||||||
@@ -10,7 +10,7 @@ const CreateMessageService = async ({
|
|||||||
messageData,
|
messageData,
|
||||||
ticketId
|
ticketId
|
||||||
}: Request): Promise<Message> => {
|
}: Request): Promise<Message> => {
|
||||||
const ticket = await FindTicketService({ where: { id: +ticketId } });
|
const ticket = await ShowTicketService(ticketId);
|
||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
throw new Error("No ticket found with this ID");
|
throw new Error("No ticket found with this ID");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { where, fn, col } from "sequelize";
|
import { where, fn, col } from "sequelize";
|
||||||
import Message from "../../models/Message";
|
import Message from "../../models/Message";
|
||||||
import Ticket from "../../models/Ticket";
|
import Ticket from "../../models/Ticket";
|
||||||
import FindTicketService from "../TicketServices/FindTicketService";
|
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
ticketId: string;
|
ticketId: string;
|
||||||
@@ -30,7 +30,7 @@ const ListMessagesService = async ({
|
|||||||
ticketId
|
ticketId
|
||||||
};
|
};
|
||||||
|
|
||||||
const ticket = await FindTicketService({ where: { id: +ticketId } });
|
const ticket = await ShowTicketService(ticketId);
|
||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
throw new Error("No ticket found with this ID");
|
throw new Error("No ticket found with this ID");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
import GetDefaultWhatsapp from "../../helpers/GetDefaultWhatsapp";
|
import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp";
|
||||||
import Ticket from "../../models/Ticket";
|
import Ticket from "../../models/Ticket";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
@@ -11,7 +11,7 @@ const CreateTicketService = async ({
|
|||||||
contactId,
|
contactId,
|
||||||
status
|
status
|
||||||
}: Request): Promise<Ticket> => {
|
}: Request): Promise<Ticket> => {
|
||||||
const defaultWhatsapp = await GetDefaultWhatsapp();
|
const defaultWhatsapp = await GetDefaultWhatsApp();
|
||||||
|
|
||||||
if (!defaultWhatsapp) {
|
if (!defaultWhatsapp) {
|
||||||
throw new AppError("No default WhatsApp found. Check Connection page.");
|
throw new AppError("No default WhatsApp found. Check Connection page.");
|
||||||
|
|||||||
@@ -3,23 +3,8 @@ import AppError from "../../errors/AppError";
|
|||||||
import Contact from "../../models/Contact";
|
import Contact from "../../models/Contact";
|
||||||
import User from "../../models/User";
|
import User from "../../models/User";
|
||||||
|
|
||||||
interface WhereParams {
|
const ShowTicketService = async (id: string | number): Promise<Ticket> => {
|
||||||
id?: number;
|
const ticket = await Ticket.findByPk(id, {
|
||||||
status?: string;
|
|
||||||
userId?: number;
|
|
||||||
contactId?: number;
|
|
||||||
whatsappId?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Request {
|
|
||||||
where?: WhereParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FindTicketService = async ({ where }: Request): Promise<Ticket> => {
|
|
||||||
const whereCondition = { ...where };
|
|
||||||
|
|
||||||
const ticket = await Ticket.findOne({
|
|
||||||
where: whereCondition,
|
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Contact,
|
model: Contact,
|
||||||
@@ -42,4 +27,4 @@ const FindTicketService = async ({ where }: Request): Promise<Ticket> => {
|
|||||||
return ticket;
|
return ticket;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FindTicketService;
|
export default ShowTicketService;
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import User from "../../models/User";
|
import User from "../../models/User";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
|
|
||||||
const FindUserService = async (id: string): Promise<User | undefined> => {
|
const ShowUserService = async (
|
||||||
const user = await User.findOne({
|
id: string | number
|
||||||
where: { id },
|
): Promise<User | undefined> => {
|
||||||
|
const user = await User.findByPk(id, {
|
||||||
attributes: ["name", "id", "email", "profile"]
|
attributes: ["name", "id", "email", "profile"]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -14,4 +15,4 @@ const FindUserService = async (id: string): Promise<User | undefined> => {
|
|||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FindUserService;
|
export default ShowUserService;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
|
|
||||||
const FindWhatsAppService = async (
|
const ShowWhatsAppService = async (
|
||||||
id: string | number
|
id: string | number
|
||||||
): Promise<Whatsapp | undefined> => {
|
): Promise<Whatsapp | undefined> => {
|
||||||
const whatsapp = await Whatsapp.findByPk(id);
|
const whatsapp = await Whatsapp.findByPk(id);
|
||||||
@@ -13,4 +13,4 @@ const FindWhatsAppService = async (
|
|||||||
return whatsapp;
|
return whatsapp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FindWhatsAppService;
|
export default ShowWhatsAppService;
|
||||||
@@ -13,6 +13,7 @@ const QrcodeModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchSession = async () => {
|
const fetchSession = async () => {
|
||||||
if (!whatsAppId) return;
|
if (!whatsAppId) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get(`/whatsapp/${whatsAppId}`);
|
const { data } = await api.get(`/whatsapp/${whatsAppId}`);
|
||||||
setQrCode(data.qrcode);
|
setQrCode(data.qrcode);
|
||||||
|
|||||||
Reference in New Issue
Block a user