mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +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 CreateContactService from "../services/ContactServices/CreateContactService";
|
||||
import FindContactService from "../services/ContactServices/FindContactService";
|
||||
import ShowContactService from "../services/ContactServices/ShowContactService";
|
||||
import UpdateContactService from "../services/ContactServices/UpdateContactService";
|
||||
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> => {
|
||||
const { contactId } = req.params;
|
||||
|
||||
const contact = await FindContactService(contactId);
|
||||
const contact = await ShowContactService(contactId);
|
||||
|
||||
return res.status(200).json(contact);
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import AppError from "../errors/AppError";
|
||||
import CreateUserService from "../services/UserServices/CreateUserService";
|
||||
import ListUsersService from "../services/UserServices/ListUsersService";
|
||||
import UpdateUserService from "../services/UserServices/UpdateUserService";
|
||||
import FindUserService from "../services/UserServices/FindUserService";
|
||||
import ShowUserService from "../services/UserServices/ShowUserService";
|
||||
import DeleteUserService from "../services/UserServices/DeleteUserService";
|
||||
|
||||
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> => {
|
||||
const { userId } = req.params;
|
||||
|
||||
const user = await FindUserService(userId);
|
||||
const user = await ShowUserService(userId);
|
||||
|
||||
return res.status(200).json(user);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Request, Response } from "express";
|
||||
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
||||
import DeleteWhatsAppService from "../services/WhatsappService/DeleteWhatsAppService";
|
||||
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 Yup from "yup";
|
||||
// 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> => {
|
||||
const { whatsappId } = req.params;
|
||||
|
||||
console.log(whatsappId);
|
||||
|
||||
const whatsapp = await FindWhatsAppService(whatsappId);
|
||||
const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||
|
||||
return res.status(200).json(whatsapp);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import AppError from "../errors/AppError";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
import FindWhatsAppService from "../services/WhatsappService/FindWhatsAppService";
|
||||
|
||||
const GetDefaultWhatsapp = async (): Promise<Whatsapp> => {
|
||||
const defaultWhatsapp = await FindWhatsAppService({
|
||||
const GetDefaultWhatsApp = async (): Promise<Whatsapp> => {
|
||||
const defaultWhatsapp = await Whatsapp.findOne({
|
||||
where: { isDefault: true }
|
||||
});
|
||||
|
||||
@@ -14,4 +13,4 @@ const GetDefaultWhatsapp = async (): Promise<Whatsapp> => {
|
||||
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 FindTicketService from "../TicketServices/FindTicketService";
|
||||
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||
|
||||
interface Request {
|
||||
ticketId: string;
|
||||
@@ -10,7 +10,7 @@ const CreateMessageService = async ({
|
||||
messageData,
|
||||
ticketId
|
||||
}: Request): Promise<Message> => {
|
||||
const ticket = await FindTicketService({ where: { id: +ticketId } });
|
||||
const ticket = await ShowTicketService(ticketId);
|
||||
|
||||
if (!ticket) {
|
||||
throw new Error("No ticket found with this ID");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { where, fn, col } from "sequelize";
|
||||
import Message from "../../models/Message";
|
||||
import Ticket from "../../models/Ticket";
|
||||
import FindTicketService from "../TicketServices/FindTicketService";
|
||||
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||
|
||||
interface Request {
|
||||
ticketId: string;
|
||||
@@ -30,7 +30,7 @@ const ListMessagesService = async ({
|
||||
ticketId
|
||||
};
|
||||
|
||||
const ticket = await FindTicketService({ where: { id: +ticketId } });
|
||||
const ticket = await ShowTicketService(ticketId);
|
||||
|
||||
if (!ticket) {
|
||||
throw new Error("No ticket found with this ID");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import AppError from "../../errors/AppError";
|
||||
import GetDefaultWhatsapp from "../../helpers/GetDefaultWhatsapp";
|
||||
import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp";
|
||||
import Ticket from "../../models/Ticket";
|
||||
|
||||
interface Request {
|
||||
@@ -11,7 +11,7 @@ const CreateTicketService = async ({
|
||||
contactId,
|
||||
status
|
||||
}: Request): Promise<Ticket> => {
|
||||
const defaultWhatsapp = await GetDefaultWhatsapp();
|
||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
||||
|
||||
if (!defaultWhatsapp) {
|
||||
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 User from "../../models/User";
|
||||
|
||||
interface WhereParams {
|
||||
id?: number;
|
||||
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,
|
||||
const ShowTicketService = async (id: string | number): Promise<Ticket> => {
|
||||
const ticket = await Ticket.findByPk(id, {
|
||||
include: [
|
||||
{
|
||||
model: Contact,
|
||||
@@ -42,4 +27,4 @@ const FindTicketService = async ({ where }: Request): Promise<Ticket> => {
|
||||
return ticket;
|
||||
};
|
||||
|
||||
export default FindTicketService;
|
||||
export default ShowTicketService;
|
||||
@@ -1,9 +1,10 @@
|
||||
import User from "../../models/User";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
const FindUserService = async (id: string): Promise<User | undefined> => {
|
||||
const user = await User.findOne({
|
||||
where: { id },
|
||||
const ShowUserService = async (
|
||||
id: string | number
|
||||
): Promise<User | undefined> => {
|
||||
const user = await User.findByPk(id, {
|
||||
attributes: ["name", "id", "email", "profile"]
|
||||
});
|
||||
|
||||
@@ -14,4 +15,4 @@ const FindUserService = async (id: string): Promise<User | undefined> => {
|
||||
return user;
|
||||
};
|
||||
|
||||
export default FindUserService;
|
||||
export default ShowUserService;
|
||||
@@ -1,7 +1,7 @@
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
const FindWhatsAppService = async (
|
||||
const ShowWhatsAppService = async (
|
||||
id: string | number
|
||||
): Promise<Whatsapp | undefined> => {
|
||||
const whatsapp = await Whatsapp.findByPk(id);
|
||||
@@ -13,4 +13,4 @@ const FindWhatsAppService = async (
|
||||
return whatsapp;
|
||||
};
|
||||
|
||||
export default FindWhatsAppService;
|
||||
export default ShowWhatsAppService;
|
||||
Reference in New Issue
Block a user