From 627c9f4e811928a01d06db4e14f7e2c08456bee4 Mon Sep 17 00:00:00 2001 From: Vivian Plasencia Date: Sat, 30 Mar 2024 13:07:08 +0100 Subject: [PATCH] refactor: update some variable names and api sdk function docs --- apps/api/src/app/groups/groups.service.ts | 24 ++++----- libs/api-sdk/src/apiSdk.ts | 63 +++++++++++++---------- libs/api-sdk/src/groups.ts | 36 ++++++------- libs/api-sdk/src/index.test.ts | 8 +-- 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/apps/api/src/app/groups/groups.service.ts b/apps/api/src/app/groups/groups.service.ts index aedd530c..4e3c06b9 100644 --- a/apps/api/src/app/groups/groups.service.ts +++ b/apps/api/src/app/groups/groups.service.ts @@ -203,16 +203,16 @@ export class GroupsService { /** * Remove groups using API Key. - * @param groupsIds Groups identifiers. + * @param groupIds Groups identifiers. * @param apiKey the api key. */ async removeGroupsWithAPIKey( - groupsIds: Array, + groupIds: Array, apiKey: string ): Promise { const admin = await getAndCheckAdmin(this.adminsService, apiKey) - for await (const groupId of groupsIds) { + for await (const groupId of groupIds) { await this.removeGroup(groupId, admin.id) } } @@ -228,14 +228,14 @@ export class GroupsService { /** * Remove groups manually without using API Key. - * @param groupsIds Groups identifiers. + * @param groupIds Groups identifiers. * @param adminId Admin id. */ async removeGroupsManually( - groupsIds: Array, + groupIds: Array, adminId: string ): Promise { - for await (const groupId of groupsIds) { + for await (const groupId of groupIds) { await this.removeGroup(groupId, adminId) } } @@ -285,13 +285,13 @@ export class GroupsService { /** * Update groups using API Key. - * @param groupsIds Groups ids. + * @param groupIds Group ids. * @param dtos External parameters used to update groups. * @param apiKey the API Key. * @returns Updated group. */ async updateGroupsWithApiKey( - groupsIds: Array, + groupIds: Array, dtos: Array, apiKey: string ): Promise> { @@ -299,7 +299,7 @@ export class GroupsService { const admin = await getAndCheckAdmin(this.adminsService, apiKey) - for await (const [index, groupId] of groupsIds.entries()) { + for await (const [index, groupId] of groupIds.entries()) { const dto = dtos[index] const group = await this.updateGroup(groupId, dto, admin.id) updatedGroups.push(group) @@ -325,19 +325,19 @@ export class GroupsService { /** * Update groups manually without using API Key. - * @param groupsIds Groups ids. + * @param groupIds Group ids. * @param dtos External parameters used to update groups. * @param adminId Group admin id. * @returns Updated groups. */ async updateGroupsManually( - groupsIds: Array, + groupIds: Array, dtos: Array, adminId: string ): Promise> { const updatedGroups: Array = [] - for await (const [index, groupId] of groupsIds.entries()) { + for await (const [index, groupId] of groupIds.entries()) { const dto = dtos[index] const group = await this.updateGroup(groupId, dto, adminId) updatedGroups.push(group) diff --git a/libs/api-sdk/src/apiSdk.ts b/libs/api-sdk/src/apiSdk.ts index a6e4f1fe..ecd6e55a 100644 --- a/libs/api-sdk/src/apiSdk.ts +++ b/libs/api-sdk/src/apiSdk.ts @@ -88,30 +88,30 @@ export default class ApiSdk { /** * Creates a group using the API key. - * @param dto The data of the group. + * @param groupData Data to create the group. * @param apiKey The API key of the admin of the group. * @returns The created group. */ async createGroup( - dto: GroupRequest, + groupData: GroupRequest, apiKey: string ): Promise { - const group = await createGroup(this._config, dto, apiKey) + const group = await createGroup(this._config, groupData, apiKey) return group } /** * Creates one or more groups using the API key. - * @param dtos The data of one or more groups. - * @param apiKey The API key of the admin of the group. + * @param groupsData Data to create the groups. + * @param apiKey The API key of the admin of the groups. * @returns The created groups. */ async createGroups( - dtos: Array, + groupsData: Array, apiKey: string ): Promise> { - const groups = await createGroups(this._config, dtos, apiKey) + const groups = await createGroups(this._config, groupsData, apiKey) return groups } @@ -120,6 +120,7 @@ export default class ApiSdk { * Removes a group using the API key. * @param groupId The group id. * @param apiKey The API key of the admin of the group. + * @returns undefined. */ async removeGroup(groupId: string, apiKey: string): Promise { return removeGroup(this._config, groupId, apiKey) @@ -127,46 +128,54 @@ export default class ApiSdk { /** * Removes one or more group using the API key. - * @param groupsIds The groups ids. - * @param apiKey The API key of the admin of the group. + * @param groupIds The group ids. + * @param apiKey The API key of the admin of the groups. + * @returns undefined. */ - async removeGroups( - groupsIds: Array, - apiKey: string - ): Promise { - return removeGroups(this._config, groupsIds, apiKey) + async removeGroups(groupIds: Array, apiKey: string): Promise { + return removeGroups(this._config, groupIds, apiKey) } /** * Update a specific group using the API key. * @param groupId The group id. - * @param dto The data to update the group. + * @param groupData Data to update the group. * @param apiKey The API key of the admin of the group. * @returns The updated group. */ async updateGroup( groupId: string, - dto: GroupUpdateRequest, + groupData: GroupUpdateRequest, apiKey: string ): Promise { - const group = await updateGroup(this._config, groupId, dto, apiKey) + const group = await updateGroup( + this._config, + groupId, + groupData, + apiKey + ) return group } /** * Updats one or more groups using the API key. - * @param groupsIds The groups ids. - * @param dtos The data to update the groups. - * @param apiKey The API key of the admin of the group. + * @param groupIds The group ids. + * @param groupsData Data to update the groups. + * @param apiKey The API key of the admin of the groups. * @returns The updated groups. */ async updateGroups( - groupsIds: Array, - dtos: Array, + groupIds: Array, + groupsData: Array, apiKey: string ): Promise> { - const groups = await updateGroups(this._config, groupsIds, dtos, apiKey) + const groups = await updateGroups( + this._config, + groupIds, + groupsData, + apiKey + ) return groups } @@ -217,7 +226,7 @@ export default class ApiSdk { * Adds a member to a group using an API Key. * @param groupId Group id. * @param memberId Member id. - * @param apiKey API Key. + * @param apiKey API Key of the admin of the group. * @returns undefined. */ async addMemberByApiKey( @@ -232,7 +241,7 @@ export default class ApiSdk { * Adds several members to a group using an API Key. * @param groupId Group id. * @param memberIds Member ids. - * @param apiKey API Key. + * @param apiKey API Key of the admin of the group. * @returns undefined. */ async addMembersByApiKey( @@ -262,7 +271,7 @@ export default class ApiSdk { * Removes a member from a group using an API Key. * @param groupId Group id. * @param memberId Member id. - * @param apiKey API Key. + * @param apiKey API Key of the admin of the group. * @returns undefined. */ async removeMemberByApiKey( @@ -277,7 +286,7 @@ export default class ApiSdk { * Removes multiple members from a group using an API Key. * @param groupId Group id. * @param memberIds Member ids. - * @param apiKey API Key. + * @param apiKey API Key of the admin of the group. * @returns undefined. */ async removeMembersByApiKey( diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index e2bfe9d6..73cfdf78 100644 --- a/libs/api-sdk/src/groups.ts +++ b/libs/api-sdk/src/groups.ts @@ -20,18 +20,18 @@ export async function getGroups(config: object): Promise { /** * Creates a group with the provided details. - * @param dto Object containing the details for the group to be created. + * @param groupData Data to create the group. * @param apiKey API Key of the admin. * @returns The created group. */ export async function createGroup( config: object, - dto: GroupRequest, + groupData: GroupRequest, apiKey: string ): Promise { const newConfig: any = { method: "post", - data: [dto], + data: [groupData], ...config } @@ -44,19 +44,19 @@ export async function createGroup( /** * Creates one or more groups with the provided details. - * @param dtos Array of objects containing the details for the groups to be created. + * @param groupsData Data to create the groups. * @param apiKey API Key of the admin. * @returns Array of the created groups. */ export async function createGroups( config: object, - dtos: Array, + groupsData: Array, apiKey: string ): Promise> { const newConfig: any = { method: "post", data: { - dtos + groupsData }, ...config } @@ -97,18 +97,18 @@ export async function removeGroup( /** * Removes one or more groups. - * @param groupsIds The groups ids. + * @param groupIds The group ids. * @param apiKey API Key of the admin. */ export async function removeGroups( config: object, - groupsIds: Array, + groupIds: Array, apiKey: string ): Promise { const newConfig: any = { method: "delete", data: { - groupsIds, + groupIds, apiKey }, ...config @@ -124,14 +124,14 @@ export async function removeGroups( /** * Updates the group. * @param groupId The group id. - * @param dto The data to update for the group. + * @param groupData Data to update the group. * @param apiKey API Key of the admin. * @return The updated group. */ export async function updateGroup( config: object, groupId: string, - dto: GroupUpdateRequest, + groupData: GroupUpdateRequest, apiKey: string ): Promise { const requestUrl = `${url}/${groupId}` @@ -140,7 +140,7 @@ export async function updateGroup( method: "put", data: { groupId, - dto, + groupData, apiKey }, ...config @@ -155,22 +155,22 @@ export async function updateGroup( /** * Updates the groups. - * @param groupsIds The groups ids. - * @param dtos The data to update for the groups. + * @param groupIds The group ids. + * @param groupsData Data to update the groups. * @param apiKey API Key of the admin. * @return The updated groups. */ export async function updateGroups( config: object, - groupsIds: Array, - dtos: Array, + groupIds: Array, + groupsData: Array, apiKey: string ): Promise> { const newConfig: any = { method: "put", data: { - groupsIds, - dtos, + groupIds, + groupsData, apiKey }, ...config diff --git a/libs/api-sdk/src/index.test.ts b/libs/api-sdk/src/index.test.ts index 7375ca29..b64ae518 100644 --- a/libs/api-sdk/src/index.test.ts +++ b/libs/api-sdk/src/index.test.ts @@ -206,7 +206,7 @@ describe("Bandada API SDK", () => { }) describe("#removeGroups", () => { it("Should create a group", async () => { - const groupsIds = [ + const groupIds = [ "10402173435763029700781503965100", "20402173435763029700781503965200" ] @@ -215,7 +215,7 @@ describe("Bandada API SDK", () => { requestMocked.mockImplementationOnce(() => Promise.resolve()) apiSdk = new ApiSdk(SupportedUrl.DEV) - const res = await apiSdk.removeGroups(groupsIds, apiKey) + const res = await apiSdk.removeGroups(groupIds, apiKey) expect(res).toBeUndefined() }) }) @@ -259,7 +259,7 @@ describe("Bandada API SDK", () => { }) describe("#updateGroups", () => { it("Should update some groups", async () => { - const groupsIds = [ + const groupIds = [ "10402173435763029700781503965100", "20402173435763029700781503965200" ] @@ -306,7 +306,7 @@ describe("Bandada API SDK", () => { apiSdk = new ApiSdk(SupportedUrl.DEV) const groups: Array = await apiSdk.updateGroups( - groupsIds, + groupIds, updatedGroups, apiKey )