refactor: modifed return types of mutation/subscriptions in UserCollections (#57)

* refactor: modifed userCollectionRemoved subscription to return custom return type

* chore: created new return type for export to JSON mutation in UserCollection

* refactor: added reqType to exportUserCollectionsToJSON query

* chore: remove duplicate enum in user-collection.model.ts file
This commit is contained in:
Balu Babu
2023-03-29 15:50:48 +05:30
committed by GitHub
parent b6950332ad
commit ea93162056
4 changed files with 63 additions and 10 deletions

View File

@@ -16,6 +16,8 @@ import { AuthUser } from 'src/types/AuthUser';
import { UserCollectionService } from './user-collection.service';
import {
UserCollection,
UserCollectionExportJSONData,
UserCollectionRemovedData,
UserCollectionReorderData,
} from './user-collections.model';
import { throwErr } from 'src/utils';
@@ -143,7 +145,7 @@ export class UserCollectionResolver {
return userCollection.right;
}
@Query(() => String, {
@Query(() => UserCollectionExportJSONData, {
description:
'Returns the JSON string giving the collections and their contents of a user',
})
@@ -158,11 +160,18 @@ export class UserCollectionResolver {
defaultValue: null,
})
collectionID: string,
@Args({
type: () => ReqType,
name: 'collectionType',
description: 'Type of the user collection',
})
collectionType: ReqType,
) {
const jsonString =
await this.userCollectionService.exportUserCollectionsToJSON(
user.uid,
collectionID,
collectionType,
);
if (E.isLeft(jsonString)) throwErr(jsonString.left as string);
@@ -371,7 +380,7 @@ export class UserCollectionResolver {
return this.pubSub.asyncIterator(`user_coll/${user.uid}/updated`);
}
@Subscription(() => ID, {
@Subscription(() => UserCollectionRemovedData, {
description: 'Listen to when a User Collection has been deleted',
resolve: (value) => value,
})