added chapter view, fixes, added ratings, added chapter updates/deletions
This commit is contained in:
parent
029b7e9353
commit
4801cf3a13
34 changed files with 1345 additions and 191 deletions
102
app/server/graphql/resolvers/ratingSetResolver.ts
Normal file
102
app/server/graphql/resolvers/ratingSetResolver.ts
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
import { ensureIdentity } from '@app/server/helpers';
|
||||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma, uuid } from '@app/server/prisma/client';
|
||||
import { MutationRatingSetArgs, RatingType } from '@generated/types';
|
||||
|
||||
export async function BookCreateResolver(
|
||||
_: any,
|
||||
{ input }: MutationRatingSetArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<void> {
|
||||
ensureIdentity(identity);
|
||||
|
||||
if (input.bookId != null) {
|
||||
const rating = await prisma.rating.findUnique({
|
||||
where: {
|
||||
userId_bookId: {
|
||||
userId: identity.id,
|
||||
bookId: input.bookId
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (rating != null && input.ratingType !== RatingType.None) {
|
||||
await prisma.rating.update({
|
||||
where: { id: rating.id },
|
||||
data: {
|
||||
type: input.ratingType
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.ratingType === RatingType.None) {
|
||||
await prisma.rating.delete({
|
||||
where: {
|
||||
userId_bookId: {
|
||||
userId: identity.id,
|
||||
bookId: input.bookId
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await prisma.rating.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId: identity.id,
|
||||
bookId: input.bookId,
|
||||
type: input.ratingType
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.bookChapterId != null) {
|
||||
const rating = await prisma.rating.findUnique({
|
||||
where: {
|
||||
userId_bookChapterId: {
|
||||
userId: identity.id,
|
||||
bookChapterId: input.bookChapterId
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (rating != null && input.ratingType !== RatingType.None) {
|
||||
await prisma.rating.update({
|
||||
where: { id: rating.id },
|
||||
data: {
|
||||
type: input.ratingType
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.ratingType === RatingType.None) {
|
||||
await prisma.rating.delete({
|
||||
where: {
|
||||
userId_bookChapterId: {
|
||||
userId: identity.id,
|
||||
bookChapterId: input.bookChapterId
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await prisma.rating.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId: identity.id,
|
||||
bookChapterId: input.bookChapterId,
|
||||
type: input.ratingType
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error('Invalid Rating id input.');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue