feat: Route to update group subject

This commit is contained in:
Davidson Gomes 2023-06-12 12:02:10 -03:00
parent 75b48aa8ac
commit a28bbce1f9
7 changed files with 62 additions and 5 deletions

View File

@ -7,6 +7,7 @@
* Route to fetch all groups that the connection is part of
* Route to fetch all privacy settings
* Route to update the privacy settings
* Route to update group subject
### Fixed

View File

@ -680,7 +680,7 @@ export const toggleEphemeralSchema: JSONSchema7 = {
...isNotEmpty('groupJid', 'expiration'),
};
export const updateGroupPicture: JSONSchema7 = {
export const updateGroupPictureSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
@ -691,6 +691,17 @@ export const updateGroupPicture: JSONSchema7 = {
...isNotEmpty('groupJid', 'image'),
};
export const updateGroupSubjectSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
subject: { type: 'string' },
},
required: ['groupJid', 'subject'],
...isNotEmpty('groupJid', 'subject'),
};
// Webhook Schema
export const webhookSchema: JSONSchema7 = {
$id: v4(),

View File

@ -3,6 +3,7 @@ import {
GroupInvite,
GroupJid,
GroupPictureDto,
GroupSubjectDto,
GroupToggleEphemeralDto,
GroupUpdateParticipantDto,
GroupUpdateSettingDto,
@ -23,6 +24,12 @@ export class GroupController {
);
}
public async updateGroupSubject(instance: InstanceDto, update: GroupSubjectDto) {
return await this.waMonitor.waInstances[instance.instanceName].updateGroupSubject(
update,
);
}
public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) {
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
}

View File

@ -1,4 +1,8 @@
import { WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from "@evolution/base";
import {
WAPrivacyOnlineValue,
WAPrivacyValue,
WAReadReceiptsValue,
} from '@evolution/base';
export class OnWhatsAppDto {
constructor(

View File

@ -9,6 +9,11 @@ export class GroupPictureDto {
image: string;
}
export class GroupSubjectDto {
groupJid: string;
subject: string;
}
export class GroupJid {
groupJid: string;
}

View File

@ -5,7 +5,8 @@ import {
updateParticipantsSchema,
updateSettingsSchema,
toggleEphemeralSchema,
updateGroupPicture,
updateGroupPictureSchema,
updateGroupSubjectSchema,
groupInviteSchema,
} from '../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router';
@ -14,6 +15,7 @@ import {
GroupInvite,
GroupJid,
GroupPictureDto,
GroupSubjectDto,
GroupUpdateParticipantDto,
GroupUpdateSettingDto,
GroupToggleEphemeralDto,
@ -35,10 +37,20 @@ export class GroupRouter extends RouterBroker {
res.status(HttpStatus.CREATED).json(response);
})
.put(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => {
const response = await this.groupValidate<GroupSubjectDto>({
request: req,
schema: updateGroupSubjectSchema,
ClassRef: GroupSubjectDto,
execute: (instance, data) => groupController.updateGroupSubject(instance, data),
});
res.status(HttpStatus.CREATED).json(response);
})
.put(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => {
const response = await this.groupValidate<GroupPictureDto>({
request: req,
schema: updateGroupPicture,
schema: updateGroupPictureSchema,
ClassRef: GroupPictureDto,
execute: (instance, data) => groupController.updateGroupPicture(instance, data),
});

View File

@ -100,6 +100,7 @@ import {
GroupUpdateParticipantDto,
GroupUpdateSettingDto,
GroupToggleEphemeralDto,
GroupSubjectDto,
} from '../dto/group.dto';
import { MessageUpQuery } from '../repository/messageUp.repository';
import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db';
@ -1631,7 +1632,23 @@ export class WAStartupService {
return { update: 'success' };
} catch (error) {
throw new InternalServerErrorException('Error creating group', error.toString());
throw new InternalServerErrorException(
'Error update group picture',
error.toString(),
);
}
}
public async updateGroupSubject(data: GroupSubjectDto) {
try {
await this.client.groupUpdateSubject(data.groupJid, data.subject);
return { update: 'success' };
} catch (error) {
throw new InternalServerErrorException(
'Error updating group subject',
error.toString(),
);
}
}