added resolvers, updated model, updated navbar
This commit is contained in:
parent
a8375b99c2
commit
1d40d7e15f
23 changed files with 439 additions and 301 deletions
29
app/server/graphql/resolvers/bookManyResolver.ts
Normal file
29
app/server/graphql/resolvers/bookManyResolver.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
import { BookManyOutput, QueryBookManyArgs } from '@generated/types';
|
||||
import { toBookSchema } from './mappers/bookMapper';
|
||||
|
||||
export async function BookManyResolver(
|
||||
_: any,
|
||||
{ input }: QueryBookManyArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<BookManyOutput> {
|
||||
const { filter } = input;
|
||||
const terms = filter.terms?.toLowerCase();
|
||||
|
||||
const items = await prisma.book.findMany({
|
||||
where: {
|
||||
OR:
|
||||
terms != null
|
||||
? [{ title: { contains: terms } }, { author: { username: terms } }]
|
||||
: undefined
|
||||
},
|
||||
skip: filter.offset ?? 0,
|
||||
take: filter.size ?? 10
|
||||
});
|
||||
|
||||
return {
|
||||
items: await Promise.all(items.map(value => toBookSchema(value))),
|
||||
total: items.length
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue