Skip to content

Commit 4fbdefd

Browse files
committed
fix: added sections
1 parent 402f5c3 commit 4fbdefd

File tree

32 files changed

+361
-14
lines changed

32 files changed

+361
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ npm run test:watch
7272
- resetPasswordTokens
7373
- courses
7474
- enrolments
75-
- modules
75+
- sections
7676
- units
7777

7878
## This repo would not exist if not inspiration coming from:

assets/jscpd-badge.svg

Lines changed: 2 additions & 2 deletions
Loading

k8s/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
description: A Helm chart for kube-ts-server
33
name: kube-ts-server
44
version: 1.0.0
5-
appVersion: 1.5.6
5+
appVersion: 1.5.17
66
home: https://cloud.docker.com/u/kubejs/repository/docker/kubejs/kube-ts-server
77
icon: https://avatars2.githubusercontent.com/u/47761918?s=200&v=4
88
sources:

k8s/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replicaCount: 2
66

77
image:
88
repository: kubejs/kube-ts-server
9-
tag: 1.5.6
9+
tag: 1.5.17
1010
pullPolicy: Always
1111
containerPort: 3000
1212

src/constants/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const PERMISSIONS = '/permissions';
2222
export const COURSES = '/courses';
2323
export const CATEGORIES = '/categories';
2424
export const ENROLMENTS = '/enrolments';
25-
export const MODULES = '/modules';
25+
export const SECTIONS = '/sections';
2626
export const UNITS = '/units';
2727
export const COMMENTS = '/comments';
2828
export const DISCOVERY_ITEMS = '/discovery-items';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { v4 as uuid } from 'uuid';
2+
3+
const sections = [
4+
{
5+
id: uuid(),
6+
order: 1,
7+
title: 'First section',
8+
},
9+
{
10+
id: uuid(),
11+
order: 2,
12+
title: 'Second section'
13+
},
14+
{
15+
id: uuid(),
16+
order: 3,
17+
title: 'Third section'
18+
},
19+
{
20+
id: uuid(),
21+
order: 4,
22+
title: 'Fourth section'
23+
},
24+
{
25+
id: uuid(),
26+
order: 5,
27+
title: 'Fifth section'
28+
},
29+
30+
];
31+
32+
export default sections;

src/presenter/commander/functions/dbSeed/functions/createCategoriesAndCourses/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ const createCategoriesAndCourses = (config: FactoryConfig) => async ({
8686
return [...acc, ...coursesPromisesArray];
8787
}, []);
8888

89-
await Promise.all(coursesPromises);
89+
const items = await Promise.all(coursesPromises);
9090

91+
9192
console.log(`Courses created successfuly!`);
9293
console.log(`--------------------------------------------------------`);
94+
95+
return items.map(({ item }) => item.id);
9396
};
9497

9598
export default createCategoriesAndCourses;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// tslint:disable:no-magic-numbers
2+
// tslint:disable:no-console
3+
import _pluck from 'ramda/src/pluck';
4+
import { v4 as uuid } from 'uuid';
5+
import getUtcDate from '../../../../../../utils/helpers/date/getUtcDate';
6+
import FactoryConfig from '../../../../presenterFactory/FactoryConfig';
7+
8+
export interface SectionPartial {
9+
readonly title: string;
10+
readonly id: string;
11+
readonly order: number;
12+
}
13+
14+
export interface Options {
15+
readonly coursesIds: string[];
16+
readonly sections: SectionPartial[];
17+
}
18+
19+
const createSectionsAndUnits = (config: FactoryConfig) => async ({
20+
coursesIds,
21+
sections,
22+
}: Options) => {
23+
console.log(`--------------------------------------------------------`);
24+
console.log(
25+
`Creating sections `
26+
);
27+
const sectionsPromises = coursesIds.reduce((acc: Promise<any>[], courseId) => {
28+
const sectionsPromisesArray = sections.map(async section => {
29+
const sectionId = uuid();
30+
31+
return config.service.sections.createItem({
32+
id: sectionId,
33+
item: {
34+
courseId,
35+
createdAt: getUtcDate(),
36+
id: sectionId,
37+
order: section.order,
38+
title: section.title,
39+
},
40+
});
41+
});
42+
43+
return [...acc, ...sectionsPromisesArray];
44+
}, []);
45+
46+
await Promise.all(sectionsPromises);
47+
48+
49+
console.log(`Sections created successfuly!`);
50+
console.log(`--------------------------------------------------------`);
51+
};
52+
53+
export default createSectionsAndUnits;

