feat: duplicate team and user collections (#4207)

* chore: created new mutation for team-collection duplication

* feat: completed duplication function in TeamCollection module

* feat: user-collection duplication complete

* chore: changed duplicated title suffix for collections

* chore: added return type to argument for duplication mutation in user-collections

* chore: capitalized duplicate in duplicate collection service4 methods

* chore: changed target of hopp-old-backend service to prod
This commit is contained in:
Balu Babu
2024-07-24 21:55:08 +05:30
committed by GitHub
parent df730e4d21
commit 9cde6c597b
4 changed files with 122 additions and 0 deletions

View File

@@ -1138,4 +1138,45 @@ export class UserCollectionService {
return E.left(USER_COLL_NOT_FOUND);
}
}
/**
* Duplicate a User Collection
*
* @param collectionID The Collection ID
* @returns Boolean of duplication status
*/
async duplicateUserCollection(
collectionID: string,
userID: string,
reqType: DBReqType,
) {
const collection = await this.getUserCollection(collectionID);
if (E.isLeft(collection)) return E.left(USER_COLL_NOT_FOUND);
if (collection.right.userUid !== userID) return E.left(USER_NOT_OWNER);
if (collection.right.type !== reqType)
return E.left(USER_COLL_NOT_SAME_TYPE);
const collectionJSONObject = await this.exportUserCollectionToJSONObject(
collection.right.userUid,
collectionID,
);
if (E.isLeft(collectionJSONObject))
return E.left(collectionJSONObject.left);
const result = await this.importCollectionsFromJSON(
JSON.stringify([
{
...collectionJSONObject.right,
name: `${collection.right.title} - Duplicate`,
},
]),
userID,
collection.right.parentID,
reqType,
);
if (E.isLeft(result)) return E.left(result.left as string);
return E.right(true);
}
}