File tree Expand file tree Collapse file tree 5 files changed +77
-0
lines changed
functions/getDiscoveryItems Expand file tree Collapse file tree 5 files changed +77
-0
lines changed 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
+
10
+ const response = await config . service . getDiscoveryItems ( { } ) ;
11
+
12
+ sendResponse ( {
13
+ body : toSnake ( response ) ,
14
+ req,
15
+ res,
16
+ status : OK ,
17
+ } ) ;
18
+ } ) ;
19
+
20
+ export default getDiscoveryItems ;
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 getDiscoveryItems from './functions/getDiscoveryItems' ;
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
+ getDiscoveryItems : getDiscoveryItems ( 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 Config from '../../FactoryConfig' ;
3
+
4
+ // tslint:disable-next-line:no-empty-interface
5
+ export interface Options { }
6
+
7
+ // tslint:disable-next-line:arrow-return-shorthand
8
+ export default ( _config : Config ) => async ( _options : Options ) => {
9
+ // TODO: return items for homepage basing on query param
10
+ // const { items: userRoles } = await repo.userRole.getItems({
11
+ // filter: {
12
+ // userId: user.id,
13
+ // },
14
+ // });
15
+
16
+ // if (userRoles.length === 0) {
17
+ // throw new ForbiddenError();
18
+ // }
19
+
20
+ // const rolesIds = _pluck('roleId', userRoles);
21
+
22
+ // const { items: rolePermissions } = await repo.rolePermission.getItems({
23
+ // filter: {
24
+ // roleId: {
25
+ // $in: rolesIds,
26
+ // },
27
+ // },
28
+ // pagination: {
29
+ // // high number to get all permissions
30
+ // limit: 1000
31
+ // }
32
+ // });
33
+
34
+ // if (rolePermissions.length === 0) {
35
+ // throw new ForbiddenError();
36
+ // }
37
+
38
+ // const permissionsIds = _pluck('permissionId', rolePermissions);
39
+
40
+ // const { count } = await repo.countPermissions({
41
+ // method: req.method,
42
+ // permissionsIds,
43
+ // url: req.originalUrl,
44
+ // });
45
+
46
+ // if (count === 0) {
47
+ // throw new ForbiddenError();
48
+ // }
49
+
50
+ return Promise . resolve ( { } ) ;
51
+ } ;
You can’t perform that action at this time.
0 commit comments