public agreement support for transparency

This commit is contained in:
2026-05-13 20:01:34 +00:00
parent d4c5b73c13
commit ad80bd2872
2 changed files with 13 additions and 5 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE public.agreement ADD COLUMN public BOOLEAN DEFAULT FALSE;

View File

@@ -72,9 +72,12 @@ async function getAgreement(client, userId, id, key) {
FROM agreement a
WHERE ${whereClause}
AND (
(
a.user_id = $2
OR a.user_id IS NULL
)
OR a.public IS TRUE
)
`
const res = await client.query(sql, [
whereValue,
@@ -169,8 +172,9 @@ async function get(input, userId) {
return response;
}
async function save(client, userId, agreement) {
async function save(client, userId, agreement, publicAgreement) {
await client.query(`BEGIN`);
const isPublic = publicAgreement ? true : false;
const res = await client.query(`
INSERT INTO agreement (
user_id,
@@ -178,6 +182,7 @@ async function save(client, userId, agreement) {
parent,
agreement_id_uuid,
context,
public,
created,
created_as_ts
) VALUES (
@@ -187,7 +192,8 @@ async function save(client, userId, agreement) {
$4,
$5,
$6,
$7
$7,
$8
) RETURNING id;
`, [
userId,
@@ -195,6 +201,7 @@ async function save(client, userId, agreement) {
agreement.parent,
agreement.agreementId,
agreement["@context"],
isPublic,
agreement.created,
new Date(agreement.created).toISOString(),
]);
@@ -431,7 +438,7 @@ async function create(input, userId, _client, uuid) {
if (uuid) {
agreement.agreementId = uuid;
}
await save(client, userId, agreement);
await save(client, userId, agreement, input.public);
response = {
message: `created and saved: ${agreement.agreementId}`,
data: agreement,