Skip to content

Commit

Permalink
fetch restricted runs in publisher (#964)
Browse files Browse the repository at this point in the history
chore: fetch restricted runs in publisher
  • Loading branch information
zawan-ila authored Jun 25, 2024
1 parent 5252f68 commit 7b1f22b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/data/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ const COURSE_URL_SLUG_VALIDATION_MESSAGE = {
[COURSE_URL_SLUG_PATTERN]: 'Course URL slug contains lowercase letters, numbers, underscores, and dashes only and must be in the format <custom-url-slug> or learn/<primary_subject>/<org-slug>-<course_slug>.',
};

const RESTRICTION_TYPE_OPTIONS = [
{ value: '', label: '--------' },
{ value: 'custom-b2b-enterprise', label: 'Custom Enterprise' },
{ value: 'custom-b2c', label: 'Custom B2C' },
];

const RESTRICTION_TYPE_VALUES = RESTRICTION_TYPE_OPTIONS.map(opt => opt.value).filter(Boolean).join(',');

export {
VERIFIED_TRACK,
AUDIT_TRACK,
Expand All @@ -59,4 +67,6 @@ export {
COURSE_URL_SLUG_PATTERN_NEW,
COURSE_URL_SLUG_PATTERN_OLD,
COURSE_URL_SLUG_VALIDATION_MESSAGE,
RESTRICTION_TYPE_OPTIONS,
RESTRICTION_TYPE_VALUES,
};
6 changes: 6 additions & 0 deletions src/data/services/DiscoveryDataApiService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';

import { PAGE_SIZE } from '../constants/table';
import { RESTRICTION_TYPE_VALUES as restrictionTypeValues } from '../constants';

const discoveryBaseUrl = `${process.env.DISCOVERY_API_BASE_URL}/api/v1`;
const publisherBaseUrl = `${process.env.DISCOVERY_API_BASE_URL}/publisher/api`;
Expand All @@ -10,6 +11,7 @@ class DiscoveryDataApiService {
const queryParams = {
editable: 1,
exclude_utm: 1,
include_restricted: restrictionTypeValues,
};
const url = `${discoveryBaseUrl}/courses/${uuid}/`;
return getAuthenticatedHttpClient().get(url, {
Expand All @@ -21,6 +23,7 @@ class DiscoveryDataApiService {
const queryParams = {
editable: 1,
exclude_utm: 1,
include_restricted: restrictionTypeValues,
...params,
};
const url = `${discoveryBaseUrl}/course_runs/${key}`;
Expand All @@ -45,6 +48,7 @@ class DiscoveryDataApiService {
fields: fields.join(),
editable: 1,
exclude_utm: 1,
include_restricted: restrictionTypeValues,
...options,
};
const url = `${discoveryBaseUrl}/courses/`;
Expand Down Expand Up @@ -145,6 +149,7 @@ class DiscoveryDataApiService {
static editCourseRuns(courseRunsData) {
const queryParams = {
exclude_utm: 1,
include_restricted: restrictionTypeValues,
};
// Create a promises array to handle all of the new/modified course runs
const promises = courseRunsData.map((courseRun) => {
Expand Down Expand Up @@ -213,6 +218,7 @@ class DiscoveryDataApiService {
const { uuid } = courseData;
const queryParams = {
exclude_utm: 1,
include_restricted: restrictionTypeValues,
};
const url = `${discoveryBaseUrl}/courses/${uuid}/`;
return getAuthenticatedHttpClient().patch(url, courseData, {
Expand Down
7 changes: 1 addition & 6 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import qs from 'query-string';
import {
COURSE_EXEMPT_FIELDS, COURSE_RUN_NON_EXEMPT_FIELDS, COURSE_URL_SLUG_PATTERN_OLD,
MASTERS_TRACK, COURSE_URL_SLUG_VALIDATION_MESSAGE, EXECUTIVE_EDUCATION_SLUG, BOOTCAMP_SLUG,
RESTRICTION_TYPE_OPTIONS as restrictionTypeOptions,
} from '../data/constants';
import DiscoveryDataApiService from '../data/services/DiscoveryDataApiService';
import { PAGE_SIZE } from '../data/constants/table';
Expand Down Expand Up @@ -369,12 +370,6 @@ const buildInitialPrices = (entitlements, courseRuns) => {
const hasMastersTrack = (runTypeUuid, runTypeModes) => (!!runTypeUuid
&& !!runTypeModes[runTypeUuid] && runTypeModes[runTypeUuid].includes(MASTERS_TRACK.key));

const restrictionTypeOptions = [
{ value: '', label: '--------' },
{ value: 'custom-b2b-enterprise', label: 'Custom Enterprise' },
{ value: 'custom-b2c', label: 'Custom B2C' },
];

export {
courseRunIsArchived,
getDateWithDashes,
Expand Down

0 comments on commit 7b1f22b

Please sign in to comment.