fix(palace): deleteMemory now decrements wing/room memoryCount
This commit is contained in:
parent
471660b771
commit
97662d1dc0
@ -198,6 +198,20 @@ describe('Palace Module — Phase N1', () => {
|
|||||||
expect(memB[0].content).toBe('B secret');
|
expect(memB[0].content).toBe('B secret');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('deleteMemory decrements wing and room memoryCount', async () => {
|
||||||
|
const wing = await ensureWing(USER_A, PRODUCT, 'ws-1', 'Work');
|
||||||
|
const room = await ensureRoom(USER_A, PRODUCT, wing.id, 'auth');
|
||||||
|
|
||||||
|
const mem = await storeMemory(USER_A, PRODUCT, wing.id, room.id, 'decisions', 'Fact 1');
|
||||||
|
await storeMemory(USER_A, PRODUCT, wing.id, room.id, 'decisions', 'Fact 2');
|
||||||
|
|
||||||
|
// Delete one memory
|
||||||
|
await deleteMemory(USER_A, PRODUCT, mem.id);
|
||||||
|
|
||||||
|
const updatedWing = await getWing(USER_A, PRODUCT, wing.id);
|
||||||
|
expect(updatedWing!.memoryCount).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('productId scoping: wrong productId returns empty results', async () => {
|
it('productId scoping: wrong productId returns empty results', async () => {
|
||||||
const wing = await ensureWing(USER_A, PRODUCT, 'ws-1', 'Work');
|
const wing = await ensureWing(USER_A, PRODUCT, 'ws-1', 'Work');
|
||||||
const room = await ensureRoom(USER_A, PRODUCT, wing.id, 'auth');
|
const room = await ensureRoom(USER_A, PRODUCT, wing.id, 'auth');
|
||||||
|
|||||||
@ -261,9 +261,27 @@ export async function deleteMemory(
|
|||||||
const doc = await memoriesCollection().findById(memoryId, userId);
|
const doc = await memoriesCollection().findById(memoryId, userId);
|
||||||
if (!doc || doc.productId !== productId) return false;
|
if (!doc || doc.productId !== productId) return false;
|
||||||
await memoriesCollection().delete(memoryId, userId);
|
await memoriesCollection().delete(memoryId, userId);
|
||||||
|
await decrementMemoryCount(userId, doc.wingId, doc.roomId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function decrementMemoryCount(userId: string, wingId: string, roomId: string): Promise<void> {
|
||||||
|
const wing = await wingsCollection().findById(wingId, userId);
|
||||||
|
if (wing && (wing.memoryCount || 0) > 0) {
|
||||||
|
await wingsCollection().update(wingId, userId, {
|
||||||
|
memoryCount: wing.memoryCount - 1,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const room = await roomsCollection().findById(roomId, userId);
|
||||||
|
if (room && (room.memoryCount || 0) > 0) {
|
||||||
|
await roomsCollection().update(roomId, userId, {
|
||||||
|
memoryCount: room.memoryCount - 1,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function listMemories(
|
export async function listMemories(
|
||||||
userId: string,
|
userId: string,
|
||||||
productId: string,
|
productId: string,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user