refactor, added slate, added editor, added book
This commit is contained in:
parent
bc250e73bb
commit
029b7e9353
33 changed files with 714 additions and 496 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
import { BookChapterManyOutput, QueryBookChapterManyArgs } from '@generated/types';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { toBookChapterSchema } from './mappers/bookChapterMapper';
|
||||
|
||||
export async function BookChapterManyResolver(
|
||||
|
|
@ -9,11 +10,14 @@ export async function BookChapterManyResolver(
|
|||
{ identity }: IdentityContext
|
||||
): Promise<BookChapterManyOutput> {
|
||||
const { bookId, filter } = input;
|
||||
const terms = filter.terms?.toLowerCase();
|
||||
|
||||
const bookChapterWhere: Prisma.BookChapterWhereInput = {
|
||||
AND: [{ bookId }, { OR: terms != null ? [{ title: { contains: terms } }] : undefined }]
|
||||
};
|
||||
|
||||
const items = await prisma.bookChapter.findMany({
|
||||
where: {
|
||||
bookId
|
||||
},
|
||||
where: bookChapterWhere,
|
||||
skip: filter.offset ?? 0,
|
||||
take: filter.size ?? 10
|
||||
});
|
||||
27
app/server/graphql/resolvers/bookCreateResolver.ts
Normal file
27
app/server/graphql/resolvers/bookCreateResolver.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { ensureIdentity } from '@app/server/helpers';
|
||||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma, uuid } from '@app/server/prisma/client';
|
||||
import { Book, MutationBookCreateArgs } from '@generated/types';
|
||||
import { toBookSchema } from './mappers/bookMapper';
|
||||
|
||||
export async function BookCreateResolver(
|
||||
_: any,
|
||||
{ input }: MutationBookCreateArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<Book> {
|
||||
ensureIdentity(identity);
|
||||
|
||||
console.log(input.title.length);
|
||||
if (input.title.length > 60) throw new Error('Title is too long.');
|
||||
if (input.description.length > 900) throw new Error('Description is too long.');
|
||||
|
||||
const model = await prisma.book.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
authorId: identity.id
|
||||
}
|
||||
});
|
||||
return toBookSchema(model);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
import { BookManyOutput, QueryBookManyArgs } from '@generated/types';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { toBookSchema } from './mappers/bookMapper';
|
||||
|
||||
export async function BookManyResolver(
|
||||
|
|
@ -11,19 +12,19 @@ export async function BookManyResolver(
|
|||
const { filter } = input;
|
||||
const terms = filter.terms?.toLowerCase();
|
||||
|
||||
const bookWhere: Prisma.BookWhereInput = {
|
||||
OR:
|
||||
terms != null ? [{ title: { contains: terms } }, { author: { username: terms } }] : undefined
|
||||
};
|
||||
|
||||
const items = await prisma.book.findMany({
|
||||
where: {
|
||||
OR:
|
||||
terms != null
|
||||
? [{ title: { contains: terms } }, { author: { username: terms } }]
|
||||
: undefined
|
||||
},
|
||||
where: bookWhere,
|
||||
skip: filter.offset ?? 0,
|
||||
take: filter.size ?? 10
|
||||
});
|
||||
|
||||
return {
|
||||
items: await Promise.all(items.map(value => toBookSchema(value))),
|
||||
total: items.length
|
||||
total: await prisma.book.count({ where: bookWhere })
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue