File tree Expand file tree Collapse file tree 1 file changed +37
-2
lines changed
apps/book-server/src/services/PageService Expand file tree Collapse file tree 1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -335,10 +335,21 @@ export class PageService implements Service {
335
335
} )
336
336
: null
337
337
338
- if ( parentPage && parentPage . fk_book_id !== book . id ) {
338
+ if ( parentPage && parentPage ? .fk_book_id !== book . id ) {
339
339
throw new ConfilctError ( 'Not related parent page' )
340
340
}
341
341
342
+ if ( parentPage && parentPage . type !== 'folder' ) {
343
+ await this . mongo . page . update ( {
344
+ where : {
345
+ id : parentPage . id ,
346
+ } ,
347
+ data : {
348
+ type : 'folder' ,
349
+ } ,
350
+ } )
351
+ }
352
+
342
353
const targetPage = await this . mongo . page . update ( {
343
354
where : {
344
355
id : page . id ,
@@ -408,7 +419,7 @@ export class PageService implements Service {
408
419
throw new BadRequestError ( 'Already deleted' )
409
420
}
410
421
411
- await this . mongo . page . update ( {
422
+ const deletedPage = await this . mongo . page . update ( {
412
423
where : {
413
424
id : page . id ,
414
425
} ,
@@ -418,6 +429,30 @@ export class PageService implements Service {
418
429
updated_at : new Date ( ) ,
419
430
} ,
420
431
} )
432
+
433
+ const siblings = await this . mongo . page . findMany ( {
434
+ where : {
435
+ parent_id : page . parent_id ,
436
+ is_deleted : false ,
437
+ id : {
438
+ not : deletedPage . id ,
439
+ } ,
440
+ } ,
441
+ orderBy : [ { index : 'asc' } , { updated_at : 'desc' } ] ,
442
+ } )
443
+
444
+ const updateSiblings = siblings . map ( ( sibling , index ) => {
445
+ return this . mongo . page . update ( {
446
+ where : {
447
+ id : sibling . id ,
448
+ } ,
449
+ data : {
450
+ index,
451
+ } ,
452
+ } )
453
+ } )
454
+
455
+ await Promise . all ( updateSiblings )
421
456
}
422
457
}
423
458
You can’t perform that action at this time.
0 commit comments