thang an bi ngu

This commit is contained in:
2024-10-06 20:42:02 +07:00
parent 7b678a7ef2
commit 83b453c3b8
9 changed files with 202 additions and 23 deletions

View File

@@ -1,11 +1,13 @@
import { Module } from '@nestjs/common';
import { GraphqlModule } from './graphql/graphql.module';
import { ClerkModule } from './clerk/clerk.module';
import { RestfulModule } from './restful/restful.module';
@Module({
imports: [
GraphqlModule, // GraphQL setup
ClerkModule, // Clerk setup
RestfulModule, // RESTful API module
],
})
export class AppModule {}

View File

@@ -2,6 +2,7 @@ import SchemaBuilder from '@pothos/core';
import PrismaPlugin from '@pothos/plugin-prisma';
import PrismaUtils from '@pothos/plugin-prisma-utils';
import { DateTimeResolver } from 'graphql-scalars';
import { GraphQLInt } from 'graphql';
import { PrismaService } from '../prisma/prisma.service';
import type PrismaTypes from '../types/pothos.generated';
import { getDatamodel } from '../types/pothos.generated';
@@ -32,6 +33,4 @@ export const builder = new SchemaBuilder<{
export const SortOrder = builder.enumType('SortOrder', {
values: ['asc', 'desc'],
});
builder.addScalarType('DateTime', DateTimeResolver, {});
builder.addScalarType('DateTime', DateTimeResolver, {});

View File

@@ -32,7 +32,25 @@ builder.prismaObject('User', {
builder.prismaObject('Order', {
fields: (t) => ({
id: t.exposeID('id'),
paymentId: t.exposeString('paymentId'),
userId: t.exposeID('userId'),
serviceId: t.exposeID('serviceId'),
status: t.exposeString('status'),
total: t.expose('total', {
type: 'Int',
}),
createdAt: t.expose('createdAt', {
type: 'DateTime',
nullable: true,
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
nullable: true,
}),
user: t.relation('user'),
payment: t.relation('payment'),
service: t.relation('service'),
refundTicket: t.relation('refundTicket'),
}),
});
@@ -59,6 +77,45 @@ builder.prismaObject('Message', {
}),
});
builder.prismaObject('Payment', {
fields: (t) => ({
id: t.exposeID('id'),
amount: t.expose('amount', {
type: 'Float',
}),
status: t.exposeString('status'),
createdAt: t.expose('createdAt', {
type: 'DateTime',
nullable: true,
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
nullable: true,
}),
order: t.relation('Order'),
}),
});
builder.prismaObject('RefundTicket', {
fields: (t) => ({
id: t.exposeID('id'),
orderId: t.exposeID('orderId'),
amount: t.expose('amount', {
type: 'Float',
}),
status: t.exposeString('status'),
createdAt: t.expose('createdAt', {
type: 'DateTime',
nullable: true,
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
nullable: true,
}),
order: t.relation('order'),
}),
});
builder.prismaObject('Service', {
fields: (t) => ({
id: t.exposeID('id'),
@@ -146,6 +203,7 @@ builder.prismaObject('ChatRoom', {
builder.prismaObject('CenterStaff', {
fields: (t) => ({
staffId: t.exposeID('staffId'),
staff: t.relation('staff'),
centerId: t.exposeID('centerId'),
serviceId: t.exposeID('serviceId'),
}),
@@ -261,28 +319,27 @@ builder.queryType({
take: t.arg.int(),
skip: t.arg.int(),
},
resolve: (query, root, args, ctx, info) => {
resolve: async (query, root, args, ctx, info) => {
return prisma.service.findMany({
// process filters
// handle where condition
where: {
name: {
contains: args.where?.nameContain as string,
startsWith: args.where?.nameStartsWith as string,
endsWith: args.where?.nameEndsWith as string,
contains: args.where?.nameContain as string | undefined,
startsWith: args.where?.nameStartsWith as string | undefined,
endsWith: args.where?.nameEndsWith as string | undefined,
},
},
// process order by
// handle orderBy condition
orderBy: {
rating: args.orderBy?.rating as Prisma.SortOrder,
price: args.orderBy?.price as Prisma.SortOrder,
},
// process pagination
cursor: args.cursor as Prisma.ServiceWhereUniqueInput,
take: args.take as number,
skip: args.skip as number,
...query,
// handle pagination
cursor: args.cursor as Prisma.ServiceWhereUniqueInput | undefined,
take: args.take as number | undefined,
skip: args.skip as number | undefined,
});
},
},
}),
service: t.prismaField({
type: 'Service',
@@ -361,7 +418,7 @@ builder.queryType({
// if (!args.data) {
// throw new Error('Data input is required');
// }
// return prisma.user.create({
// ...query,
// data: args.data as Prisma.UserCreateInput, // Explicit type casting to match Prisma's expectation

View File

@@ -1,10 +1,36 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { cors } from './common/utils/cors.utils';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
// Import DateTime scalar if necessary
require('./common/utils/datetime.utils');
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors(cors);
await app.listen(3069);
const config = new DocumentBuilder()
.setTitle('EPESS API')
.setDescription('API documentation for EPESS application')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
document.paths['/graphql'] = {
get: {
summary: 'GraphQL Playground',
description: 'Access the GraphQL Playground to interact with the GraphQL API.',
responses: {
'200': {
description: 'GraphQL Playground',
},
},
},
};
await app.listen(3000);
}
bootstrap();

View File

@@ -1,5 +1,9 @@
import { Module } from '@nestjs/common';
import { RestfulController } from './restful.controller';
import { RestfulService } from './restful.service';
@Module({
imports: [],
controllers: [RestfulController],
providers: [RestfulService],
})
export class RestfulModule {}
export class RestfulModule {}

View File

@@ -0,0 +1,31 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class RestfulService {
getAllItems() {
// Implementation to get all items
return []; // Replace with actual logic
}
getItem(id: string) {
// Implementation to get a single item by id
return {}; // Replace with actual logic
}
createItem(createDto: any) {
// Implementation to create a new item
return {}; // Replace with actual logic
}
updateItem(id: string, updateDto: any) {
// Implementation to update an item by id
return {}; // Replace with actual logic
}
deleteItem(id: string) {
// Implementation to delete an item by id
return {}; // Replace with actual logic
}
}
export default RestfulService;