Skip to content

Commit

Permalink
revert: docs: Add TypeScript typings to LmsApiService group methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonkeating committed Feb 19, 2025
1 parent d5fef09 commit 3b0ca28
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 78 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
},
"devDependencies": {
"@edx/browserslist-config": "1.5.0",
"@edx/typescript-config": "1.1.0",
"@faker-js/faker": "^7.6.0",
"@openedx/frontend-build": "14.2.2",
"@testing-library/dom": "9.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('useEnterpriseGroup', () => {
it('should fetch and return enterprise group', async () => {
jest.spyOn(LmsApiService, 'fetchEnterpriseGroup').mockResolvedValueOnce({
data: {
enterpriseCustomer: 'customer-uuid',
enterprise_customer: 'customer-uuid',
name: 'groupidy group',
uuid: 'group-uuid',
},
Expand All @@ -47,7 +47,7 @@ describe('useEnterpriseGroup', () => {
it('should return null if no group associations are listed', async () => {
jest.spyOn(LmsApiService, 'fetchEnterpriseGroup').mockResolvedValueOnce({
data: {
enterpriseCustomer: 'customer-uuid',
enterprise_customer: 'customer-uuid',
name: 'groupidy group',
uuid: 'group-uuid',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQuery } from '@tanstack/react-query';
import { camelCaseObject } from '@edx/frontend-platform/utils';
import isEmpty from 'lodash/isEmpty';

import { learnerCreditManagementQueryKeys } from '../constants';
Expand All @@ -15,7 +16,8 @@ const getEnterpriseGroup = async ({ subsidyAccessPolicy }) => {
return null;
}
const response = await LmsApiService.fetchEnterpriseGroup(subsidyAccessPolicy.groupAssociations[0]);
return response.data;
const enterpriseGroup = camelCaseObject(response.data);
return enterpriseGroup;
};

const useEnterpriseGroup = (subsidyAccessPolicy, { queryOptions } = {}) => useQuery({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { camelCaseObject } from '@edx/frontend-platform/utils';
import type { AxiosResponse } from 'axios';

import { configuration } from '../../config';
import generateFormattedStatusUrl from './apiServiceUtils';
import { EnterpriseGroup, PaginatedCurrentPage } from '../../types';

export type CreateEnterpriseGroupArgs = {
/* The name of the group to create */
groupName: string,
/* The uuid of the new group's enterprise customer */
enterpriseUUID: string
};

export type UpdateEnterpriseGroupArgs = {
/* The updated name of the group */
name: string,
};

export type EnterpriseGroupResponse = Promise<AxiosResponse<EnterpriseGroup>>;
export type EnterpriseGroupListResponse = Promise<AxiosResponse<PaginatedCurrentPage<EnterpriseGroup>>>;

class LmsApiService {
static apiClient = getAuthenticatedHttpClient;
Expand Down Expand Up @@ -66,14 +49,14 @@ class LmsApiService {

static enterpriseLearnerUrl = `${LmsApiService.baseUrl}/enterprise/api/v1/enterprise-learner/`;

static createEnterpriseGroup({ groupName, enterpriseUUID }: CreateEnterpriseGroupArgs): EnterpriseGroup {
static createEnterpriseGroup(options) {
const postParams = {
name: groupName,
enterprise_customer: enterpriseUUID,
name: options.groupName,
enterprise_customer: options.enterpriseUUID,
members: [],
};
const createEnterpriseGroupUrl = `${LmsApiService.enterpriseGroupListUrl}`;
return camelCaseObject(LmsApiService.apiClient().post(createEnterpriseGroupUrl, postParams));
return LmsApiService.apiClient().post(createEnterpriseGroupUrl, postParams);
}

static fetchEnterpriseSsoOrchestrationRecord(configurationUuid) {
Expand Down Expand Up @@ -445,7 +428,7 @@ class LmsApiService {
);
};

static async fetchData(url, linkedEnterprises: any[] = []) {
static async fetchData(url, linkedEnterprises = []) {
const response = await getAuthenticatedHttpClient().get(url);
const responseData = camelCaseObject(response.data);
const linkedEnterprisesCopy = [...linkedEnterprises];
Expand All @@ -466,18 +449,14 @@ class LmsApiService {
return response;
};

static fetchEnterpriseGroup = async (groupUuid: string): EnterpriseGroupResponse => {
static fetchEnterpriseGroup = async (groupUuid) => {
const groupEndpoint = `${LmsApiService.enterpriseGroupListUrl}${groupUuid}/`;
const response = LmsApiService.apiClient().get(groupEndpoint);
response.data = camelCaseObject(response.data);
return response;
return LmsApiService.apiClient().get(groupEndpoint);

Check warning on line 454 in src/data/services/LmsApiService.js

View check run for this annotation

Codecov / codecov/patch

src/data/services/LmsApiService.js#L454

Added line #L454 was not covered by tests
};

static fetchEnterpriseGroups = async (): EnterpriseGroupListResponse => {
static fetchEnterpriseGroups = async () => {
const url = `${LmsApiService.enterpriseGroupUrl}`;
const response = LmsApiService.apiClient().get(url);
response.data = camelCaseObject(response.data);
return response;
return LmsApiService.apiClient().get(url);

Check warning on line 459 in src/data/services/LmsApiService.js

View check run for this annotation

Codecov / codecov/patch

src/data/services/LmsApiService.js#L459

Added line #L459 was not covered by tests
};

static inviteEnterpriseLearnersToGroup = async (groupUuid, formData) => {
Expand All @@ -496,26 +475,21 @@ class LmsApiService {

static fetchAllEnterpriseGroupLearners = async (groupUuid) => {
const queryParams = new URLSearchParams({
page: '1',
page: 1,
});
const url = `${LmsApiService.enterpriseGroupUrl}${groupUuid}/learners?${queryParams.toString()}`;
const response = await LmsApiService.fetchData(url);
return response;
};

static removeEnterpriseGroup = async (groupUuid: string): Promise<AxiosResponse> => {
static removeEnterpriseGroup = async (groupUuid) => {
const removeGroupEndpoint = `${LmsApiService.enterpriseGroupListUrl}${groupUuid}/`;
return LmsApiService.apiClient().delete(removeGroupEndpoint);
};

static updateEnterpriseGroup = async (
groupUuid: string,
formData: UpdateEnterpriseGroupArgs,
): EnterpriseGroupResponse => {
static updateEnterpriseGroup = async (groupUuid, formData) => {
const updateGroupEndpoint = `${LmsApiService.enterpriseGroupListUrl}${groupUuid}/`;
const response = LmsApiService.apiClient().patch(updateGroupEndpoint, formData);
response.data = camelCaseObject(response.data);
return response;
return LmsApiService.apiClient().patch(updateGroupEndpoint, formData);

Check warning on line 492 in src/data/services/LmsApiService.js

View check run for this annotation

Codecov / codecov/patch

src/data/services/LmsApiService.js#L492

Added line #L492 was not covered by tests
};

static removeEnterpriseLearnersFromGroup = async (groupUuid, formData) => {
Expand Down
2 changes: 1 addition & 1 deletion src/data/services/tests/LmsApiService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('LmsApiService', () => {
data: {
uuid: 'test-uuid',
name: 'test-name',
enterpriseCustomer: 'test-enterprise-customer',
enterprise_customer: 'test-enterprise-customer',
members: [],
},
});
Expand Down
30 changes: 0 additions & 30 deletions src/types.d.ts

This file was deleted.

24 changes: 21 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
{
"extends": "@edx/typescript-config",
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "es6", "dom.iterable"],
"isolatedModules": true,
"module": "ES6",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": false,
"noImplicitThis": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictFunctionTypes": false,
"target": "ES6",
"rootDir": ".",
"outDir": "dist",
"outDir": "dist"
},
"include": ["src/**/*", "__mocks__/**/*"],
"exclude": ["dist", "src/icons/*"],
"exclude": ["dist", "src/icons/*"]
}

0 comments on commit 3b0ca28

Please sign in to comment.