mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
feat: Route to fetch all groups that the connection is part of
This commit is contained in:
parent
75b8bcb853
commit
ea8d6bf6c8
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
* Improved fetch instances endpoint, now it also fetch other instances even if they are not connected
|
* Improved fetch instances endpoint, now it also fetch other instances even if they are not connected
|
||||||
* Added conversion of audios for sending recorded audio, now it is possible to send mp3 audios and not just ogg
|
* Added conversion of audios for sending recorded audio, now it is possible to send mp3 audios and not just ogg
|
||||||
|
* Route to fetch all groups that the connection is part of
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -65,6 +65,37 @@ export abstract class RouterBroker {
|
|||||||
return await execute(instance, ref);
|
return await execute(instance, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async groupNoValidate<T>(args: DataValidate<T>) {
|
||||||
|
const { request, ClassRef, schema, execute } = args;
|
||||||
|
|
||||||
|
const instance = request.params as unknown as InstanceDto;
|
||||||
|
|
||||||
|
const ref = new ClassRef();
|
||||||
|
|
||||||
|
Object.assign(ref, request.body);
|
||||||
|
|
||||||
|
const v = validate(ref, schema);
|
||||||
|
|
||||||
|
if (!v.valid) {
|
||||||
|
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||||
|
let message: string;
|
||||||
|
if (schema['description']) {
|
||||||
|
message = schema['description'];
|
||||||
|
} else {
|
||||||
|
message = stack.replace('instance.', '');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
property: property.replace('instance.', ''),
|
||||||
|
message,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
logger.error([...message]);
|
||||||
|
throw new BadRequestException(...message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await execute(instance, ref);
|
||||||
|
}
|
||||||
|
|
||||||
public async groupValidate<T>(args: DataValidate<T>) {
|
public async groupValidate<T>(args: DataValidate<T>) {
|
||||||
const { request, ClassRef, schema, execute } = args;
|
const { request, ClassRef, schema, execute } = args;
|
||||||
|
|
||||||
|
@ -27,6 +27,10 @@ export class GroupController {
|
|||||||
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
|
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async fetchAllGroups(instance: InstanceDto) {
|
||||||
|
return await this.waMonitor.waInstances[instance.instanceName].fetchAllGroups();
|
||||||
|
}
|
||||||
|
|
||||||
public async inviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
public async inviteCode(instance: InstanceDto, groupJid: GroupJid) {
|
||||||
return await this.waMonitor.waInstances[instance.instanceName].inviteCode(groupJid);
|
return await this.waMonitor.waInstances[instance.instanceName].inviteCode(groupJid);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,16 @@ export class GroupRouter extends RouterBroker {
|
|||||||
|
|
||||||
res.status(HttpStatus.OK).json(response);
|
res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
|
.get(this.routerPath('fetchAllGroups'), ...guards, async (req, res) => {
|
||||||
|
const response = await this.groupNoValidate<GroupJid>({
|
||||||
|
request: req,
|
||||||
|
schema: {},
|
||||||
|
ClassRef: GroupJid,
|
||||||
|
execute: (instance) => groupController.fetchAllGroups(instance),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json(response);
|
||||||
|
})
|
||||||
.get(this.routerPath('participants'), ...guards, async (req, res) => {
|
.get(this.routerPath('participants'), ...guards, async (req, res) => {
|
||||||
const response = await this.groupValidate<GroupJid>({
|
const response = await this.groupValidate<GroupJid>({
|
||||||
request: req,
|
request: req,
|
||||||
|
@ -1610,6 +1610,14 @@ export class WAStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async fetchAllGroups() {
|
||||||
|
try {
|
||||||
|
return await this.client.groupFetchAllParticipating();
|
||||||
|
} catch (error) {
|
||||||
|
throw new NotFoundException('Error fetching group', error.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async inviteCode(id: GroupJid) {
|
public async inviteCode(id: GroupJid) {
|
||||||
try {
|
try {
|
||||||
const code = await this.client.groupInviteCode(id.groupJid);
|
const code = await this.client.groupInviteCode(id.groupJid);
|
||||||
|
Loading…
Reference in New Issue
Block a user