feat: 完善通用服务后台配置能力
This commit is contained in:
1 parent
60ca897574
commit
d167b58a05
6 files changed
+46
-3
No files matched your search
@@ -23,6 +23,21 @@ export class UpdateServiceDto {
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() bookingEnabled?: boolean;
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
@IsOptional() @IsString() categoryKey?: string;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class CreateServiceDto {
|
||||
@IsString() name!: string;
|
||||
@IsString() description!: string;
|
||||
@IsOptional() @IsString() categoryKey?: string;
|
||||
@IsOptional() @IsString() coverUrl?: string;
|
||||
@IsOptional() @IsString() priceText?: string;
|
||||
@IsOptional() @IsInt() @Min(0) priceAmount?: number;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() bookingEnabled?: boolean;
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class UpdateBookingStatusDto {
|
||||
|
||||
@@ -20,7 +20,7 @@ import { PrismaService } from "./prisma.service.js";
|
||||
import { WechatAuthService } from "./wechat-auth.js";
|
||||
import { BookingService } from "./booking.service.js";
|
||||
import { CreateBookingDto } from "./booking.dto.js";
|
||||
import { CreateTagDto, UpdateBookingStatusDto, UpdateBookingTagsDto, UpdateBrandDto, UpdateServiceDto } from "./admin.dto.js";
|
||||
import { CreateServiceDto, CreateTagDto, UpdateBookingStatusDto, UpdateBookingTagsDto, UpdateBrandDto, UpdateServiceDto } from "./admin.dto.js";
|
||||
import { AdminAuthService } from "./admin-auth.service.js";
|
||||
import { AdminLoginDto } from "./admin-auth.dto.js";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
@@ -75,6 +75,8 @@ export class PublicController {
|
||||
priceText: true,
|
||||
priceAmount: true,
|
||||
bookingEnabled: true,
|
||||
categoryKey: true,
|
||||
config: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -294,12 +296,17 @@ export class AdminConfigController {
|
||||
getBrand(@Req() request: FastifyRequest): Promise<unknown> { this.requireAdmin(request); return this.prisma.brandProfile.findUnique({ where: { id: this.brandId() } }); }
|
||||
@Patch("brand")
|
||||
updateBrand(@Req() request: FastifyRequest, @Body() body: UpdateBrandDto): Promise<unknown> { this.requireAdmin(request); return this.prisma.brandProfile.update({ where: { id: this.brandId() }, data: body }); }
|
||||
@Get("services")
|
||||
listServices(@Req() request: FastifyRequest): Promise<unknown> { this.requireAdmin(request); return this.prisma.service.findMany({ where: { brandId: this.brandId() }, orderBy: { sortOrder: "asc" } }); }
|
||||
@Post("services")
|
||||
createService(@Req() request: FastifyRequest, @Body() body: CreateServiceDto): Promise<unknown> { this.requireAdmin(request); const { config, ...fields } = body; return this.prisma.service.create({ data: { ...fields, brandId: this.brandId(), categoryKey: body.categoryKey ?? "standard", ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }) } }); }
|
||||
@Patch("services/:id")
|
||||
async updateService(@Req() request: FastifyRequest, @Param("id") id: string, @Body() body: UpdateServiceDto): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const service = await this.prisma.service.findFirst({ where: { id, brandId: this.brandId() } });
|
||||
if (!service) throw new BadRequestException("服务不存在");
|
||||
return this.prisma.service.update({ where: { id }, data: body });
|
||||
const { config, ...fields } = body;
|
||||
return this.prisma.service.update({ where: { id }, data: { ...fields, ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }) } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user