book_manage/apps/server/src/models/share-code/share-code.router.ts

49 lines
2.0 KiB
TypeScript

import { z } from "zod";
import { ShareCodeService } from "./share-code.service";
import { TrpcService } from "@server/trpc/trpc.service";
import { Injectable } from "@nestjs/common";
@Injectable()
export class ShareCodeRouter {
constructor(
private readonly shareCodeService: ShareCodeService,
private readonly trpc: TrpcService
) {}
router = this.trpc.router({
generateShareCode: this.trpc.procedure
.input(z.object({ fileId: z.string() }))
.mutation(async ({ input }) => {
return this.shareCodeService.generateShareCode(input.fileId);
}),
validateAndUseCode: this.trpc.procedure
.input(z.object({ code: z.string() }))
.mutation(async ({ input }) => {
return this.shareCodeService.validateAndUseCode(input.code);
}),
getShareCodeInfo: this.trpc.procedure
.input(z.object({ code: z.string() }))
.query(async ({ input }) => {
return this.shareCodeService.getShareCodeInfo(input.code);
}),
hasActiveShareCode: this.trpc.procedure
.input(z.object({ fileId: z.string() }))
.query(async ({ input }) => {
return this.shareCodeService.hasActiveShareCode(input.fileId);
}),
getFileShareHistory: this.trpc.procedure
.input(z.object({ fileId: z.string() }))
.query(async ({ input }) => {
return this.shareCodeService.getFileShareHistory(input.fileId);
}),
getFileByShareCode: this.trpc.procedure
.input(z.object({ code: z.string() }))
.query(async ({ input }) => {
return this.shareCodeService.getFileByShareCode(input.code);
}),
generateShareCodeByFileId: this.trpc.procedure
.input(z.object({ fileId: z.string() }))
.mutation(async ({ input }) => {
return this.shareCodeService.generateShareCodeByFileId(input.fileId);
}),
});
}