|
| 1 | + |
| 2 | +function createRest() {} |
| 3 | +function resources() {} |
| 4 | +function resource() {} |
| 5 | +function member() {} |
| 6 | +function childs() {} |
| 7 | +function scope() {} |
| 8 | +function root() {} |
| 9 | +function post() {} |
| 10 | +function get() {} |
| 11 | +function destroy() {} |
| 12 | +function put() {} |
| 13 | +function patch() {} |
| 14 | + |
| 15 | +class SectionsController {} |
| 16 | +class BooksController {} |
| 17 | +class DemoController {} |
| 18 | +class LikeController {} |
| 19 | +class ProfileController {} |
| 20 | +class PagesController {} |
| 21 | +class BookmarksController {} |
| 22 | + |
| 23 | +module.exports = createRest( |
| 24 | + root( |
| 25 | + resources('book', { validate: mySuperValidateFunction }, BooksController), |
| 26 | + resources('section', { only: ['index', 'read'] }, SectionsController), |
| 27 | + resources('demo', {}, DemoController, childs( |
| 28 | + member( |
| 29 | + get('status'), |
| 30 | + post('close'), |
| 31 | + post('open', { methodName: 'reopen' }), |
| 32 | + ), |
| 33 | + resource('like', {}, LikeController), |
| 34 | + )), |
| 35 | + resource('profile', {}, ProfileController, childs( |
| 36 | + resources('bookmark', { memberId: 'id' }, BookmarksController, childs( |
| 37 | + member( |
| 38 | + resource('share_link', {}, BookmarksController.ShareLinkController), |
| 39 | + ), |
| 40 | + )), |
| 41 | + )), |
| 42 | + scope('admin', childs( |
| 43 | + post('login'), |
| 44 | + post('logout'), |
| 45 | + resources('pages', {}, PagesController), |
| 46 | + scope('status', childs( |
| 47 | + get('database'), |
| 48 | + get('service'), |
| 49 | + get('redis'), |
| 50 | + )), |
| 51 | + )), |
| 52 | + ), |
| 53 | +) |
| 54 | + |
| 55 | + |
| 56 | +const SimpleController = { |
| 57 | + read() {}, |
| 58 | + create() {}, |
| 59 | + update() {}, |
| 60 | + destroy() {}, |
| 61 | +} |
| 62 | + |
| 63 | +const myValidations = (req, res, next) => { |
| 64 | + // validations |
| 65 | + next() |
| 66 | +} |
| 67 | + |
| 68 | +createRest( |
| 69 | + resource('simple', { before: [myValidations] }, SimpleController), |
| 70 | +) |
| 71 | + |
0 commit comments