changed ticket creation and list to typescript

This commit is contained in:
canove
2020-09-19 21:00:49 -03:00
parent 5dda3aabaf
commit 1d0bbda00d
16 changed files with 473 additions and 81 deletions

View 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;

View File

@@ -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;