chore: export single User/Team Collection (#4359)

* chore: added query to export single TeamCollection data

* chore: added query to export single UserCollection data

* chore: fixed typo

* chore: completed requested changes in PR review
This commit is contained in:
Balu Babu
2024-09-27 16:55:47 +05:30
committed by GitHub
parent 421e6b76c9
commit fc37196354
5 changed files with 68 additions and 3 deletions

View File

@@ -102,6 +102,36 @@ export class TeamCollectionResolver {
return jsonString.right;
}
@Query(() => String, {
description:
'Returns a JSON string of all the contents of a Team Collection',
})
@UseGuards(GqlAuthGuard, GqlTeamMemberGuard)
@RequiresTeamRole(
TeamMemberRole.VIEWER,
TeamMemberRole.EDITOR,
TeamMemberRole.OWNER,
)
async exportCollectionToJSON(
@Args({ name: 'teamID', description: 'ID of the team', type: () => ID })
teamID: string,
@Args({
name: 'collectionID',
description: 'ID of the collection',
type: () => ID,
})
collectionID: string,
) {
const collectionData =
await this.teamCollectionService.exportCollectionToJSONObject(
teamID,
collectionID,
);
if (E.isLeft(collectionData)) throwErr(collectionData.left as string);
return JSON.stringify(collectionData.right);
}
@Query(() => [TeamCollection], {
description: 'Returns the collections of a team',
})

View File

@@ -103,10 +103,10 @@ export class TeamCollectionService {
* @param collectionID The Collection ID
* @returns A JSON string containing all the contents of a collection
*/
private async exportCollectionToJSONObject(
async exportCollectionToJSONObject(
teamID: string,
collectionID: string,
) {
): Promise<E.Right<CollectionFolder> | E.Left<string>> {
const collection = await this.getCollection(collectionID);
if (E.isLeft(collection)) return E.left(TEAM_INVALID_COLL_ID);

View File

@@ -186,6 +186,30 @@ export class UserCollectionResolver {
return jsonString.right;
}
@Query(() => String, {
description:
'Returns a JSON string of all the contents of a User Collection',
})
@UseGuards(GqlAuthGuard)
async exportUserCollectionToJSON(
@GqlUser() user: AuthUser,
@Args({
type: () => ID,
name: 'collectionID',
description: 'ID of the user collection',
})
collectionID: string,
) {
const jsonString =
await this.userCollectionService.exportUserCollectionToJSONObject(
user.uid,
collectionID,
);
if (E.isLeft(jsonString)) throwErr(jsonString.left as string);
return JSON.stringify(jsonString.right);
}
// Mutations
@Mutation(() => UserCollection, {
description: 'Creates root REST user collection(no parent user collection)',

View File

@@ -836,7 +836,7 @@ export class UserCollectionService {
* @param collectionID The Collection ID
* @returns A JSON string containing all the contents of a collection
*/
private async exportUserCollectionToJSONObject(
async exportUserCollectionToJSONObject(
userUID: string,
collectionID: string,
): Promise<E.Left<string> | E.Right<CollectionFolder>> {

View File

@@ -116,6 +116,17 @@ export const getGqlArg = <ArgName extends string>(
);
/**
* To the daring adventurer who has stumbled upon this relic of code... welcome.
* Many have gazed upon its depths, yet few have returned with answers.
* I could have deleted it, but that felt... too easy, too final.
*
* If you're still reading, perhaps you're the one destined to unravel its secrets.
* Or, maybe you're like me—content to let it linger, a puzzle for the ages.
* The choice is yours, but beware... once you start, there is no turning back.
*
* PLEASE, NO ONE KNOWS HOW THIS WORKS...
* -- Balu, whispering from the great beyond... probably still trying to understand this damn thing.
*
* Sequences an array of TaskEither values while maintaining an array of all the error values
* @param arr Array of TaskEithers
* @returns A TaskEither saying all the errors possible on the left or all the success values on the right