Add SortOrder enum and enhance Service query with sorting and filtering options
This commit is contained in:
@@ -29,4 +29,9 @@ export const builder = new SchemaBuilder<{
|
||||
},
|
||||
});
|
||||
|
||||
export const SortOrder = builder.enumType('SortOrder', {
|
||||
values: ['asc', 'desc'],
|
||||
});
|
||||
|
||||
|
||||
builder.addScalarType('DateTime', DateTimeResolver, {});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { builder, prisma } from './graphql.builder';
|
||||
import { builder, prisma, SortOrder } from './graphql.builder';
|
||||
|
||||
builder.prismaObject('User', {
|
||||
fields: (t) => ({
|
||||
@@ -224,6 +224,42 @@ builder.queryType({
|
||||
}),
|
||||
services: t.prismaField({
|
||||
type: ['Service'],
|
||||
args: {
|
||||
where: t.arg({
|
||||
type: builder.inputType('ServiceWhereInput', {
|
||||
fields: (t) => ({
|
||||
// search by name contains
|
||||
name: t.string(),
|
||||
// search by name starts with
|
||||
nameStartsWith: t.string(),
|
||||
// search by name ends with
|
||||
nameEndsWith: t.string(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
orderBy: t.arg({
|
||||
type: builder.inputType('ServiceOrderByInput', {
|
||||
fields: (t) => ({
|
||||
rating: t.field({
|
||||
type: SortOrder,
|
||||
}),
|
||||
price: t.field({
|
||||
type: SortOrder,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cursor: t.arg({
|
||||
type: builder.inputType('ServiceWhereUniqueInput', {
|
||||
fields: (t) => ({
|
||||
// Define fields to match your `ServiceWhereUniqueInput` structure.
|
||||
name: t.string(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
take: t.arg.int(),
|
||||
skip: t.arg.int(),
|
||||
},
|
||||
resolve: (query, root, args, ctx, info) => {
|
||||
return prisma.service.findMany({
|
||||
...query,
|
||||
|
||||
@@ -3,7 +3,13 @@ import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.enableCors({
|
||||
origin: '*',
|
||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 204,
|
||||
credentials: true,
|
||||
});
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
0
src/middlewares/cors.middleware.ts
Normal file
0
src/middlewares/cors.middleware.ts
Normal file
Reference in New Issue
Block a user