diff --git a/apps/server/src/models/enrollment/enroll.schema.ts b/apps/server/src/models/enrollment/enroll.schema.ts deleted file mode 100755 index 652f2c8..0000000 --- a/apps/server/src/models/enrollment/enroll.schema.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { z } from 'zod'; - -export const EnrollSchema = z.object({ - studentId: z.string(), - postId: z.string(), -}); - -export const UnenrollSchema = z.object({ - studentId: z.string(), - postId: z.string(), -}); diff --git a/apps/server/src/models/enrollment/enrollment.module.ts b/apps/server/src/models/enrollment/enrollment.module.ts deleted file mode 100755 index dd9c554..0000000 --- a/apps/server/src/models/enrollment/enrollment.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Module } from '@nestjs/common'; -import { EnrollmentRouter } from './enrollment.router'; -import { EnrollmentService } from './enrollment.service'; - -@Module({ - exports: [EnrollmentRouter, EnrollmentService], - providers: [EnrollmentRouter, EnrollmentService], -}) -export class EnrollmentModule {} diff --git a/apps/server/src/models/enrollment/enrollment.router.ts b/apps/server/src/models/enrollment/enrollment.router.ts deleted file mode 100755 index b14e2f2..0000000 --- a/apps/server/src/models/enrollment/enrollment.router.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { TrpcService } from '@server/trpc/trpc.service'; -import { Prisma, UpdateOrderSchema } from '@nice/common'; -import { EnrollmentService } from './enrollment.service'; -import { z, ZodType } from 'zod'; -import { EnrollSchema, UnenrollSchema } from './enroll.schema'; -const EnrollmentCreateArgsSchema: ZodType = z.any() -const EnrollmentCreateManyInputSchema: ZodType = z.any() -const EnrollmentDeleteManyArgsSchema: ZodType = z.any() -const EnrollmentFindManyArgsSchema: ZodType = z.any() -const EnrollmentFindFirstArgsSchema: ZodType = z.any() -const EnrollmentWhereInputSchema: ZodType = z.any() -const EnrollmentSelectSchema: ZodType = z.any() - -@Injectable() -export class EnrollmentRouter { - constructor( - private readonly trpc: TrpcService, - private readonly enrollmentService: EnrollmentService, - ) { } - router = this.trpc.router({ - findFirst: this.trpc.procedure - .input(EnrollmentFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.enrollmentService.findFirst(input); - }), - findMany: this.trpc.procedure - .input(EnrollmentFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.enrollmentService.findMany(input); - }), - findManyWithCursor: this.trpc.protectProcedure - .input(z.object({ - cursor: z.any().nullish(), - take: z.number().nullish(), - where: EnrollmentWhereInputSchema.nullish(), - select: EnrollmentSelectSchema.nullish() - })) - .query(async ({ ctx, input }) => { - const { staff } = ctx; - return await this.enrollmentService.findManyWithCursor(input); - }), - enroll: this.trpc.protectProcedure - .input(EnrollSchema) - .mutation(async ({ input }) => { - return await this.enrollmentService.enroll(input); - }), - unenroll: this.trpc.protectProcedure - .input(UnenrollSchema) - .mutation(async ({ input }) => { - return await this.enrollmentService.unenroll(input); - }), - }); -} diff --git a/apps/server/src/models/enrollment/enrollment.service.ts b/apps/server/src/models/enrollment/enrollment.service.ts deleted file mode 100755 index 1b6ca8f..0000000 --- a/apps/server/src/models/enrollment/enrollment.service.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - ConflictException, - Injectable, - NotFoundException, -} from '@nestjs/common'; -import { BaseService } from '../base/base.service'; -import { - UserProfile, - db, - ObjectType, - Prisma, - EnrollmentStatus, -} from '@nice/common'; -import { z } from 'zod'; -import { EnrollSchema, UnenrollSchema } from './enroll.schema'; -import EventBus, { CrudOperation } from '@server/utils/event-bus'; - -@Injectable() -export class EnrollmentService extends BaseService { - constructor() { - super(db, ObjectType.COURSE); - } - async enroll(params: z.infer) { - const { studentId, postId } = params; - const result = await db.$transaction(async (tx) => { - // 检查是否已经报名 - const existing = await tx.enrollment.findUnique({ - where: { - studentId_postId: { - studentId: studentId, - postId: postId, - }, - }, - }); - if (existing) { - throw new ConflictException('Already enrolled in this post'); - } - // 创建报名记录 - const enrollment = await tx.enrollment.create({ - data: { - studentId: studentId, - postId: postId, - status: EnrollmentStatus.ACTIVE, - }, - }); - - return enrollment; - }); - - EventBus.emit('dataChanged', { - type: ObjectType.ENROLLMENT, - operation: CrudOperation.CREATED, - data: result, - }); - return result; - } - async unenroll(params: z.infer) { - const { studentId, postId } = params; - const result = await db.enrollment.update({ - where: { - studentId_postId: { - studentId, - postId, - }, - }, - data: { - status: EnrollmentStatus.CANCELLED, - }, - }); - - EventBus.emit('dataChanged', { - type: ObjectType.ENROLLMENT, - operation: CrudOperation.UPDATED, - data: result, - }); - return result; - } -} diff --git a/apps/server/src/models/post/post.service.ts b/apps/server/src/models/post/post.service.ts index 1c6f810..43b02e1 100755 --- a/apps/server/src/models/post/post.service.ts +++ b/apps/server/src/models/post/post.service.ts @@ -183,7 +183,7 @@ export class PostService extends BaseTreeService { pageSize?: number; where?: Prisma.PostWhereInput; orderBy?: OrderByArgs<(typeof db.post)['findMany']>; - select?: Prisma.PostSelect; + select?: Prisma.PostSelect; }): Promise<{ items: { id: string; diff --git a/apps/server/src/models/resource/resource.router.ts b/apps/server/src/models/resource/resource.router.ts index 6d4290f..12afc82 100755 --- a/apps/server/src/models/resource/resource.router.ts +++ b/apps/server/src/models/resource/resource.router.ts @@ -3,68 +3,76 @@ import { TrpcService } from '@server/trpc/trpc.service'; import { Prisma, UpdateOrderSchema } from '@nice/common'; import { ResourceService } from './resource.service'; import { z, ZodType } from 'zod'; -const ResourceCreateArgsSchema: ZodType = z.any() -const ResourceCreateManyInputSchema: ZodType = z.any() -const ResourceDeleteManyArgsSchema: ZodType = z.any() -const ResourceFindManyArgsSchema: ZodType = z.any() -const ResourceFindFirstArgsSchema: ZodType = z.any() -const ResourceWhereInputSchema: ZodType = z.any() -const ResourceSelectSchema: ZodType = z.any() + +const ResourceCreateArgsSchema: ZodType = z.any(); +const ResourceCreateManyInputSchema: ZodType = + z.any(); +const ResourceDeleteManyArgsSchema: ZodType = + z.any(); +const ResourceFindManyArgsSchema: ZodType = + z.any(); +const ResourceFindFirstArgsSchema: ZodType = + z.any(); +const ResourceWhereInputSchema: ZodType = z.any(); +const ResourceSelectSchema: ZodType = z.any(); @Injectable() export class ResourceRouter { - constructor( - private readonly trpc: TrpcService, - private readonly resourceService: ResourceService, - ) { } - router = this.trpc.router({ - create: this.trpc.protectProcedure - .input(ResourceCreateArgsSchema) - .mutation(async ({ ctx, input }) => { - const { staff } = ctx; - return await this.resourceService.create(input, { staff }); - }), - createMany: this.trpc.protectProcedure.input(z.array(ResourceCreateManyInputSchema)) - .mutation(async ({ ctx, input }) => { - const { staff } = ctx; + constructor( + private readonly trpc: TrpcService, + private readonly resourceService: ResourceService, + ) {} + router = this.trpc.router({ + create: this.trpc.protectProcedure + .input(ResourceCreateArgsSchema) + .mutation(async ({ ctx, input }) => { + const { staff } = ctx; + return await this.resourceService.create(input, { staff }); + }), + createMany: this.trpc.protectProcedure + .input(z.array(ResourceCreateManyInputSchema)) + .mutation(async ({ ctx, input }) => { + const { staff } = ctx; - return await this.resourceService.createMany({ data: input }, staff); - }), - deleteMany: this.trpc.procedure - .input(ResourceDeleteManyArgsSchema) - .mutation(async ({ input }) => { - return await this.resourceService.deleteMany(input); - }), - findFirst: this.trpc.procedure - .input(ResourceFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.resourceService.findFirst(input); - }), - softDeleteByIds: this.trpc.protectProcedure - .input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema - .mutation(async ({ input }) => { - return this.resourceService.softDeleteByIds(input.ids); - }), - updateOrder: this.trpc.protectProcedure - .input(UpdateOrderSchema) - .mutation(async ({ input }) => { - return this.resourceService.updateOrder(input); - }), - findMany: this.trpc.procedure - .input(ResourceFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.resourceService.findMany(input); - }), - findManyWithCursor: this.trpc.protectProcedure - .input(z.object({ - cursor: z.any().nullish(), - take: z.number().nullish(), - where: ResourceWhereInputSchema.nullish(), - select: ResourceSelectSchema.nullish() - })) - .query(async ({ ctx, input }) => { - const { staff } = ctx; - return await this.resourceService.findManyWithCursor(input); - }), - }); + return await this.resourceService.createMany({ data: input }, staff); + }), + deleteMany: this.trpc.procedure + .input(ResourceDeleteManyArgsSchema) + .mutation(async ({ input }) => { + return await this.resourceService.deleteMany(input); + }), + findFirst: this.trpc.procedure + .input(ResourceFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword + .query(async ({ input }) => { + return await this.resourceService.findFirst(input); + }), + softDeleteByIds: this.trpc.protectProcedure + .input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema + .mutation(async ({ input }) => { + return this.resourceService.softDeleteByIds(input.ids); + }), + updateOrder: this.trpc.protectProcedure + .input(UpdateOrderSchema) + .mutation(async ({ input }) => { + return this.resourceService.updateOrder(input); + }), + findMany: this.trpc.procedure + .input(ResourceFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword + .query(async ({ input }) => { + return await this.resourceService.findMany(input); + }), + findManyWithCursor: this.trpc.protectProcedure + .input( + z.object({ + cursor: z.any().nullish(), + take: z.number().nullish(), + where: ResourceWhereInputSchema.nullish(), + select: ResourceSelectSchema.nullish(), + }), + ) + .query(async ({ ctx, input }) => { + const { staff } = ctx; + return await this.resourceService.findManyWithCursor(input); + }), + }); } diff --git a/apps/server/tsconfig.json b/apps/server/tsconfig.json index 858dbf5..689b525 100755 --- a/apps/server/tsconfig.json +++ b/apps/server/tsconfig.json @@ -12,7 +12,6 @@ "outDir": "./dist", "strict": true, "esModuleInterop": true, - "incremental": true, - // "skipLibCheck": true, - }, -} \ No newline at end of file + "incremental": true + } +}