mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
all routes changed to typescript
This commit is contained in:
@@ -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;
|
||||
13
backend/src/services/WhatsappService/ListWhatsAppsService.ts
Normal file
13
backend/src/services/WhatsappService/ListWhatsAppsService.ts
Normal 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;
|
||||
Reference in New Issue
Block a user