@@ -216,7 +216,11 @@ export class TeamCollectionService {
216216 await this . prisma . $transaction ( async ( tx ) => {
217217 try {
218218 // lock the rows
219- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , teamID , parentID ) ;
219+ await this . prisma . lockTeamCollectionByTeamAndParent (
220+ tx ,
221+ teamID ,
222+ parentID ,
223+ ) ;
220224
221225 // Get the last order index
222226 const lastEntry = await tx . teamCollection . findFirst ( {
@@ -397,15 +401,18 @@ export class TeamCollectionService {
397401 * @param collectionID The collection ID
398402 * @returns An Either of the Collection details
399403 */
400- async getCollection ( collectionID : string , tx : Prisma . TransactionClient | null = null ) {
404+ async getCollection (
405+ collectionID : string ,
406+ tx : Prisma . TransactionClient | null = null ,
407+ ) {
401408 try {
402- const teamCollection = await ( tx || this . prisma ) . teamCollection . findUniqueOrThrow (
403- {
404- where : {
405- id : collectionID ,
406- } ,
409+ const teamCollection = await (
410+ tx || this . prisma
411+ ) . teamCollection . findUniqueOrThrow ( {
412+ where : {
413+ id : collectionID ,
407414 } ,
408- ) ;
415+ } ) ;
409416 return E . right ( teamCollection ) ;
410417 } catch ( error ) {
411418 return E . left ( TEAM_COLL_NOT_FOUND ) ;
@@ -469,7 +476,11 @@ export class TeamCollectionService {
469476 teamCollection = await this . prisma . $transaction ( async ( tx ) => {
470477 try {
471478 // lock the rows
472- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , teamID , parentID ) ;
479+ await this . prisma . lockTeamCollectionByTeamAndParent (
480+ tx ,
481+ teamID ,
482+ parentID ,
483+ ) ;
473484
474485 // fetch last collection
475486 const lastCollection = await tx . teamCollection . findFirst ( {
@@ -552,15 +563,19 @@ export class TeamCollectionService {
552563 await this . prisma . $transaction ( async ( tx ) => {
553564 try {
554565 // lock the rows
555- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , collection . teamID , collection . parentID ) ;
566+ await this . prisma . lockTeamCollectionByTeamAndParent (
567+ tx ,
568+ collection . teamID ,
569+ collection . parentID ,
570+ ) ;
556571
557572 const deletedCollection = await tx . teamCollection . delete ( {
558573 where : { id : collection . id } ,
559574 } ) ;
560-
575+
561576 // if collection is deleted, update siblings orderIndexes
562577 // if collection was deleted before the transaction started (race condition), do not update siblings orderIndexes
563- if ( deletedCollection ) {
578+ if ( deletedCollection ) {
564579 // update siblings orderIndexes
565580 await tx . teamCollection . updateMany ( {
566581 where : {
@@ -623,7 +638,7 @@ export class TeamCollectionService {
623638 ) ;
624639
625640 return E . right ( true ) ;
626- }
641+ }
627642
628643 /**
629644 * Change parentID of TeamCollection's
@@ -638,11 +653,10 @@ export class TeamCollectionService {
638653 newParentID : string | null ,
639654 ) {
640655 // fetch last collection
641- const lastCollectionUnderNewParent =
642- await tx . teamCollection . findFirst ( {
643- where : { teamID : collection . teamID , parentID : newParentID } ,
644- orderBy : { orderIndex : 'desc' } ,
645- } ) ;
656+ const lastCollectionUnderNewParent = await tx . teamCollection . findFirst ( {
657+ where : { teamID : collection . teamID , parentID : newParentID } ,
658+ orderBy : { orderIndex : 'desc' } ,
659+ } ) ;
646660
647661 // decrement orderIndex of all next sibling collections from original collection
648662 await tx . teamCollection . updateMany ( {
@@ -736,47 +750,52 @@ export class TeamCollectionService {
736750 const collection = await this . getCollection ( collectionID , tx ) ;
737751 if ( E . isLeft ( collection ) ) return E . left ( collection . left ) ;
738752 // lock the rows of the collection and its siblings
739- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , collection . right . teamID , collection . right . parentID ) ;
753+ await this . prisma . lockTeamCollectionByTeamAndParent (
754+ tx ,
755+ collection . right . teamID ,
756+ collection . right . parentID ,
757+ ) ;
740758 // destCollectionID == null i.e move collection to root
741759 if ( ! destCollectionID ) {
742760 if ( ! collection . right . parentID ) {
743761 // collection is a root collection
744762 // Throw error if collection is already a root collection
745763 return E . left ( TEAM_COL_ALREADY_ROOT ) ;
746764 }
747-
765+
748766 // Change parent from child to root i.e child collection becomes a root collection
749767 // Move child collection into root and update orderIndexes for root teamCollections
750768 const updatedCollection = await this . changeParentAndUpdateOrderIndex (
751769 tx ,
752770 collection . right ,
753771 null ,
754772 ) ;
755- if ( E . isLeft ( updatedCollection ) ) return E . left ( updatedCollection . left ) ;
756-
773+ if ( E . isLeft ( updatedCollection ) )
774+ return E . left ( updatedCollection . left ) ;
775+
757776 this . pubsub . publish (
758777 `team_coll/${ collection . right . teamID } /coll_moved` ,
759778 updatedCollection . right ,
760779 ) ;
761-
780+
762781 return E . right ( updatedCollection . right ) ;
763782 }
764-
783+
765784 // destCollectionID != null i.e move into another collection
766785 if ( collectionID === destCollectionID ) {
767786 // Throw error if collectionID and destCollectionID are the same
768787 return E . left ( TEAM_COLL_DEST_SAME ) ;
769788 }
770-
789+
771790 // Get collection details of destCollectionID
772791 const destCollection = await this . getCollection ( destCollectionID , tx ) ;
773792 if ( E . isLeft ( destCollection ) ) return E . left ( TEAM_COLL_NOT_FOUND ) ;
774-
793+
775794 // Check if collection and destCollection belong to the same user account
776795 if ( collection . right . teamID !== destCollection . right . teamID ) {
777796 return E . left ( TEAM_COLL_NOT_SAME_TEAM ) ;
778797 }
779-
798+
780799 // Check if collection is present on the parent tree for destCollection
781800 const checkIfParent = await this . isParent (
782801 collection . right ,
@@ -788,8 +807,12 @@ export class TeamCollectionService {
788807 }
789808
790809 // lock the rows of the destination collection and its siblings
791- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , destCollection . right . teamID , destCollection . right . parentID ) ;
792-
810+ await this . prisma . lockTeamCollectionByTeamAndParent (
811+ tx ,
812+ destCollection . right . teamID ,
813+ destCollection . right . parentID ,
814+ ) ;
815+
793816 // Change parent from null to teamCollection i.e collection becomes a child collection
794817 // Move root/child collection into another child collection and update orderIndexes of the previous parent
795818 const updatedCollection = await this . changeParentAndUpdateOrderIndex (
@@ -807,11 +830,7 @@ export class TeamCollectionService {
807830 return E . right ( updatedCollection . right ) ;
808831 } ) ;
809832 } catch ( error ) {
810-
811- console . error (
812- 'Error from TeamCollectionService.moveCollection' ,
813- error ,
814- ) ;
833+ console . error ( 'Error from TeamCollectionService.moveCollection' , error ) ;
815834 return E . left ( TEAM_COL_REORDERING_FAILED ) ;
816835 }
817836 }
@@ -823,7 +842,11 @@ export class TeamCollectionService {
823842 * @param teamID The Team ID (required when collectionID is null for root collections)
824843 * @returns Number of collections
825844 */
826- getCollectionCount ( collectionID : string , teamID : string , tx : Prisma . TransactionClient | null = null ) : Promise < number > {
845+ getCollectionCount (
846+ collectionID : string ,
847+ teamID : string ,
848+ tx : Prisma . TransactionClient | null = null ,
849+ ) : Promise < number > {
827850 return ( tx || this . prisma ) . teamCollection . count ( {
828851 where : { parentID : collectionID , teamID : teamID } ,
829852 } ) ;
@@ -867,7 +890,7 @@ export class TeamCollectionService {
867890
868891 // if collection is found, update orderIndexes of siblings
869892 // if collection was deleted before the transaction started (race condition), do not update siblings orderIndexes
870- if ( collectionInTx ) {
893+ if ( collectionInTx ) {
871894 // Step 1: Decrement orderIndex of all items that come after collection.orderIndex till end of list of items
872895 await tx . teamCollection . updateMany ( {
873896 where : {
@@ -881,7 +904,7 @@ export class TeamCollectionService {
881904 orderIndex : { decrement : 1 } ,
882905 } ,
883906 } ) ;
884-
907+
885908 // Step 2: Update orderIndex of collection to length of list
886909 await tx . teamCollection . update ( {
887910 where : { id : collection . right . id } ,
@@ -894,7 +917,6 @@ export class TeamCollectionService {
894917 } ,
895918 } ) ;
896919 }
897-
898920 } catch ( error ) {
899921 throw new ConflictException ( error ) ;
900922 }
@@ -927,7 +949,11 @@ export class TeamCollectionService {
927949 await this . prisma . $transaction ( async ( tx ) => {
928950 try {
929951 // Step 0: lock the rows
930- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , collection . right . teamID , collection . right . parentID ) ;
952+ await this . prisma . lockTeamCollectionByTeamAndParent (
953+ tx ,
954+ collection . right . teamID ,
955+ collection . right . parentID ,
956+ ) ;
931957
932958 const collectionInTx = await tx . teamCollection . findFirst ( {
933959 where : { id : collectionID } ,
@@ -940,10 +966,10 @@ export class TeamCollectionService {
940966
941967 // if collection and subsequentCollection are found, update orderIndexes of siblings
942968 // if collection or subsequentCollection was deleted before the transaction started (race condition), do not update siblings orderIndexes
943- if ( collectionInTx && subsequentCollectionInTx ) {
969+ if ( collectionInTx && subsequentCollectionInTx ) {
944970 // Step 1: Determine if we are moving collection up or down the list
945971 const isMovingUp =
946- subsequentCollectionInTx . orderIndex < collectionInTx . orderIndex ;
972+ subsequentCollectionInTx . orderIndex < collectionInTx . orderIndex ;
947973
948974 // Step 2: Update OrderIndex of items in list depending on moving up or down
949975 const updateFrom = isMovingUp
@@ -1490,7 +1516,11 @@ export class TeamCollectionService {
14901516
14911517 try {
14921518 await this . prisma . $transaction ( async ( tx ) => {
1493- await this . prisma . lockTeamCollectionByTeamAndParent ( tx , teamID , parentID ) ;
1519+ await this . prisma . lockTeamCollectionByTeamAndParent (
1520+ tx ,
1521+ teamID ,
1522+ parentID ,
1523+ ) ;
14941524
14951525 const collections = await tx . teamCollection . findMany ( {
14961526 where : { teamID, parentID } ,
0 commit comments