Skip to content

Commit 19d3964

Browse files
authored
Merge pull request #101 from kube-js/develop
fix: added get discovery items route
2 parents 277e7c5 + 8522821 commit 19d3964

File tree

9 files changed

+81
-2
lines changed

9 files changed

+81
-2
lines changed

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.4.32
5+
appVersion: 1.4.37
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.4.32
9+
tag: 1.4.37
1010
pullPolicy: Always
1111
containerPort: 3000
1212

src/constants/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export const ENROLMENTS = '/enrolments';
2525
export const MODULES = '/modules';
2626
export const UNITS = '/units';
2727
export const COMMENTS = '/comments';
28+
export const DISCOVERY_ITEMS = '/discovery-items';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AUTH,
44
CATEGORIES,
55
COURSES,
6+
DISCOVERY_ITEMS,
67
ENROLMENTS,
78
// MODULES,
89
// UNITS
@@ -16,6 +17,7 @@ import authFactory from './routes/auth/factory';
1617
import categoriesFactory from './routes/categories/factory';
1718
import coursesFactory from './routes/courses/factory';
1819
import enrolmentsFactory from './routes/enrolments/factory';
20+
import getDiscoveryItems from './routes/getDiscoveryItems';
1921
import permissionsFactory from './routes/permissions/factory';
2022
import rolesFactory from './routes/roles/factory';
2123
import usersFactory from './routes/users/factory';
@@ -38,6 +40,7 @@ const apiV1 = (config: Config): Router => {
3840
router.use(CATEGORIES, categoriesFactory(config));
3941
router.use(COURSES, coursesFactory(config));
4042
router.use(ENROLMENTS, enrolmentsFactory(config));
43+
router.use(DISCOVERY_ITEMS, getDiscoveryItems(config));
4144
// router.use(MODULES, modulesFactory(config));
4245
// router.use(UNITS, unitsFactory(config));
4346
// TODO: add route for uploading /avatar
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sendResponse from '@js-items/express/dist/utils/sendResponse';
2+
import { toSnake } from 'convert-keys';
3+
import { OK } from 'http-status-codes';
4+
import Config from '../../../../presenterFactory/Config';
5+
import catchErrors from '../../../../utils/errors/catchErrors';
6+
7+
const getDiscoveryItems = (config: Config) =>
8+
catchErrors(config, async (req, res) => {
9+
const type = req.query.type;
10+
11+
let response;
12+
13+
switch (type) {
14+
case 'homepage':
15+
default:
16+
response = await config.service.getDiscoveryItemsForHomepage({});
17+
}
18+
19+
sendResponse({
20+
body: toSnake(response),
21+
req,
22+
res,
23+
status: OK,
24+
});
25+
});
26+
27+
export default getDiscoveryItems;

src/presenter/express/api/v1/routes/utils/describeApi/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Object {
1818
"version": "/version",
1919
},
2020
"courses": "/api/v1/courses",
21+
"discovery_items": "/api/v1/discovery-items",
2122
"enrolments": "/api/v1/enrolments",
2223
"permissions": "/api/v1/permissions",
2324
"roles": "/api/v1/roles",

src/presenter/express/api/v1/routes/utils/describeApi/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const describeApi = (config: Config) =>
2525
version,
2626
},
2727
courses: '/api/v1/courses',
28+
discoveryItems: '/api/v1/discovery-items',
2829
enrolments: '/api/v1/enrolments',
2930
permissions: '/api/v1/permissions',
3031
roles: '/api/v1/roles',

src/service/factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import migrationsServiceFactory from '@js-migrations/core/dist/factory';
22
import FactoryConfig from './FactoryConfig';
33
import authFactory from './functions/auth/factory';
4+
import getDiscoveryItemsForHomepage from './functions/getDiscoveryItemsForHomepage';
45
import hasPermission from './functions/hasPermission';
56
import assignRolePermission from './functions/roles/assignRolePermission';
67
import revokeRolePermission from './functions/roles/revokeRolePermission';
@@ -15,6 +16,7 @@ export default (config: FactoryConfig) => ({
1516
closeDbConnection: config.repo.closeDbConnection,
1617
courses: config.repo.courses,
1718
enrolments: config.repo.enrolments,
19+
getDiscoveryItemsForHomepage: getDiscoveryItemsForHomepage(config),
1820
hasPermission: hasPermission(config),
1921
migrations: migrationsServiceFactory({
2022
repo: config.repo.migrations,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import _pluck from 'ramda/src/pluck';
2+
import Course from '../../../types/items/Course';
3+
import Config from '../../FactoryConfig';
4+
5+
// tslint:disable-next-line:no-empty-interface
6+
export interface Options {}
7+
8+
// tslint:disable-next-line:arrow-return-shorthand
9+
export default ({ repo }: Config) => async (_options: Options) => {
10+
const { items: categories } = await repo.categories.getItems({
11+
pagination: {
12+
limit: 10000,
13+
},
14+
});
15+
16+
const { items: courses } = await repo.courses.getItems({
17+
pagination: {
18+
limit: 10000,
19+
},
20+
});
21+
22+
const { items: users } = await repo.users.getItems({
23+
pagination: {
24+
limit: 10000,
25+
},
26+
});
27+
28+
const enhancedCourses = courses.map((course: Course) => ({
29+
...course,
30+
user: users.filter(user => user.id === course.userId),
31+
}));
32+
33+
return {
34+
bestSellers: {
35+
// TODO: in the future basing on number of enrolments choose the most popular one
36+
categories,
37+
courses: enhancedCourses,
38+
},
39+
mostViewed: {
40+
// TODO: in the future choose the most viewed ones
41+
courses: enhancedCourses,
42+
},
43+
};
44+
};

0 commit comments

Comments
 (0)