-
Notifications
You must be signed in to change notification settings - Fork 21
/
settings.js
38 lines (32 loc) · 1.29 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const knex = require('../../db/connection');
const { requiredArgument } = require('../lib/preconditions');
const { useTenantId } = require('../use-request');
function setCurrentReportingPeriod(id, trns = knex, tenantId = useTenantId()) {
requiredArgument(id, 'must specify id in setCurrentReportingPeriod');
return trns('application_settings')
.where('tenant_id', tenantId)
.update('current_reporting_period_id', id);
}
async function getCurrentReportingPeriodID(trns = knex, tenantId = useTenantId()) {
return trns('application_settings')
.select('*')
.where('tenant_id', tenantId)
.then((r) => r[0].current_reporting_period_id);
}
async function applicationSettings(tenantId = useTenantId(), trns = knex) {
return trns('application_settings')
.join(
'reporting_periods',
'application_settings.current_reporting_period_id',
'reporting_periods.id',
)
.select('*')
.where('application_settings.tenant_id', tenantId)
.then((rows) => rows[0]);
}
module.exports = {
applicationSettings,
getCurrentReportingPeriodID,
setCurrentReportingPeriod,
};
// NOTE: This file was copied from src/server/db/settings.js (git @ ada8bfdc98) in the arpa-reporter repo on 2022-09-23T20:05:47.735Z