@@ -4,17 +4,15 @@ async function resolveAuthLevel(schema, options, doc) {
4
4
// Look into options the options and try to find authLevels. Always prefer to take
5
5
// authLevels from the direct authLevel option as opposed to the computed
6
6
// ones from getAuthLevel in the schema object.
7
- let authLevelsIn = [ ] ;
7
+ let authLevels = [ ] ;
8
8
if ( options ) {
9
9
if ( options . authLevel ) {
10
- authLevelsIn = options . authLevel ;
10
+ authLevels = _ . castArray ( options . authLevel ) ;
11
11
} else if ( typeof schema . getAuthLevel === 'function' ) {
12
- authLevelsIn = schema . getAuthLevel ( options . authPayload , doc ) ;
12
+ authLevels = _ . castArray ( await schema . getAuthLevel ( options . authPayload , doc ) ) ;
13
13
}
14
14
}
15
15
16
- const authLevels = _ . castArray ( await Promise . resolve ( authLevelsIn ) ) ;
17
-
18
16
// Add `defaults` to the list of levels since you should always be able to do what's specified
19
17
// in defaults.
20
18
authLevels . push ( 'defaults' ) ;
@@ -117,18 +115,18 @@ async function sanitizeDocument(schema, options, doc) {
117
115
async function sanitizeDocumentList ( schema , options , docs ) {
118
116
const multi = _ . isArrayLike ( docs ) ;
119
117
const docList = _ . castArray ( docs ) ;
118
+ const sanitizeAndAddOptions = ( doc ) => {
119
+ const upgradedOptions = _ . isEmpty ( schema . pathsWithPermissionedSchemas )
120
+ ? options
121
+ : _ . merge ( { } , options , { authPayload : { originalDoc : doc } } ) ;
122
+ return sanitizeDocument ( schema , upgradedOptions , doc ) ;
123
+ } ;
120
124
121
- const filteredResult = _ . chain ( await Promise . all ( _ . map ( docList , async ( doc ) => {
122
- const upgradedOptions = _ . isEmpty ( schema . pathsWithPermissionedSchemas )
123
- ? options
124
- : _ . merge ( { } , options , { authPayload : { originalDoc : doc } } ) ;
125
-
126
- return await sanitizeDocument ( schema , upgradedOptions , doc ) ;
127
- } ) ) )
128
- . filter ( docList )
129
- . value ( ) ;
125
+ const filteredResult = (
126
+ await Promise . all ( docList . map ( sanitizeAndAddOptions ) )
127
+ ) . filter ( doc => ! doc ) ;
130
128
131
- return multi ? Promise . all ( filteredResult ) : filteredResult [ 0 ] ;
129
+ return multi ? ( filteredResult ) : filteredResult [ 0 ] ;
132
130
}
133
131
134
132
function getUpdatePaths ( updates ) {
0 commit comments