feat: add admin order tags and read state
This commit is contained in:
1 parent
bb5ccb1359
commit
0d4caaba00
3 files changed
+89
-2
No files matched your search
@@ -137,4 +137,43 @@ export class BookingService {
|
||||
data: { status, ...(adminNote !== undefined ? { adminNote } : {}), isRead: true },
|
||||
});
|
||||
}
|
||||
|
||||
async markRead(brandId: string, id: string) {
|
||||
const booking = await this.prisma.booking.findFirst({ where: { id, brandId } });
|
||||
if (!booking) throw new NotFoundException("订单不存在");
|
||||
return this.prisma.booking.update({ where: { id }, data: { isRead: true } });
|
||||
}
|
||||
|
||||
async listTags(brandId: string) {
|
||||
return this.prisma.tag.findMany({
|
||||
where: { brandId, isEnabled: true },
|
||||
orderBy: [{ isPreset: "desc" }, { name: "asc" }],
|
||||
});
|
||||
}
|
||||
|
||||
async createTag(brandId: string, name: string) {
|
||||
const normalized = name.trim();
|
||||
if (!normalized || normalized.length > 24) throw new BadRequestException("标签名称长度无效");
|
||||
return this.prisma.tag.create({ data: { brandId, name: normalized } });
|
||||
}
|
||||
|
||||
async updateTags(brandId: string, bookingId: string, tagIds: string[]) {
|
||||
const booking = await this.prisma.booking.findFirst({ where: { id: bookingId, brandId } });
|
||||
if (!booking) throw new NotFoundException("订单不存在");
|
||||
const tags = await this.prisma.tag.findMany({
|
||||
where: { id: { in: tagIds }, brandId, isEnabled: true },
|
||||
select: { id: true },
|
||||
});
|
||||
if (tags.length !== new Set(tagIds).size) throw new BadRequestException("存在无效标签");
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.bookingTag.deleteMany({ where: { bookingId } }),
|
||||
this.prisma.bookingTag.createMany({
|
||||
data: tags.map((tag) => ({ bookingId, tagId: tag.id })),
|
||||
}),
|
||||
]);
|
||||
return this.prisma.booking.findUnique({
|
||||
where: { id: bookingId },
|
||||
include: { tags: { include: { tag: true } } },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user