doll active state

This commit is contained in:
2025-12-21 02:07:48 +08:00
parent 5bed1fc92e
commit cd71e97655
10 changed files with 310 additions and 5 deletions

View File

@@ -34,6 +34,10 @@ describe('DollsService', () => {
friendship: {
findMany: jest.fn().mockResolvedValue([]),
},
$transaction: jest.fn((callback) => callback(mockPrismaService)),
user: {
updateMany: jest.fn().mockResolvedValue({ count: 1 }),
},
};
const mockEventEmitter = {

View File

@@ -187,11 +187,20 @@ export class DollsService {
}
// Soft delete
await this.prisma.doll.update({
where: { id },
data: {
deletedAt: new Date(),
},
await this.prisma.$transaction(async (tx) => {
// 1. Soft delete the doll
await tx.doll.update({
where: { id },
data: {
deletedAt: new Date(),
},
});
// 2. Unset if it was active
await tx.user.updateMany({
where: { id: requestingUserId, activeDollId: id },
data: { activeDollId: null },
});
});
const event: DollDeletedEvent = {