feat(isac): add oversight proposal corrections
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user