all routes changed to typescript

This commit is contained in:
canove
2020-09-19 09:40:24 -03:00
parent 99fa2cea61
commit 0ea4dbea51
11 changed files with 469 additions and 270 deletions

View File

@@ -0,0 +1,47 @@
import * as Yup from "yup";
import AppError from "../../errors/AppError";
import Whatsapp from "../../models/Whatsapp";
interface Request {
name: string;
status?: string;
}
const CreateWhatsAppService = async ({
name,
status = "INITIALIZING"
}: Request): Promise<Whatsapp> => {
// const schema = Yup.object().shape({
// name: Yup.string().required().min(2),
// default: Yup.boolean()
// .required()
// .test(
// "Check-default",
// "Only one default whatsapp is permited",
// async value => {
// if (value === true) {
// const whatsappFound = await Whatsapp.findOne({
// where: { default: true }
// });
// return !Boolean(whatsappFound);
// } else return true;
// }
// )
// });
// try {
// await schema.validate({ name, status });
// } catch (err) {
// throw new AppError(err.message);
// }
const whatsapp = await Whatsapp.create({
name,
status
});
return whatsapp;
};
export default CreateWhatsAppService;

View File

@@ -0,0 +1,13 @@
import Whatsapp from "../../models/Whatsapp";
interface Response {
whatsapps: Whatsapp[];
}
const ListWhatsAppsService = async (): Promise<Response> => {
const whatsapps = await Whatsapp.findAll();
return { whatsapps };
};
export default ListWhatsAppsService;