@@ -73,12 +73,18 @@ module.exports = {
7373 let body = req . body ;
7474 body . owner = res . locals . _id ;
7575
76+ console . log ( body )
77+
7678 // Add accessGroups if body.accessGroups is undefined
77- if ( ! body . accessGroups . read || body . accessGroups . read . length < 1 ) {
78- body . accessGroups . read = [ res . locals . group ] ;
79- }
80- if ( ! body . accessGroups . edit || body . accessGroups . edit . length < 1 ) {
81- body . accessGroups . edit = [ res . locals . group ] ;
79+ if ( ! body . accessGroups ) {
80+ body . accessGroups = { read : [ res . locals . group ] , edit : [ res . locals . group ] } ;
81+ } else {
82+ if ( ! body . accessGroups . read || body . accessGroups . read . length < 1 ) {
83+ body . accessGroups . read = [ res . locals . group ] ;
84+ }
85+ if ( ! body . accessGroups . edit || body . accessGroups . edit . length < 1 ) {
86+ body . accessGroups . edit = [ res . locals . group ] ;
87+ }
8288 }
8389
8490 const result = await itemService . create ( body ) ;
@@ -92,6 +98,7 @@ module.exports = {
9298
9399 res . status ( 201 ) . send ( result ) ;
94100 } catch ( err ) {
101+ console . log ( err ) ;
95102 res . status ( err . status || 500 ) . send ( err . message ) ;
96103 }
97104 } ,
@@ -135,12 +142,16 @@ module.exports = {
135142 if ( item === null )
136143 throw new NotFoundError ( `Not Found: 검색 결과가 없습니다.` ) ;
137144
145+ // Algolia
146+ await algolia . deleteObject ( item_id ) ;
147+
148+ // Delete item
138149 let promises = [ itemService . delete ( item_id ) ] ;
150+
151+ // Removing all items
139152 for ( let historyItem of item . history ) {
140153 promises . push ( itemService . delete ( historyItem ) ) ;
141154 }
142-
143- // Waiting for removing all items;
144155 await Promise . all ( promises ) ;
145156
146157 res . status ( 204 ) . send ( ) ;
0 commit comments