mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 20:02:20 -06:00
chore: Simplified payloads and endpoints
This commit is contained in:
@@ -55,7 +55,7 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('markMessageAsRead'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('markMessageAsRead'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<ReadMessageDto>({
|
||||
request: req,
|
||||
schema: readMessageSchema,
|
||||
@@ -65,7 +65,7 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('archiveChat'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('archiveChat'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<ArchiveChatDto>({
|
||||
request: req,
|
||||
schema: archiveChatSchema,
|
||||
@@ -75,7 +75,7 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('markChatUnread'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('markChatUnread'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<MarkChatUnreadDto>({
|
||||
request: req,
|
||||
schema: markChatUnreadSchema,
|
||||
@@ -105,16 +105,46 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.post(this.routerPath('fetchProfile'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<NumberDto>({
|
||||
.post(this.routerPath('getBase64FromMediaMessage'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<getBase64FromMediaMessageDto>({
|
||||
request: req,
|
||||
schema: profileSchema,
|
||||
ClassRef: NumberDto,
|
||||
execute: (instance, data) => chatController.fetchProfile(instance, data),
|
||||
schema: null,
|
||||
ClassRef: getBase64FromMediaMessageDto,
|
||||
execute: (instance, data) => chatController.getBase64FromMediaMessage(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('updateMessage'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<UpdateMessageDto>({
|
||||
request: req,
|
||||
schema: updateMessageSchema,
|
||||
ClassRef: UpdateMessageDto,
|
||||
execute: (instance, data) => chatController.updateMessage(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendPresence'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<null>({
|
||||
request: req,
|
||||
schema: presenceSchema,
|
||||
ClassRef: SendPresenceDto,
|
||||
execute: (instance, data) => chatController.sendPresence(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('updateBlockStatus'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<BlockUserDto>({
|
||||
request: req,
|
||||
schema: blockUserSchema,
|
||||
ClassRef: BlockUserDto,
|
||||
execute: (instance, data) => chatController.blockUser(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('findContacts'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<Query<Contact>>({
|
||||
request: req,
|
||||
@@ -125,16 +155,6 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.post(this.routerPath('getBase64FromMediaMessage'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<getBase64FromMediaMessageDto>({
|
||||
request: req,
|
||||
schema: null,
|
||||
ClassRef: getBase64FromMediaMessageDto,
|
||||
execute: (instance, data) => chatController.getBase64FromMediaMessage(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('findMessages'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<Query<Message>>({
|
||||
request: req,
|
||||
@@ -165,37 +185,7 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendPresence'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<null>({
|
||||
request: req,
|
||||
schema: presenceSchema,
|
||||
ClassRef: SendPresenceDto,
|
||||
execute: (instance, data) => chatController.sendPresence(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
// Profile routes
|
||||
.get(this.routerPath('fetchPrivacySettings'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: null,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => chatController.fetchPrivacySettings(instance),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('updatePrivacySettings'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<PrivacySettingDto>({
|
||||
request: req,
|
||||
schema: privacySettingsSchema,
|
||||
ClassRef: PrivacySettingDto,
|
||||
execute: (instance, data) => chatController.updatePrivacySettings(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<ProfilePictureDto>({
|
||||
request: req,
|
||||
@@ -206,6 +196,17 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.post(this.routerPath('fetchProfile'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<NumberDto>({
|
||||
request: req,
|
||||
schema: profileSchema,
|
||||
ClassRef: NumberDto,
|
||||
execute: (instance, data) => chatController.fetchProfile(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
|
||||
.post(this.routerPath('updateProfileName'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<ProfileNameDto>({
|
||||
request: req,
|
||||
@@ -246,22 +247,22 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateMessage'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<UpdateMessageDto>({
|
||||
.get(this.routerPath('fetchPrivacySettings'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: updateMessageSchema,
|
||||
ClassRef: UpdateMessageDto,
|
||||
execute: (instance, data) => chatController.updateMessage(instance, data),
|
||||
schema: null,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => chatController.fetchPrivacySettings(instance),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateBlockStatus'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<BlockUserDto>({
|
||||
.post(this.routerPath('updatePrivacySettings'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<PrivacySettingDto>({
|
||||
request: req,
|
||||
schema: blockUserSchema,
|
||||
ClassRef: BlockUserDto,
|
||||
execute: (instance, data) => chatController.blockUser(instance, data),
|
||||
schema: privacySettingsSchema,
|
||||
ClassRef: PrivacySettingDto,
|
||||
execute: (instance, data) => chatController.updatePrivacySettings(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
|
||||
@@ -46,7 +46,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupSubjectDto>({
|
||||
request: req,
|
||||
schema: updateGroupSubjectSchema,
|
||||
@@ -56,7 +56,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupPictureDto>({
|
||||
request: req,
|
||||
schema: updateGroupPictureSchema,
|
||||
@@ -66,7 +66,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateGroupDescription'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('updateGroupDescription'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupDescriptionDto>({
|
||||
request: req,
|
||||
schema: updateGroupDescriptionSchema,
|
||||
@@ -146,7 +146,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('revokeInviteCode'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('revokeInviteCode'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupJid>({
|
||||
request: req,
|
||||
schema: groupJidSchema,
|
||||
@@ -156,7 +156,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateParticipant'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('updateParticipant'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupUpdateParticipantDto>({
|
||||
request: req,
|
||||
schema: updateParticipantsSchema,
|
||||
@@ -166,7 +166,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('updateSetting'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('updateSetting'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupUpdateSettingDto>({
|
||||
request: req,
|
||||
schema: updateSettingsSchema,
|
||||
@@ -176,7 +176,7 @@ export class GroupRouter extends RouterBroker {
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.put(this.routerPath('toggleEphemeral'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('toggleEphemeral'), ...guards, async (req, res) => {
|
||||
const response = await this.groupValidate<GroupToggleEphemeralDto>({
|
||||
request: req,
|
||||
schema: toggleEphemeralSchema,
|
||||
|
||||
@@ -20,7 +20,7 @@ export class LabelRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.put(this.routerPath('handleLabel'), ...guards, async (req, res) => {
|
||||
.post(this.routerPath('handleLabel'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<HandleLabelDto>({
|
||||
request: req,
|
||||
schema: handleLabelSchema,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { RequestHandler, Router } from 'express';
|
||||
|
||||
import {
|
||||
audioMessageSchema,
|
||||
buttonMessageSchema,
|
||||
contactMessageSchema,
|
||||
listMessageSchema,
|
||||
locationMessageSchema,
|
||||
@@ -17,7 +16,6 @@ import {
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import {
|
||||
SendAudioDto,
|
||||
SendButtonDto,
|
||||
SendContactDto,
|
||||
SendListDto,
|
||||
SendLocationDto,
|
||||
@@ -36,6 +34,16 @@ export class MessageRouter extends RouterBroker {
|
||||
constructor(...guards: RequestHandler[]) {
|
||||
super();
|
||||
this.router
|
||||
.post(this.routerPath('sendTemplate'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendTemplateDto>({
|
||||
request: req,
|
||||
schema: templateMessageSchema,
|
||||
ClassRef: SendTemplateDto,
|
||||
execute: (instance, data) => sendMessageController.sendTemplate(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendText'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendTextDto>({
|
||||
request: req,
|
||||
@@ -66,22 +74,22 @@ export class MessageRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendTemplate'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendTemplateDto>({
|
||||
.post(this.routerPath('sendStatus'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendStatusDto>({
|
||||
request: req,
|
||||
schema: templateMessageSchema,
|
||||
ClassRef: SendTemplateDto,
|
||||
execute: (instance, data) => sendMessageController.sendTemplate(instance, data),
|
||||
schema: statusMessageSchema,
|
||||
ClassRef: SendStatusDto,
|
||||
execute: (instance, data) => sendMessageController.sendStatus(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendButtons'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendButtonDto>({
|
||||
.post(this.routerPath('sendSticker'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendStickerDto>({
|
||||
request: req,
|
||||
schema: buttonMessageSchema,
|
||||
ClassRef: SendButtonDto,
|
||||
execute: (instance, data) => sendMessageController.sendButtons(instance, data),
|
||||
schema: stickerMessageSchema,
|
||||
ClassRef: SendStickerDto,
|
||||
execute: (instance, data) => sendMessageController.sendSticker(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
@@ -96,16 +104,6 @@ export class MessageRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendList'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendListDto>({
|
||||
request: req,
|
||||
schema: listMessageSchema,
|
||||
ClassRef: SendListDto,
|
||||
execute: (instance, data) => sendMessageController.sendList(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendContact'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendContactDto>({
|
||||
request: req,
|
||||
@@ -136,26 +134,26 @@ export class MessageRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendStatus'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendStatusDto>({
|
||||
.post(this.routerPath('sendList'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendListDto>({
|
||||
request: req,
|
||||
schema: statusMessageSchema,
|
||||
ClassRef: SendStatusDto,
|
||||
execute: (instance, data) => sendMessageController.sendStatus(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('sendSticker'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<SendStickerDto>({
|
||||
request: req,
|
||||
schema: stickerMessageSchema,
|
||||
ClassRef: SendStickerDto,
|
||||
execute: (instance, data) => sendMessageController.sendSticker(instance, data),
|
||||
schema: listMessageSchema,
|
||||
ClassRef: SendListDto,
|
||||
execute: (instance, data) => sendMessageController.sendList(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
});
|
||||
// .post(this.routerPath('sendButtons'), ...guards, async (req, res) => {
|
||||
// const response = await this.dataValidate<SendButtonDto>({
|
||||
// request: req,
|
||||
// schema: buttonMessageSchema,
|
||||
// ClassRef: SendButtonDto,
|
||||
// execute: (instance, data) => sendMessageController.sendButtons(instance, data),
|
||||
// });
|
||||
|
||||
// return res.status(HttpStatus.CREATED).json(response);
|
||||
// })
|
||||
}
|
||||
|
||||
public readonly router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { instanceSchema, settingsSchema } from '../../validate/validate.schema';
|
||||
import { settingsSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { SettingsDto } from '../dto/settings.dto';
|
||||
@@ -24,7 +24,7 @@ export class SettingsRouter extends RouterBroker {
|
||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: instanceSchema,
|
||||
schema: null,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => settingsController.findSettings(instance),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user