Skip to content

Commit

Permalink
refactor: update some variable names and api sdk function docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vplasencia committed Mar 30, 2024
1 parent e286bba commit 627c9f4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 61 deletions.
24 changes: 12 additions & 12 deletions apps/api/src/app/groups/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
groupIds: Array<string>,
apiKey: string
): Promise<void> {
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)
}
}
Expand All @@ -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<string>,
groupIds: Array<string>,
adminId: string
): Promise<void> {
for await (const groupId of groupsIds) {
for await (const groupId of groupIds) {
await this.removeGroup(groupId, adminId)
}
}
Expand Down Expand Up @@ -285,21 +285,21 @@ 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<string>,
groupIds: Array<string>,
dtos: Array<UpdateGroupDto>,
apiKey: string
): Promise<Array<Group>> {
const updatedGroups: Array<Group> = []

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)
Expand All @@ -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<string>,
groupIds: Array<string>,
dtos: Array<UpdateGroupDto>,
adminId: string
): Promise<Array<Group>> {
const updatedGroups: Array<Group> = []

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)
Expand Down
63 changes: 36 additions & 27 deletions libs/api-sdk/src/apiSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupResponse> {
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<GroupRequest>,
groupsData: Array<GroupRequest>,
apiKey: string
): Promise<Array<GroupResponse>> {
const groups = await createGroups(this._config, dtos, apiKey)
const groups = await createGroups(this._config, groupsData, apiKey)

return groups
}
Expand All @@ -120,53 +120,62 @@ 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<void> {
return removeGroup(this._config, groupId, apiKey)
}

/**
* 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<string>,
apiKey: string
): Promise<void> {
return removeGroups(this._config, groupsIds, apiKey)
async removeGroups(groupIds: Array<string>, apiKey: string): Promise<void> {
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<GroupResponse> {
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<string>,
dtos: Array<GroupUpdateRequest>,
groupIds: Array<string>,
groupsData: Array<GroupUpdateRequest>,
apiKey: string
): Promise<Array<GroupResponse>> {
const groups = await updateGroups(this._config, groupsIds, dtos, apiKey)
const groups = await updateGroups(
this._config,
groupIds,
groupsData,
apiKey
)

return groups
}
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
36 changes: 18 additions & 18 deletions libs/api-sdk/src/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ export async function getGroups(config: object): Promise<GroupResponse[]> {

/**
* 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<GroupResponse> {
const newConfig: any = {
method: "post",
data: [dto],
data: [groupData],
...config
}

Expand All @@ -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<GroupRequest>,
groupsData: Array<GroupRequest>,
apiKey: string
): Promise<Array<GroupResponse>> {
const newConfig: any = {
method: "post",
data: {
dtos
groupsData
},
...config
}
Expand Down Expand Up @@ -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<string>,
groupIds: Array<string>,
apiKey: string
): Promise<void> {
const newConfig: any = {
method: "delete",
data: {
groupsIds,
groupIds,
apiKey
},
...config
Expand All @@ -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<GroupResponse> {
const requestUrl = `${url}/${groupId}`
Expand All @@ -140,7 +140,7 @@ export async function updateGroup(
method: "put",
data: {
groupId,
dto,
groupData,
apiKey
},
...config
Expand All @@ -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<string>,
dtos: Array<GroupUpdateRequest>,
groupIds: Array<string>,
groupsData: Array<GroupUpdateRequest>,
apiKey: string
): Promise<Array<GroupResponse>> {
const newConfig: any = {
method: "put",
data: {
groupsIds,
dtos,
groupIds,
groupsData,
apiKey
},
...config
Expand Down
8 changes: 4 additions & 4 deletions libs/api-sdk/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe("Bandada API SDK", () => {
})
describe("#removeGroups", () => {
it("Should create a group", async () => {
const groupsIds = [
const groupIds = [
"10402173435763029700781503965100",
"20402173435763029700781503965200"
]
Expand All @@ -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()
})
})
Expand Down Expand Up @@ -259,7 +259,7 @@ describe("Bandada API SDK", () => {
})
describe("#updateGroups", () => {
it("Should update some groups", async () => {
const groupsIds = [
const groupIds = [
"10402173435763029700781503965100",
"20402173435763029700781503965200"
]
Expand Down Expand Up @@ -306,7 +306,7 @@ describe("Bandada API SDK", () => {

apiSdk = new ApiSdk(SupportedUrl.DEV)
const groups: Array<GroupResponse> = await apiSdk.updateGroups(
groupsIds,
groupIds,
updatedGroups,
apiKey
)
Expand Down

0 comments on commit 627c9f4

Please sign in to comment.