Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support group membership request #2087

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions src/controller/groupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,182 @@ export async function demoteParticipant(req: Request, res: Response) {
}
}

export async function approveGroupMembershipRequest(req: Request, res: Response) {
/**
#swagger.tags = ["Group"]
#swagger.autoBody=false
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters["session"] = {
schema: 'NERDWHATS_AMERICA'
}
#swagger.requestBody = {
required: true,
"@content": {
"application/json": {
schema: {
type: "object",
properties: {
"groupId": { type: "string" },
"phone": { type: "string" }
},
required: ["groupId", "phone"]
},
examples: {
"Default": {
value: {
"groupId": "<groupId>",
"phone": "5521999999999"
}
}
}
}
}
}
*/
const { groupId, phone } = req.body;

try {
const arrayGroups: any = [];
for (const group of groupToArray(groupId)) {
await req.client.approveGroupMembershipRequest(group, contactToArray(phone));
arrayGroups.push(group);
}

return res.status(201).json({
status: 'success',
response: {
message: 'Group membership Request(s) approve successfully',
participants: phone,
groups: arrayGroups,
},
});
} catch (e) {
req.logger.error(e);
return res.status(500).json({
status: 'error',
message: "Error approve membership request's",
error: e,
});
}
}

export async function rejectGroupMembershipRequest(req: Request, res: Response) {
/**
#swagger.tags = ["Group"]
#swagger.autoBody=false
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters["session"] = {
schema: 'NERDWHATS_AMERICA'
}
#swagger.requestBody = {
required: true,
"@content": {
"application/json": {
schema: {
type: "object",
properties: {
"groupId": { type: "string" },
"phone": { type: "string" }
},
required: ["groupId", "phone"]
},
examples: {
"Default": {
value: {
"groupId": "<groupId>",
"phone": "5521999999999"
}
}
}
}
}
}
*/
const { groupId, phone } = req.body;

try {
const arrayGroups: any = [];
for (const group of groupToArray(groupId)) {
await req.client.rejectGroupMembershipRequest(group, contactToArray(phone));
arrayGroups.push(group);
}

return res.status(201).json({
status: 'success',
response: {
message: 'Group membership Request(s) reject successfully',
participants: phone,
groups: arrayGroups,
},
});
} catch (e) {
req.logger.error(e);
return res.status(500).json({
status: 'error',
message: "Error reject membership request's",
error: e,
});
}
}

export async function getGroupMembershipRequests(req: Request, res: Response) {
/**
#swagger.tags = ["Group"]
#swagger.autoBody=false
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters["session"] = {
schema: 'NERDWHATS_AMERICA'
}
#swagger.requestBody = {
required: true,
"@content": {
"application/json": {
schema: {
type: "object",
properties: {
"groupId": { type: "string" }
},
required: ["groupId"]
},
examples: {
"Default": {
value: {
"groupId": "<groupId>"
}
}
}
}
}
}
*/
const { groupId } = req.params;

try {
let response = {};
const arrayGroups: any = [];

for (const group of groupToArray(groupId)) {
response = await req.client.getGroupMembershipRequests(group);
arrayGroups.push(response);
}

return res.status(200).json({ status: 'success', response: arrayGroups });
} catch (e) {
req.logger.error(e);
return res.status(500).json({
status: 'error',
message: 'Error retrieving group membership requests(s)',
error: e,
});
}
}

export async function getGroupAdmins(req: Request, res: Response) {
/**
#swagger.tags = ["Group"]
Expand Down
18 changes: 18 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ routes.post(
statusConnection,
GroupController.demoteParticipant
);
routes.get(
'/api/:session/group-membership-request/:groupId',
verifyToken,
statusConnection,
GroupController.getGroupMembershipRequests
);
routes.post(
'/api/:session/approve-group-membership-request',
verifyToken,
statusConnection,
GroupController.approveGroupMembershipRequest
);
routes.post(
'/api/:session/reject-group-membership-request',
verifyToken,
statusConnection,
GroupController.rejectGroupMembershipRequest
);
routes.post(
'/api/:session/group-info-from-invite-link',
verifyToken,
Expand Down