@@ -102,18 +102,16 @@ import {
102
102
deleteFor ,
103
103
Router ,
104
104
} from '@lykmapipo/express-rest-actions' ;
105
- import File from './file.model' ;
105
+ import { createModels } from './file.model' ;
106
106
107
107
/* constants */
108
108
const API_VERSION = getString ( 'API_VERSION' , '1.0.0' ) ;
109
109
const PATH_SINGLE = '/files/:bucket/:id' ;
110
110
const PATH_LIST = '/files/:bucket' ;
111
- const PATH_SCHEMA = '/files/:bucket/schema/ ' ;
111
+ const PATH_SCHEMA = '/files/:bucket/schema' ;
112
112
113
113
/* declarations */
114
- const router = new Router ( {
115
- version : API_VERSION ,
116
- } ) ;
114
+ const router = new Router ( { version : API_VERSION } ) ;
117
115
118
116
/**
119
117
* @api {get } /files/:bucket List Files
@@ -134,7 +132,10 @@ const router = new Router({
134
132
router . get (
135
133
PATH_LIST ,
136
134
getFor ( {
137
- get : ( options , done ) => File . get ( options , done ) ,
135
+ get : ( options , done ) => {
136
+ const { File } = createModels ( ) ;
137
+ return File . get ( options , done ) ;
138
+ } ,
138
139
} )
139
140
) ;
140
141
@@ -150,6 +151,7 @@ router.get(
150
151
PATH_SCHEMA ,
151
152
schemaFor ( {
152
153
getSchema : ( query , done ) => {
154
+ const { File } = createModels ( ) ;
153
155
const jsonSchema = File . jsonSchema ( ) ;
154
156
return done ( null , jsonSchema ) ;
155
157
} ,
@@ -175,7 +177,10 @@ router.get(
175
177
router . post (
176
178
PATH_LIST ,
177
179
postFor ( {
178
- post : ( body , done ) => File . post ( body , done ) ,
180
+ post : ( body , done ) => {
181
+ const { File } = createModels ( ) ;
182
+ File . post ( body , done ) ;
183
+ } ,
179
184
} )
180
185
) ;
181
186
@@ -197,7 +202,10 @@ router.post(
197
202
router . get (
198
203
PATH_SINGLE ,
199
204
getByIdFor ( {
200
- getById : ( options , done ) => File . getById ( options , done ) ,
205
+ getById : ( options , done ) => {
206
+ const { File } = createModels ( ) ;
207
+ return File . getById ( options , done ) ;
208
+ } ,
201
209
} )
202
210
) ;
203
211
@@ -220,7 +228,10 @@ router.get(
220
228
router . patch (
221
229
PATH_SINGLE ,
222
230
patchFor ( {
223
- patch : ( options , done ) => File . patch ( options , done ) ,
231
+ patch : ( options , done ) => {
232
+ const { File } = createModels ( ) ;
233
+ return File . patch ( options , done ) ;
234
+ } ,
224
235
} )
225
236
) ;
226
237
@@ -243,7 +254,10 @@ router.patch(
243
254
router . put (
244
255
PATH_SINGLE ,
245
256
putFor ( {
246
- put : ( options , done ) => File . put ( options , done ) ,
257
+ put : ( options , done ) => {
258
+ const { File } = createModels ( ) ;
259
+ return File . put ( options , done ) ;
260
+ } ,
247
261
} )
248
262
) ;
249
263
@@ -266,8 +280,11 @@ router.put(
266
280
router . delete (
267
281
PATH_SINGLE ,
268
282
deleteFor ( {
269
- del : ( options , done ) => File . del ( options , done ) ,
270
283
soft : true ,
284
+ del : ( options , done ) => {
285
+ const { File } = createModels ( ) ;
286
+ return File . del ( options , done ) ;
287
+ } ,
271
288
} )
272
289
) ;
273
290
0 commit comments