troi mua qua
This commit is contained in:
9
src/center/center.module.ts
Normal file
9
src/center/center.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { CenterSchema } from './center.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [CenterSchema],
|
||||||
|
exports: [CenterSchema],
|
||||||
|
})
|
||||||
|
export class CenterModule {}
|
||||||
60
src/center/center.schema.ts
Normal file
60
src/center/center.schema.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CenterSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PothosRef()
|
||||||
|
center() {
|
||||||
|
return this.builder.prismaObject('Center', {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID('id'),
|
||||||
|
centerOwnerId: t.exposeID('centerOwnerId'),
|
||||||
|
name: t.exposeString('name'),
|
||||||
|
description: t.exposeString('description'),
|
||||||
|
location: t.exposeString('location'),
|
||||||
|
individual: t.exposeBoolean('individual'),
|
||||||
|
createdAt: t.expose('createdAt', { type: 'Date' }),
|
||||||
|
updatedAt: t.expose('updatedAt', { type: 'Date' }),
|
||||||
|
services: t.relation('services'),
|
||||||
|
centerOwner: t.relation('centerOwner'),
|
||||||
|
chatRoom: t.relation('chatRoom'),
|
||||||
|
centerStaff: t.relation('CenterStaff'),
|
||||||
|
resume: t.relation('Resume'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pothos()
|
||||||
|
init(): void {
|
||||||
|
this.builder.queryFields((t) => ({
|
||||||
|
centers: t.prismaField({
|
||||||
|
type: [this.center()],
|
||||||
|
args: {
|
||||||
|
skip: t.arg.int(),
|
||||||
|
take: t.arg.int(),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args, ctx, info) => {
|
||||||
|
const { skip, take } = args;
|
||||||
|
return await this.prisma.center.findMany({
|
||||||
|
skip: skip ?? 0,
|
||||||
|
take: take ?? 10,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/centerstaff/centerstaff.module.ts
Normal file
9
src/centerstaff/centerstaff.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { CenterStaffSchema } from './centerstaff.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [CenterStaffSchema],
|
||||||
|
exports: [CenterStaffSchema],
|
||||||
|
})
|
||||||
|
export class CenterStaffModule {}
|
||||||
34
src/centerstaff/centerstaff.schema.ts
Normal file
34
src/centerstaff/centerstaff.schema.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CenterStaffSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PothosRef()
|
||||||
|
centerStaff() {
|
||||||
|
return this.builder.prismaObject('CenterStaff', {
|
||||||
|
fields: (t) => ({
|
||||||
|
staffId: t.exposeID('staffId'),
|
||||||
|
centerId: t.exposeID('centerId'),
|
||||||
|
serviceId: t.exposeID('serviceId'),
|
||||||
|
staff: t.relation('staff'),
|
||||||
|
center: t.relation('center'),
|
||||||
|
service: t.relation('service'),
|
||||||
|
createdWorkshop: t.relation('createdWorkshop'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/chatroom/chatroom.module.ts
Normal file
9
src/chatroom/chatroom.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { ChatroomSchema } from './chatroom.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [ChatroomSchema],
|
||||||
|
exports: [ChatroomSchema],
|
||||||
|
})
|
||||||
|
export class ChatroomModule {}
|
||||||
28
src/chatroom/chatroom.schema.ts
Normal file
28
src/chatroom/chatroom.schema.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ChatroomSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PothosRef()
|
||||||
|
chatRoom() {
|
||||||
|
return this.builder.prismaObject('ChatRoom', {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID('id'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,27 @@ import { PrismaService } from '../prisma/prisma.service';
|
|||||||
import { GraphQLValidationMiddleware } from 'src/middlewares/graphql.middleware';
|
import { GraphQLValidationMiddleware } from 'src/middlewares/graphql.middleware';
|
||||||
import { PrismaModule } from 'src/prisma/prisma.module';
|
import { PrismaModule } from 'src/prisma/prisma.module';
|
||||||
import { UserModule } from 'src/user/user.module';
|
import { UserModule } from 'src/user/user.module';
|
||||||
|
import { CenterModule } from 'src/center/center.module';
|
||||||
import { GraphqlService } from './graphql.service';
|
import { GraphqlService } from './graphql.service';
|
||||||
|
import { ServiceModule } from 'src/service/service.module';
|
||||||
|
import { ChatroomModule } from 'src/chatroom/chatroom.module';
|
||||||
|
import { CenterStaffModule } from 'src/centerstaff/centerstaff.module';
|
||||||
|
import { ResumeModule } from 'src/resume/resume.module';
|
||||||
|
import { WorkshopModule } from 'src/workshop/workshop.module';
|
||||||
|
import { WorkshopOrganizationModule } from 'src/workshoporganization/workshoporganization.module';
|
||||||
|
import { WorkshopSubscriptionModule } from 'src/workshopsubscription/workshopsubscription.module';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
PrismaModule,
|
PrismaModule,
|
||||||
UserModule,
|
UserModule,
|
||||||
|
CenterModule,
|
||||||
|
ServiceModule,
|
||||||
|
ChatroomModule,
|
||||||
|
CenterStaffModule,
|
||||||
|
ResumeModule,
|
||||||
|
WorkshopModule,
|
||||||
|
WorkshopOrganizationModule,
|
||||||
|
WorkshopSubscriptionModule,
|
||||||
PothosModule.forRoot({
|
PothosModule.forRoot({
|
||||||
builder: {
|
builder: {
|
||||||
inject: [PrismaService],
|
inject: [PrismaService],
|
||||||
|
|||||||
@@ -22,6 +22,17 @@ export class GraphQLValidationMiddleware implements NestMiddleware {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// handle query only contain \n
|
||||||
|
if (query.trim() === '') {
|
||||||
|
return res.status(400).json({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
'Must provide a valid GraphQL query, mutation, or subscription.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue to the next middleware or GraphQL handler
|
// Continue to the next middleware or GraphQL handler
|
||||||
|
|||||||
9
src/resume/resume.module.ts
Normal file
9
src/resume/resume.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { ResumeSchema } from './resume.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [ResumeSchema],
|
||||||
|
exports: [ResumeSchema],
|
||||||
|
})
|
||||||
|
export class ResumeModule {}
|
||||||
40
src/resume/resume.schema.ts
Normal file
40
src/resume/resume.schema.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ResumeSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PothosRef()
|
||||||
|
resume() {
|
||||||
|
return this.builder.prismaObject('Resume', {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID('id'),
|
||||||
|
userId: t.exposeID('userId'),
|
||||||
|
centerId: t.exposeID('centerId'),
|
||||||
|
status: t.exposeString('status'),
|
||||||
|
createdAt: t.expose('createdAt', {
|
||||||
|
type: 'Date',
|
||||||
|
nullable: true,
|
||||||
|
}),
|
||||||
|
updatedAt: t.expose('updatedAt', {
|
||||||
|
type: 'Date',
|
||||||
|
nullable: true,
|
||||||
|
}),
|
||||||
|
center: t.relation('center'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { ServiceSchema } from './service.schema';
|
||||||
|
|
||||||
@Module({})
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [ServiceSchema],
|
||||||
|
exports: [ServiceSchema],
|
||||||
|
})
|
||||||
export class ServiceModule {}
|
export class ServiceModule {}
|
||||||
|
|||||||
30
src/service/service.schema.ts
Normal file
30
src/service/service.schema.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ServiceSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PothosRef()
|
||||||
|
service() {
|
||||||
|
return this.builder.prismaObject('Service', {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID('id'),
|
||||||
|
name: t.exposeString('name'),
|
||||||
|
description: t.exposeString('description'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ export class UserSchema extends PothosSchema {
|
|||||||
role: t.exposeString('role'),
|
role: t.exposeString('role'),
|
||||||
createdAt: t.expose('createdAt', { type: 'Date' }),
|
createdAt: t.expose('createdAt', { type: 'Date' }),
|
||||||
updatedAt: t.expose('updatedAt', { type: 'Date' }),
|
updatedAt: t.expose('updatedAt', { type: 'Date' }),
|
||||||
|
center: t.relation('center'),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -61,6 +62,22 @@ export class UserSchema extends PothosSchema {
|
|||||||
return users;
|
return users;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
user: t.prismaField({
|
||||||
|
type: this.user(),
|
||||||
|
args: {
|
||||||
|
id: t.arg.id({
|
||||||
|
description: 'The ID of the user to retrieve',
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args, ctx, info) => {
|
||||||
|
const { id } = args;
|
||||||
|
if (!id) {
|
||||||
|
throw new Error('User ID is required');
|
||||||
|
}
|
||||||
|
return await this.prisma.user.findUnique({ where: { id } });
|
||||||
|
},
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
src/workshop/workshop.module.ts
Normal file
9
src/workshop/workshop.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { WorkshopSchema } from './workshop.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [WorkshopSchema],
|
||||||
|
exports: [WorkshopSchema],
|
||||||
|
})
|
||||||
|
export class WorkshopModule {}
|
||||||
45
src/workshop/workshop.schema.ts
Normal file
45
src/workshop/workshop.schema.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class WorkshopSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PothosRef()
|
||||||
|
workshop() {
|
||||||
|
return this.builder.prismaObject('Workshop', {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID('id'),
|
||||||
|
title: t.exposeString('title'),
|
||||||
|
description: t.exposeString('description'),
|
||||||
|
staffId: t.exposeID('staffId'),
|
||||||
|
serviceId: t.exposeID('serviceId'),
|
||||||
|
date: t.expose('date', {
|
||||||
|
type: 'Date',
|
||||||
|
}),
|
||||||
|
createdAt: t.expose('createdAt', {
|
||||||
|
type: 'Date',
|
||||||
|
}),
|
||||||
|
updatedAt: t.expose('updatedAt', {
|
||||||
|
type: 'Date',
|
||||||
|
}),
|
||||||
|
service: t.relation('service'),
|
||||||
|
workshopOrganization: t.relation('workshopOrganization'),
|
||||||
|
workshopSubscription: t.relation('workshopSubscription'),
|
||||||
|
staff: t.relation('staff'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/workshoporganization/workshoporganization.module.ts
Normal file
9
src/workshoporganization/workshoporganization.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { WorkshopOrganizationSchema } from './workshoporganization.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [WorkshopOrganizationSchema],
|
||||||
|
exports: [WorkshopOrganizationSchema],
|
||||||
|
})
|
||||||
|
export class WorkshopOrganizationModule {}
|
||||||
30
src/workshoporganization/workshoporganization.schema.ts
Normal file
30
src/workshoporganization/workshoporganization.schema.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class WorkshopOrganizationSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
@PothosRef()
|
||||||
|
workshopOrganization() {
|
||||||
|
return this.builder.prismaObject('WorkshopOrganization', {
|
||||||
|
fields: (t) => ({
|
||||||
|
workshopId: t.exposeID('workshopId'),
|
||||||
|
serviceId: t.exposeID('serviceId'),
|
||||||
|
workshop: t.relation('workshop'),
|
||||||
|
service: t.relation('service'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/workshopsubscription/workshopsubscription.module.ts
Normal file
9
src/workshopsubscription/workshopsubscription.module.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { WorkshopSubscriptionSchema } from './workshopsubscription.schema';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [WorkshopSubscriptionSchema],
|
||||||
|
exports: [WorkshopSubscriptionSchema],
|
||||||
|
})
|
||||||
|
export class WorkshopSubscriptionModule {}
|
||||||
30
src/workshopsubscription/workshopsubscription.schema.ts
Normal file
30
src/workshopsubscription/workshopsubscription.schema.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
Pothos,
|
||||||
|
PothosRef,
|
||||||
|
PothosSchema,
|
||||||
|
SchemaBuilderToken,
|
||||||
|
} from '@smatch-corp/nestjs-pothos';
|
||||||
|
import { Builder } from '../graphql/graphql.builder';
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class WorkshopSubscriptionSchema extends PothosSchema {
|
||||||
|
constructor(
|
||||||
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
@PothosRef()
|
||||||
|
workshopSubscription() {
|
||||||
|
return this.builder.prismaObject('WorkshopSubscription', {
|
||||||
|
fields: (t) => ({
|
||||||
|
userId: t.exposeID('userId'),
|
||||||
|
workshopId: t.exposeID('workshopId'),
|
||||||
|
user: t.relation('user'),
|
||||||
|
workshop: t.relation('workshop'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user