feat: 增加后台品牌与服务配置能力
This commit is contained in:
1 parent
34ec893369
commit
f485257e37
4 files changed
+61
-4
No files matched your search
@@ -1,4 +1,28 @@
|
||||
import { IsArray, IsIn, IsOptional, IsString } from "class-validator";
|
||||
import { IsArray, IsBoolean, IsIn, IsInt, IsOptional, IsString, Max, Min } from "class-validator";
|
||||
|
||||
export class UpdateBrandDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@IsOptional() @IsString() tagline?: string;
|
||||
@IsOptional() @IsString() description?: string;
|
||||
@IsOptional() @IsString() avatarUrl?: string;
|
||||
@IsOptional() @IsString() coverUrl?: string;
|
||||
@IsOptional() @IsString() hours?: string;
|
||||
@IsOptional() @IsString() address?: string;
|
||||
@IsOptional() @IsString() deliveryNote?: string;
|
||||
@IsOptional() @IsString() contactPhone?: string;
|
||||
@IsOptional() @IsString() contactWechat?: string;
|
||||
}
|
||||
|
||||
export class UpdateServiceDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@IsOptional() @IsString() description?: 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;
|
||||
}
|
||||
|
||||
export class UpdateBookingStatusDto {
|
||||
@IsIn(["received", "contacting", "confirmed", "completed", "cancelled"])
|
||||
|
||||
+25
-1
@@ -7,6 +7,7 @@ import {
|
||||
Module,
|
||||
Param,
|
||||
Post,
|
||||
Patch,
|
||||
Query,
|
||||
Req,
|
||||
ValidationPipe,
|
||||
@@ -19,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 } from "./admin.dto.js";
|
||||
import { 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";
|
||||
@@ -279,6 +280,28 @@ export class AdminBookingController {
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("admin/config")
|
||||
export class AdminConfigController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
private brandId(): string { return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001"; }
|
||||
private requireAdmin(request: FastifyRequest): void {
|
||||
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
|
||||
if (!token) throw new BadRequestException("缺少管理员登录态");
|
||||
if (readIdentity(token).role !== "admin") throw new BadRequestException("无管理员权限");
|
||||
}
|
||||
@Get("brand")
|
||||
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 }); }
|
||||
@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 });
|
||||
}
|
||||
}
|
||||
|
||||
@Module({
|
||||
controllers: [
|
||||
HealthController,
|
||||
@@ -287,6 +310,7 @@ export class AdminBookingController {
|
||||
AdminSessionController,
|
||||
CustomerBookingController,
|
||||
AdminBookingController,
|
||||
AdminConfigController,
|
||||
],
|
||||
providers: [PrismaService, WechatAuthService, BookingService, AdminAuthService],
|
||||
exports: [PrismaService, WechatAuthService],
|
||||
|
||||
Reference in new issue
Block a user