public agreement support for transparency
This commit is contained in:
1
src/db/migrations/000013 - public-agreement.sql
Normal file
1
src/db/migrations/000013 - public-agreement.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE public.agreement ADD COLUMN public BOOLEAN DEFAULT FALSE;
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user