|
| 1 | +/** |
| 2 | + * ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| 3 | + * β @author jrCleber β |
| 4 | + * β @filename message.model.ts β |
| 5 | + * β Developed by: Cleber Wilson β |
| 6 | + * β Creation date: Dez 07, 2023 β |
| 7 | + * β Contact: contato@codechat.dev β |
| 8 | + * ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ |
| 9 | + * β @copyright Β© Cleber Wilson 2022. All rights reserved. β |
| 10 | + * β Licensed under the Apache License, Version 2.0 β |
| 11 | + * β β |
| 12 | + * β @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β |
| 13 | + * β β |
| 14 | + * β You may not use this file except in compliance with the License. β |
| 15 | + * β You may obtain a copy of the License at β |
| 16 | + * β β |
| 17 | + * β http://www.apache.org/licenses/LICENSE-2.0 β |
| 18 | + * β β |
| 19 | + * β Unless required by applicable law or agreed to in writing, software β |
| 20 | + * β distributed under the License is distributed on an "AS IS" BASIS, β |
| 21 | + * β WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β |
| 22 | + * β β |
| 23 | + * β See the License for the specific language governing permissions and β |
| 24 | + * β limitations under the License. β |
| 25 | + * β β |
| 26 | + * β @class S3Router β β |
| 27 | + * ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ |
| 28 | + * β @important β |
| 29 | + * β For any future changes to the code in this file, it is recommended to β |
| 30 | + * β contain, together with the modification, the information of the developer β |
| 31 | + * β who changed it and the date of modification. β |
| 32 | + * ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| 33 | + */ |
| 34 | + |
| 35 | +import { RequestHandler, Router } from 'express'; |
| 36 | +import { TypebotDto, TypebotUpdateSessionDto } from './dto/typebot.dto'; |
| 37 | +import { |
| 38 | + typebotFindSessionSchema, |
| 39 | + typebotSchema, |
| 40 | + typebotUpdateSchema, |
| 41 | + typebotUpdateSessionSchema, |
| 42 | +} from '../../validate/validate.schema'; |
| 43 | +import { HttpStatus } from '../../app.module'; |
| 44 | +import { TypebotService } from './typebot.service'; |
| 45 | +import { dataValidate, routerPath } from '../../validate/router.validate'; |
| 46 | + |
| 47 | +export function TypebotRouter( |
| 48 | + typebotService: TypebotService, |
| 49 | + ...guards: RequestHandler[] |
| 50 | +) { |
| 51 | + const router = Router() |
| 52 | + .post(routerPath('create'), ...guards, async (req, res) => { |
| 53 | + const response = await dataValidate<TypebotDto>({ |
| 54 | + request: req, |
| 55 | + schema: typebotSchema, |
| 56 | + execute: (instance, data) => |
| 57 | + typebotService.createBotInstance(instance.instanceName, data), |
| 58 | + }); |
| 59 | + |
| 60 | + return res.status(HttpStatus.CREATED).json(response); |
| 61 | + }) |
| 62 | + .put(routerPath('update'), ...guards, async (req, res) => { |
| 63 | + const response = await dataValidate<TypebotDto>({ |
| 64 | + request: req, |
| 65 | + schema: typebotUpdateSchema, |
| 66 | + execute: (instance, data) => |
| 67 | + typebotService.updateBotInstance(instance.instanceName, data), |
| 68 | + }); |
| 69 | + |
| 70 | + return res.status(HttpStatus.OK).json(response); |
| 71 | + }) |
| 72 | + .get(routerPath('find'), ...guards, async (req, res) => { |
| 73 | + const response = await dataValidate({ |
| 74 | + request: req, |
| 75 | + schema: null, |
| 76 | + execute: (instance) => typebotService.getBotInstance(instance.instanceName), |
| 77 | + }); |
| 78 | + |
| 79 | + return res.status(HttpStatus.OK).json(response?.['Typebot']); |
| 80 | + }) |
| 81 | + .delete(routerPath('delete'), ...guards, async (req, res) => { |
| 82 | + const response = await dataValidate({ |
| 83 | + request: req, |
| 84 | + schema: null, |
| 85 | + execute: (instance) => typebotService.deleteBotInstance(instance.instanceName), |
| 86 | + }); |
| 87 | + |
| 88 | + return res.status(HttpStatus.OK).json(response?.['Typebot']); |
| 89 | + }) |
| 90 | + .post(routerPath('sessions/find'), ...guards, async (req, res) => { |
| 91 | + const response = await dataValidate<TypebotUpdateSessionDto>({ |
| 92 | + request: req, |
| 93 | + schema: typebotFindSessionSchema, |
| 94 | + execute: (instance, data) => |
| 95 | + typebotService.findSessionsRegistered(instance.instanceName, data), |
| 96 | + }); |
| 97 | + |
| 98 | + return res.status(HttpStatus.OK).json(response); |
| 99 | + }) |
| 100 | + .patch(routerPath('sessions/update'), ...guards, async (req, res) => { |
| 101 | + const response = await dataValidate<TypebotUpdateSessionDto>({ |
| 102 | + request: req, |
| 103 | + schema: typebotUpdateSessionSchema, |
| 104 | + execute: (instance, data) => |
| 105 | + typebotService.updateSessionRegistered(instance.instanceName, data), |
| 106 | + }); |
| 107 | + |
| 108 | + return res.status(HttpStatus.OK).json(response); |
| 109 | + }); |
| 110 | + |
| 111 | + return router; |
| 112 | +} |
0 commit comments