troi mua qua

This commit is contained in:
2024-10-07 20:46:20 +07:00
parent 30159e01ad
commit 5c836323b0
19 changed files with 411 additions and 2 deletions

View 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 {}

View 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,
});
},
}),
}));
}
}

View 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 {}

View 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'),
}),
});
}
}

View 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 {}

View 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'),
}),
});
}
}

View File

@@ -8,11 +8,27 @@ import { PrismaService } from '../prisma/prisma.service';
import { GraphQLValidationMiddleware } from 'src/middlewares/graphql.middleware';
import { PrismaModule } from 'src/prisma/prisma.module';
import { UserModule } from 'src/user/user.module';
import { CenterModule } from 'src/center/center.module';
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({
imports: [
PrismaModule,
UserModule,
CenterModule,
ServiceModule,
ChatroomModule,
CenterStaffModule,
ResumeModule,
WorkshopModule,
WorkshopOrganizationModule,
WorkshopSubscriptionModule,
PothosModule.forRoot({
builder: {
inject: [PrismaService],

View File

@@ -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

View 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 {}

View 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'),
}),
});
}
}

View File

@@ -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 {}

View 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'),
}),
});
}
}

View File

@@ -30,6 +30,7 @@ export class UserSchema extends PothosSchema {
role: t.exposeString('role'),
createdAt: t.expose('createdAt', { type: 'Date' }),
updatedAt: t.expose('updatedAt', { type: 'Date' }),
center: t.relation('center'),
}),
});
}
@@ -61,6 +62,22 @@ export class UserSchema extends PothosSchema {
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 } });
},
}),
}));
}

View 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 {}

View 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'),
}),
});
}
}

View 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 {}

View 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'),
}),
});
}
}

View 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 {}

View 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'),
}),
});
}
}