feat(memory): S3 3a minnes-yta + impact-endpoint
This commit is contained in:
@@ -6,6 +6,7 @@ import { userLanguageTag } from "../lib/contentLanguage.js";
|
||||
import { idParamSchema, memoryQuerySchema, updateMemoryItemInputSchema } from "@app/validation";
|
||||
import { errors, parse } from "../lib/errors.js";
|
||||
import { audit, emitEvent, getActiveHouseholdId } from "../lib/helpers.js";
|
||||
import { computeMemoryImpact } from "../lib/memoryImpact.js";
|
||||
|
||||
/**
|
||||
* "Vad plattformen vet om mig" (spec §32): full transparens.
|
||||
@@ -59,6 +60,50 @@ export async function memoryRoutes(app: FastifyInstance) {
|
||||
return overview;
|
||||
});
|
||||
|
||||
/**
|
||||
* Visa vilka rekommendationer ett specifikt minne påverkar.
|
||||
* Kräver personalization-samtycke; isolerat till den anropande användaren.
|
||||
*/
|
||||
app.get("/v1/me/memory/:id/impact", auth, async (req, reply) => {
|
||||
const { id } = parse(idParamSchema, req.params);
|
||||
const item = await getOwnedMemory(app, id, req.userId);
|
||||
|
||||
const memoryItem: import("@app/shared-types").MemoryItem = {
|
||||
id: item.id,
|
||||
userId: item.userId ?? undefined,
|
||||
householdId: item.householdId ?? undefined,
|
||||
kind: item.kind,
|
||||
key: item.key,
|
||||
summarySv: item.summarySv,
|
||||
value: item.value,
|
||||
origin: item.origin,
|
||||
confidence: item.confidence,
|
||||
verifiedByUser: item.verifiedByUser,
|
||||
paused: item.paused,
|
||||
createdAt: item.createdAt.toISOString(),
|
||||
updatedAt: item.updatedAt.toISOString(),
|
||||
lastUsedAt: item.lastUsedAt?.toISOString(),
|
||||
expiresAt: item.expiresAt?.toISOString(),
|
||||
};
|
||||
|
||||
const result = await computeMemoryImpact({
|
||||
db: app.db,
|
||||
userId: req.userId,
|
||||
memoryItem,
|
||||
});
|
||||
|
||||
if (!result.personalizationEnabled) {
|
||||
return reply.status(403).send({
|
||||
error: {
|
||||
code: "PERSONALIZATION_CONSENT_REQUIRED",
|
||||
message: "Impact kräver personalization-samtycke.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
app.patch("/v1/me/memory/:id", auth, async (req) => {
|
||||
const { id } = parse(idParamSchema, req.params);
|
||||
const input = parse(updateMemoryItemInputSchema, req.body);
|
||||
|
||||
Reference in New Issue
Block a user