feat(isac): add oversight proposal corrections

This commit is contained in:
JB
2026-07-25 14:06:07 -04:00
parent 32dbef822b
commit e6ad7b4c4e
10 changed files with 131 additions and 21 deletions
+13
View File
@@ -43,6 +43,19 @@ export function deserializeProposal(payload: string): FormData {
return form;
}
export async function refreshProposalDependencies(proposalId: string, payload: string) {
const database = await getDatabase();
const text = serializedTextValues(payload).map((entry) => entry.value).join('\n');
const candidates = await (await database.prepare(`SELECT id,draft_entity_id FROM data_change_proposals
WHERE id<>? AND draft_entity_id IS NOT NULL`)).all(proposalId);
const dependencies = candidates.filter((candidate) => text.includes(String(candidate.draft_entity_id)));
await (await database.prepare('DELETE FROM data_change_proposal_dependencies WHERE proposal_id=?')).run(proposalId);
for (const dependency of dependencies) {
await (await database.prepare('INSERT INTO data_change_proposal_dependencies(proposal_id,depends_on_proposal_id) VALUES(?,?)')).run(proposalId, dependency.id);
}
return dependencies.map((dependency) => String(dependency.id));
}
const serializedTextValues = (payload: string) =>
(JSON.parse(payload) as SerializedEntry[]).filter((entry): entry is Extract<SerializedEntry, { kind: 'text' }> => entry.kind === 'text');