chore: completed query to fetch all user created shared-requests
This commit is contained in:
@@ -18,6 +18,7 @@ import { throwErr } from 'src/utils';
|
||||
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
||||
import { AuthUser } from 'src/types/AuthUser';
|
||||
import { SkipThrottle } from '@nestjs/throttler';
|
||||
import { PaginationArgs } from 'src/types/input-types.args';
|
||||
|
||||
@UseGuards(GqlThrottlerGuard)
|
||||
@Resolver(() => SharedRequest)
|
||||
@@ -47,6 +48,17 @@ export class SharedRequestResolver {
|
||||
return result.right;
|
||||
}
|
||||
|
||||
@Query(() => [SharedRequest], {
|
||||
description: 'List all shared-request the current user has generated',
|
||||
})
|
||||
@UseGuards(GqlAuthGuard)
|
||||
async mySharedRequest(
|
||||
@GqlUser() user: AuthUser,
|
||||
@Args() args: PaginationArgs,
|
||||
) {
|
||||
return this.sharedRequestService.fetchUserSharedRequests(user.uid, args);
|
||||
}
|
||||
|
||||
/* Mutations */
|
||||
@Mutation(() => SharedRequest, {
|
||||
description: 'Create a shared-request for the given request.',
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from 'src/errors';
|
||||
import { stringToJson } from 'src/utils';
|
||||
import { AuthUser } from 'src/types/AuthUser';
|
||||
import { PaginationArgs } from 'src/types/input-types.args';
|
||||
|
||||
const SHORT_CODE_LENGTH = 12;
|
||||
const SHORT_CODE_CHARS =
|
||||
@@ -125,4 +126,31 @@ export class SharedRequestService {
|
||||
|
||||
return E.right(this.cast(createdSharedRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch SharedRequest created by a User
|
||||
*
|
||||
* @param uid User Uid
|
||||
* @param args Pagination arguments
|
||||
* @returns Array of SharedRequest
|
||||
*/
|
||||
async fetchUserSharedRequests(uid: string, args: PaginationArgs) {
|
||||
const sharedRequests = await this.prisma.shortcode.findMany({
|
||||
where: {
|
||||
creatorUid: uid,
|
||||
},
|
||||
orderBy: {
|
||||
createdOn: 'desc',
|
||||
},
|
||||
skip: args.cursor ? 1 : 0,
|
||||
take: args.take,
|
||||
cursor: args.cursor ? { id: args.cursor } : undefined,
|
||||
});
|
||||
|
||||
const fetchedSharedRequests: SharedRequest[] = sharedRequests.map((code) =>
|
||||
this.cast(code),
|
||||
);
|
||||
|
||||
return fetchedSharedRequests;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user