File tree Expand file tree Collapse file tree 9 files changed +81
-2
lines changed
functions/getDiscoveryItemsForHomepage Expand file tree Collapse file tree 9 files changed +81
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ apiVersion: v1
2
2
description : A Helm chart for kube-ts-server
3
3
name : kube-ts-server
4
4
version : 1.0.0
5
- appVersion : 1.4.32
5
+ appVersion : 1.4.37
6
6
home : https://cloud.docker.com/u/kubejs/repository/docker/kubejs/kube-ts-server
7
7
icon : https://avatars2.githubusercontent.com/u/47761918?s=200&v=4
8
8
sources :
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ replicaCount: 2
6
6
7
7
image :
8
8
repository : kubejs/kube-ts-server
9
- tag : 1.4.32
9
+ tag : 1.4.37
10
10
pullPolicy : Always
11
11
containerPort : 3000
12
12
Original file line number Diff line number Diff line change @@ -25,3 +25,4 @@ export const ENROLMENTS = '/enrolments';
25
25
export const MODULES = '/modules' ;
26
26
export const UNITS = '/units' ;
27
27
export const COMMENTS = '/comments' ;
28
+ export const DISCOVERY_ITEMS = '/discovery-items' ;
Original file line number Diff line number Diff line change 3
3
AUTH ,
4
4
CATEGORIES ,
5
5
COURSES ,
6
+ DISCOVERY_ITEMS ,
6
7
ENROLMENTS ,
7
8
// MODULES,
8
9
// UNITS
@@ -16,6 +17,7 @@ import authFactory from './routes/auth/factory';
16
17
import categoriesFactory from './routes/categories/factory' ;
17
18
import coursesFactory from './routes/courses/factory' ;
18
19
import enrolmentsFactory from './routes/enrolments/factory' ;
20
+ import getDiscoveryItems from './routes/getDiscoveryItems' ;
19
21
import permissionsFactory from './routes/permissions/factory' ;
20
22
import rolesFactory from './routes/roles/factory' ;
21
23
import usersFactory from './routes/users/factory' ;
@@ -38,6 +40,7 @@ const apiV1 = (config: Config): Router => {
38
40
router . use ( CATEGORIES , categoriesFactory ( config ) ) ;
39
41
router . use ( COURSES , coursesFactory ( config ) ) ;
40
42
router . use ( ENROLMENTS , enrolmentsFactory ( config ) ) ;
43
+ router . use ( DISCOVERY_ITEMS , getDiscoveryItems ( config ) ) ;
41
44
// router.use(MODULES, modulesFactory(config));
42
45
// router.use(UNITS, unitsFactory(config));
43
46
// TODO: add route for uploading /avatar
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Object {
18
18
" version" : " /version" ,
19
19
},
20
20
" courses" : " /api/v1/courses" ,
21
+ " discovery_items" : " /api/v1/discovery-items" ,
21
22
" enrolments" : " /api/v1/enrolments" ,
22
23
" permissions" : " /api/v1/permissions" ,
23
24
" roles" : " /api/v1/roles" ,
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const describeApi = (config: Config) =>
25
25
version,
26
26
} ,
27
27
courses : '/api/v1/courses' ,
28
+ discoveryItems : '/api/v1/discovery-items' ,
28
29
enrolments : '/api/v1/enrolments' ,
29
30
permissions : '/api/v1/permissions' ,
30
31
roles : '/api/v1/roles' ,
Original file line number Diff line number Diff line change 1
1
import migrationsServiceFactory from '@js-migrations/core/dist/factory' ;
2
2
import FactoryConfig from './FactoryConfig' ;
3
3
import authFactory from './functions/auth/factory' ;
4
+ import getDiscoveryItemsForHomepage from './functions/getDiscoveryItemsForHomepage' ;
4
5
import hasPermission from './functions/hasPermission' ;
5
6
import assignRolePermission from './functions/roles/assignRolePermission' ;
6
7
import revokeRolePermission from './functions/roles/revokeRolePermission' ;
@@ -15,6 +16,7 @@ export default (config: FactoryConfig) => ({
15
16
closeDbConnection : config . repo . closeDbConnection ,
16
17
courses : config . repo . courses ,
17
18
enrolments : config . repo . enrolments ,
19
+ getDiscoveryItemsForHomepage : getDiscoveryItemsForHomepage ( config ) ,
18
20
hasPermission : hasPermission ( config ) ,
19
21
migrations : migrationsServiceFactory ( {
20
22
repo : config . repo . migrations ,
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments