diff --git a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js new file mode 100644 --- /dev/null +++ b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js @@ -0,0 +1,23 @@ +// @flow + +import type { PolicyType } from 'lib/facts/policies.js'; +import { type UserPolicyConfirmationType } from 'lib/types/policy-types.js'; + +import { dbQuery, SQL } from '../database/database.js'; +import { Viewer } from '../session/viewer.js'; + +async function fetchPolicyAcknowledgments( + viewer: Viewer, + policies: $ReadOnlyArray, +): Promise<$ReadOnlyArray> { + const query = SQL` + SELECT policy, confirmed + FROM policy_acknowledgments + WHERE user=${viewer.id} + AND policy IN (${policies}) + `; + const [data] = await dbQuery(query); + return data; +} + +export { fetchPolicyAcknowledgments }; diff --git a/lib/types/policy-types.js b/lib/types/policy-types.js new file mode 100644 --- /dev/null +++ b/lib/types/policy-types.js @@ -0,0 +1,8 @@ +// @flow + +import type { PolicyType } from '../facts/policies.js'; + +export type UserPolicyConfirmationType = { + +policy: PolicyType, + +confirmed: boolean, +};