thang an bi ngu
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
const { environments } = require('eslint-plugin-prettier');
|
||||
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
|
||||
64
package-lock.json
generated
64
package-lock.json
generated
@@ -23,6 +23,7 @@
|
||||
"@nestjs/graphql": "^12.2.0",
|
||||
"@nestjs/jwt": "^10.2.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/swagger": "^7.4.2",
|
||||
"@pothos/core": "^4.2.0",
|
||||
"@pothos/plugin-add-graphql": "^4.1.0",
|
||||
"@pothos/plugin-prisma": "^4.2.1",
|
||||
@@ -40,6 +41,7 @@
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"type-graphql": "^2.0.0-rc.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -4910,6 +4912,12 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/tsdoc": {
|
||||
"version": "0.15.0",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.15.0.tgz",
|
||||
"integrity": "sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@nestjs/apollo": {
|
||||
"version": "12.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/apollo/-/apollo-12.2.0.tgz",
|
||||
@@ -5303,6 +5311,39 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@nestjs/swagger": {
|
||||
"version": "7.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-7.4.2.tgz",
|
||||
"integrity": "sha512-Mu6TEn1M/owIvAx2B4DUQObQXqo2028R2s9rSZ/hJEgBK95+doTwS0DjmVA2wTeZTyVtXOoN7CsoM5pONBzvKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@microsoft/tsdoc": "^0.15.0",
|
||||
"@nestjs/mapped-types": "2.0.5",
|
||||
"js-yaml": "4.1.0",
|
||||
"lodash": "4.17.21",
|
||||
"path-to-regexp": "3.3.0",
|
||||
"swagger-ui-dist": "5.17.14"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@fastify/static": "^6.0.0 || ^7.0.0",
|
||||
"@nestjs/common": "^9.0.0 || ^10.0.0",
|
||||
"@nestjs/core": "^9.0.0 || ^10.0.0",
|
||||
"class-transformer": "*",
|
||||
"class-validator": "*",
|
||||
"reflect-metadata": "^0.1.12 || ^0.2.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@fastify/static": {
|
||||
"optional": true
|
||||
},
|
||||
"class-transformer": {
|
||||
"optional": true
|
||||
},
|
||||
"class-validator": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/testing": {
|
||||
"version": "10.4.4",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-10.4.4.tgz",
|
||||
@@ -7212,7 +7253,6 @@
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||
"dev": true,
|
||||
"license": "Python-2.0"
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
@@ -11602,7 +11642,6 @@
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
@@ -14247,6 +14286,27 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/swagger-ui-dist": {
|
||||
"version": "5.17.14",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.17.14.tgz",
|
||||
"integrity": "sha512-CVbSfaLpstV65OnSjbXfVd6Sta3q3F7Cj/yYuvHMp1P90LztOLs6PfUnKEVAeiIVQt9u2SaPwv0LiH/OyMjHRw==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/swagger-ui-express": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-5.0.1.tgz",
|
||||
"integrity": "sha512-SrNU3RiBGTLLmFU8GIJdOdanJTl4TOmT27tt3bWWHppqYmAZ6IDuEuBvMU6nZq0zLEe6b/1rACXCgLZqO6ZfrA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"swagger-ui-dist": ">=5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= v0.10.32"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"express": ">=4.0.0 || >=5.0.0-beta"
|
||||
}
|
||||
},
|
||||
"node_modules/swap-case": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/swap-case/-/swap-case-2.0.2.tgz",
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"@nestjs/graphql": "^12.2.0",
|
||||
"@nestjs/jwt": "^10.2.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/swagger": "^7.4.2",
|
||||
"@pothos/core": "^4.2.0",
|
||||
"@pothos/plugin-add-graphql": "^4.1.0",
|
||||
"@pothos/plugin-prisma": "^4.2.1",
|
||||
@@ -54,6 +55,7 @@
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"type-graphql": "^2.0.0-rc.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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, {});
|
||||
@@ -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,26 +319,25 @@ 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,
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
28
src/main.ts
28
src/main.ts
@@ -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();
|
||||
|
||||
@@ -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 {}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user