mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
changed ticket creation and list to typescript
This commit is contained in:
30
backend/src/services/WhatsappService/FindWhatsAppService.ts
Normal file
30
backend/src/services/WhatsappService/FindWhatsAppService.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
interface WhereParams {
|
||||
id?: number;
|
||||
name?: string;
|
||||
isDefault?: boolean;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
where?: WhereParams;
|
||||
}
|
||||
|
||||
const FindWhatsAppService = async ({
|
||||
where
|
||||
}: Request): Promise<Whatsapp | undefined> => {
|
||||
const whereCondition = { ...where };
|
||||
|
||||
const whatsapp = await Whatsapp.findOne({
|
||||
where: whereCondition
|
||||
});
|
||||
|
||||
if (!whatsapp) {
|
||||
throw new AppError("No whatsapp found with this conditions.", 404);
|
||||
}
|
||||
|
||||
return whatsapp;
|
||||
};
|
||||
|
||||
export default FindWhatsAppService;
|
||||
@@ -1,18 +0,0 @@
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
const ShowWhatsAppService = async (
|
||||
id: string
|
||||
): Promise<Whatsapp | undefined> => {
|
||||
const whatsapp = await Whatsapp.findOne({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
if (!whatsapp) {
|
||||
throw new AppError("No whatsapp found with this ID.", 404);
|
||||
}
|
||||
|
||||
return whatsapp;
|
||||
};
|
||||
|
||||
export default ShowWhatsAppService;
|
||||
Reference in New Issue
Block a user