@@ -159,14 +159,56 @@ export default class OfflineApi {
159159
160160 // Method to handle POST requests
161161 async post < T = any > ( url : string , data : T , ...config : any ) : AxiosPromise < T > {
162- const { model, id, query } = urlParts ( url ) ;
162+ const { model, id, query, parts } = urlParts ( url ) ;
163163 log ( 'post' , url , data ) ;
164164 switch ( model ) {
165165 case 'admin' :
166166 return resolveResponse ( data as unknown as T ) ;
167167 case 'cms' :
168168 return resolveResponse ( { } as unknown as T ) ;
169+ case 'users' :
170+ if ( parts . length === 1 && parts [ 0 ] === 'documentRoots' ) {
171+ const { documentRootIds, type } = data as {
172+ documentRootIds : string [ ] ;
173+ type ?: DocumentType ;
174+ } ;
175+ if ( documentRootIds . length === 0 ) {
176+ resolveResponse ( [ ] as unknown as T ) ;
177+ }
178+ const documentRootDocs = await Promise . all (
179+ documentRootIds . map ( ( id ) => this . documentsBy ( id ) )
180+ ) ;
181+ const filteredDocs = type
182+ ? documentRootDocs . map ( ( docs ) => docs . filter ( ( doc ) => doc . type === type ) )
183+ : documentRootDocs ;
184+
185+ const documenRoots = documentRootIds . map ( ( rid ) => {
186+ return {
187+ id : rid ,
188+ access : Access . RW_DocumentRoot ,
189+ sharedAccess : Access . RW_DocumentRoot ,
190+ userPermissions : [ ] ,
191+ groupPermissions : [ ] ,
192+ documents :
193+ filteredDocs . find (
194+ ( docs ) => docs . length > 0 && docs [ 0 ] . documentRootId === rid
195+ ) || [ ]
196+ } ;
197+ } ) as unknown as T ;
198+ log ( '-> post' , url , documenRoots ) ;
199+ return resolveResponse ( documenRoots ) ;
200+ }
201+ return resolveResponse ( [ ] as unknown as T ) ;
169202 case 'documents' :
203+ if ( url === 'documents/multiple' ) {
204+ const documentRootIds = new Set ( ( data as { documentRootIds : string [ ] } ) . documentRootIds ) ;
205+ const allDocuments = await this . dbAdapter . getAll < Document < any > > ( DOCUMENTS_STORE ) ;
206+
207+ const filteredDocuments = allDocuments . filter ( ( doc ) =>
208+ documentRootIds . has ( doc . documentRootId )
209+ ) ;
210+ return resolveResponse ( filteredDocuments as unknown as T ) ;
211+ }
170212 const document = await this . upsertDocumentRecord < any > (
171213 data as Partial < Document < any > > ,
172214 query . has ( 'uniqueMain' )
@@ -214,35 +256,6 @@ export default class OfflineApi {
214256 switch ( model ) {
215257 case 'user' :
216258 return resolveResponse ( OfflineUser as unknown as T ) ;
217- case 'users' :
218- if ( parts . length === 1 && parts [ 0 ] === 'documentRoots' ) {
219- const ids = query . getAll ( 'ids' ) ;
220- const docType = query . get ( 'type' ) as DocumentType | null ;
221- if ( ids . length === 0 ) {
222- resolveResponse ( [ ] as unknown as T ) ;
223- }
224- const documentRootDocs = await Promise . all ( ids . map ( ( id ) => this . documentsBy ( id ) ) ) ;
225- const filteredDocs = docType
226- ? documentRootDocs . map ( ( docs ) => docs . filter ( ( doc ) => doc . type === docType ) )
227- : documentRootDocs ;
228-
229- const documenRoots = ids . map ( ( rid ) => {
230- return {
231- id : rid ,
232- access : Access . RW_DocumentRoot ,
233- sharedAccess : Access . RW_DocumentRoot ,
234- userPermissions : [ ] ,
235- groupPermissions : [ ] ,
236- documents :
237- filteredDocs . find (
238- ( docs ) => docs . length > 0 && docs [ 0 ] . documentRootId === rid
239- ) || [ ]
240- } ;
241- } ) as unknown as T ;
242- log ( '-> get' , url , documenRoots ) ;
243- return resolveResponse ( documenRoots ) ;
244- }
245- return resolveResponse ( [ OfflineUser ] as unknown as T ) ;
246259 case 'admin' :
247260 return resolveResponse ( [ ] as unknown as T ) ;
248261 case 'allowedActions' :
@@ -255,6 +268,7 @@ export default class OfflineApi {
255268 }
256269 return resolveResponse ( null ) ;
257270 }
271+ // TODO: is this needed/used at all?
258272 if ( query . has ( 'ids' ) ) {
259273 const ids = query . getAll ( 'ids' ) ;
260274 const filteredDocuments : Document < any > [ ] = [ ] ;
@@ -266,19 +280,12 @@ export default class OfflineApi {
266280 }
267281 return resolveResponse ( filteredDocuments as unknown as T ) ;
268282 }
269- if ( query . has ( 'rids' ) ) {
270- const rids = query . getAll ( 'rids' ) ;
271-
272- const allDocuments = await this . dbAdapter . getAll < Document < any > > ( DOCUMENTS_STORE ) ;
273-
274- const filteredDocuments = allDocuments . filter ( ( doc ) => rids . includes ( doc . documentRootId ) ) ;
275-
276- return resolveResponse ( filteredDocuments as unknown as T ) ;
277- }
278283
279284 return resolveResponse (
280285 ( await this . dbAdapter . getAll < Document < any > > ( DOCUMENTS_STORE ) ) as unknown as T
281286 ) ;
287+ case 'users' :
288+ return resolveResponse ( [ OfflineUser ] as unknown as T ) ;
282289 case 'documentRoots' :
283290 if ( parts [ 0 ] === 'permissions' ) {
284291 return resolveResponse ( {
0 commit comments