feat: 完善业务提供项生命周期管理
This commit is contained in:
1 parent
754da72245
commit
2aafa871bc
3 files changed
+46
No files matched your search
@@ -41,6 +41,18 @@ export function ServicesPage() {
|
|||||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const deleteOffering = useMutation({
|
||||||
|
mutationFn: (id: string) => client.deleteAdminOffering(id),
|
||||||
|
onSuccess: () => {
|
||||||
|
message.success("业务提供项已删除");
|
||||||
|
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const toggleOffering = useMutation({
|
||||||
|
mutationFn: ({ id, isEnabled }: { id: string; isEnabled: boolean }) =>
|
||||||
|
client.updateAdminOffering(id, { isEnabled }),
|
||||||
|
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] }),
|
||||||
|
});
|
||||||
const beginOffering = (item?: Offering) => {
|
const beginOffering = (item?: Offering) => {
|
||||||
setEditingOffering(item ?? null);
|
setEditingOffering(item ?? null);
|
||||||
setOfferingOpen(true);
|
setOfferingOpen(true);
|
||||||
@@ -105,9 +117,22 @@ export function ServicesPage() {
|
|||||||
{
|
{
|
||||||
title: "操作",
|
title: "操作",
|
||||||
render: (_: unknown, item: Offering) => (
|
render: (_: unknown, item: Offering) => (
|
||||||
|
<Space>
|
||||||
<Button size="small" onClick={() => beginOffering(item)}>
|
<Button size="small" onClick={() => beginOffering(item)}>
|
||||||
编辑详情
|
编辑详情
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
onClick={() =>
|
||||||
|
toggleOffering.mutate({ id: item.id, isEnabled: !item.isEnabled })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{item.isEnabled ? "禁用" : "启用"}
|
||||||
|
</Button>
|
||||||
|
<Button danger size="small" onClick={() => deleteOffering.mutate(item.id)}>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -114,6 +114,22 @@ class AdminWorkspaceController {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Delete("offerings/:id")
|
||||||
|
async deleteOffering(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
|
||||||
|
this.requireAdmin(request);
|
||||||
|
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
|
||||||
|
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||||
|
const [forms, bookings, items] = await Promise.all([
|
||||||
|
this.prisma.inquiryForm.count({ where: { offeringId: id } }),
|
||||||
|
this.prisma.booking.count({ where: { offeringId: id } }),
|
||||||
|
this.prisma.bookingItem.count({ where: { offeringId: id } }),
|
||||||
|
]);
|
||||||
|
if (forms || bookings || items)
|
||||||
|
throw new BadRequestException("业务提供项已有业务记录,只能禁用不能删除");
|
||||||
|
await this.prisma.offering.delete({ where: { id } });
|
||||||
|
return { deleted: true };
|
||||||
|
}
|
||||||
private requireAdmin(request: FastifyRequest): void {
|
private requireAdmin(request: FastifyRequest): void {
|
||||||
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
|
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
|
||||||
if (!token) throw new UnauthorizedException("缺少管理员登录态");
|
if (!token) throw new UnauthorizedException("缺少管理员登录态");
|
||||||
|
|||||||
@@ -452,6 +452,11 @@ export class ApiClient {
|
|||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
deleteAdminOffering(id: string): Promise<{ deleted: boolean }> {
|
||||||
|
return this.request(`/admin/workspace/offerings/${encodeURIComponent(id)}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
}
|
||||||
listAdminTrustContent(): Promise<TrustContent[]> {
|
listAdminTrustContent(): Promise<TrustContent[]> {
|
||||||
return this.request("/admin/config/trust-content");
|
return this.request("/admin/config/trust-content");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user