refactor: adding JSON import/export functions to UserCollections module (HBE-169) (#37)

* feat: created exportUserCollectionsToJSON mutation for UserCollection module

* chore: added comments to export functions

* chore: added type and user ownership checking to creation methods

* chore: replaced request property with spread request object instead

* chore: completed all changes requested in inital review of PR

* chore: explicitly exporting request title in export function

* chore: explicitly exporting request title in export function

* chore: added codegen folder to gitignore

* chore: removed gql-code gen file from repo
This commit is contained in:
Balu Babu
2023-03-14 18:31:47 +05:30
committed by GitHub
parent e5002b4ef3
commit be46ed2686
6 changed files with 352 additions and 14 deletions

View File

@@ -24,6 +24,7 @@ import { PaginationArgs } from 'src/types/input-types.args';
import {
CreateChildUserCollectionArgs,
CreateRootUserCollectionArgs,
ImportUserCollectionsFromJSONArgs,
MoveUserCollectionArgs,
RenameUserCollectionsArgs,
UpdateUserCollectionArgs,
@@ -139,6 +140,32 @@ export class UserCollectionResolver {
return userCollection.right;
}
@Query(() => String, {
description:
'Returns the JSON string giving the collections and their contents of a user',
})
@UseGuards(GqlAuthGuard)
async exportUserCollectionsToJSON(
@GqlUser() user: AuthUser,
@Args({
type: () => ID,
name: 'collectionID',
description: 'ID of the user collection',
nullable: true,
defaultValue: null,
})
collectionID: string,
) {
const jsonString =
await this.userCollectionService.exportUserCollectionsToJSON(
user.uid,
collectionID,
);
if (E.isLeft(jsonString)) throwErr(jsonString.left as string);
return jsonString.right;
}
// Mutations
@Mutation(() => UserCollection, {
description: 'Creates root REST user collection(no parent user collection)',
@@ -300,6 +327,25 @@ export class UserCollectionResolver {
return res.right;
}
@Mutation(() => Boolean, {
description: 'Import collections from JSON string to the specified Team',
})
@UseGuards(GqlAuthGuard)
async importUserCollectionsFromJSON(
@Args() args: ImportUserCollectionsFromJSONArgs,
@GqlUser() user: AuthUser,
) {
const importedCollection =
await this.userCollectionService.importCollectionsFromJSON(
args.jsonString,
user.uid,
args.parentCollectionID,
args.reqType,
);
if (E.isLeft(importedCollection)) throwErr(importedCollection.left);
return importedCollection.right;
}
// Subscriptions
@Subscription(() => UserCollection, {
description: 'Listen for User Collection Creation',