mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
changed find to show services
This commit is contained in:
@@ -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