src/presenter/commander/functions/dbSeed/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '../../../../constants/permissions';
77
import { ADMIN, INSTRUCTOR, STUDENT } from '../../../../constants/roles';
88
import categories from '../../data/categories';
9+
import sections from '../../data/sections';
910
import {
1011
adminOptions,
1112
firstInstructorOptions,
@@ -19,6 +20,7 @@ import connectPermissionsToRoles from './functions/connectPermissionsToRoles';
1920
import createCategoriesAndCourses from './functions/createCategoriesAndCourses';
2021
import createPermissions from './functions/createPermissions';
2122
import createRoles from './functions/createRoles';
23+
import createSectionsAndUnits from './functions/createSectionsAndUnits';
2224
import createUser from './functions/createUser';
2325

2426
export const processExitTimeout = 10000;
@@ -97,11 +99,16 @@ const dbSeed = (config: FactoryConfig) => async () => {
9799
rolesIds: [studentRoleId],
98100
});
99101

100-
await createCategoriesAndCourses(config)({
102+
const coursesIds = await createCategoriesAndCourses(config)({
101103
categories,
102104
instructorsIds: [firstInstructorId, secondInstructorId],
103105
});
104106

107+
await createSectionsAndUnits(config)({
108+
coursesIds,
109+
sections,
110+
});
111+
105112
config.logger.info('Seeding successful');
106113

107114
// FYI: allow logger to send all the logs

src/presenter/express/api/v1/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
COURSES,
77
DISCOVERY_ITEMS,
88
ENROLMENTS,
9-
// MODULES,
109
// UNITS
1110
PERMISSIONS,
1211
ROLES,
1312
ROOT,
13+
SECTIONS,
1414
USERS,
1515
} from '../../../../constants/routes';
1616
import Config from '../../presenterFactory/Config';
@@ -22,6 +22,7 @@ import enrolmentsFactory from './routes/enrolments/factory';
2222
import getDiscoveryItems from './routes/getDiscoveryItems';
2323
import permissionsFactory from './routes/permissions/factory';
2424
import rolesFactory from './routes/roles/factory';
25+
import sectionsFactory from './routes/sections/factory';
2526
import usersFactory from './routes/users/factory';
2627
import describeApi from './routes/utils/describeApi';
2728

@@ -44,14 +45,15 @@ const apiV1 = (config: Config): Router => {
4445
router.use(ENROLMENTS, enrolmentsFactory(config));
4546
router.use(DISCOVERY_ITEMS, getDiscoveryItems(config));
4647
router.get(AUTOCOMPLETE, autocompleteHandler(config));
47-
// router.use(MODULES, modulesFactory(config));
48+
router.use(SECTIONS, sectionsFactory(config));
4849
// router.use(UNITS, unitsFactory(config));
4950
// TODO: add route for uploading /avatar
5051
// TODO: add route for uploads
5152
// TODO: research uploading to s3: https://github.com/SanderKnape/aws-upload-to-s3
5253
// https://sanderknape.com/2017/08/using-pre-signed-urls-upload-file-private-s3-bucket/
5354
// https://stackoverflow.com/questions/40304512/get-or-put-objects-on-amazon-s3-with-pre-signed-url
5455
// https://www.quora.com/How-do-I-link-a-file-from-S3-to-DynamoDB
56+
// https://stackoverflow.com/questions/54119399/expose-port-80-on-digital-oceans-managed-kubernetes-without-a-load-balancer/55968709#55968709
5557

5658
router.get(ROOT, describeApi(config));
5759

0 commit comments

Comments
 (0)