Skip to content

Commit

Permalink
update sdg validations (#2351)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
minotogna and mergify[bot] authored Mar 1, 2023
1 parent 1d529ee commit da2fe66
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AssessmentController } from '@server/controller/assessment'
import { BaseProtocol, Schemas } from '@server/db'

export default async (client: BaseProtocol) => {
const { assessment, cycle } = await AssessmentController.getOneWithCycle(
{ assessmentName: 'fra', cycleName: '2025' },
client
)
const schemaAssessment = Schemas.getName(assessment)

await client.query(`
update ${schemaAssessment}.row r
set props = jsonb_set(
r.props,
'{validateFns}',
jsonb_build_object('${cycle.uuid}', d.formula),
true
)
from (select r.id,
r.props ->> 'variableName' as variable_name,
t.props ->> 'name' as table_name,
jsonb_build_array(concat(
'validatorNotGreaterThan(',
t.props ->> 'name',
'.',
r.props ->> 'variableName',
','
'''100''',
')'
)) as formula
from ${schemaAssessment}.row r
left outer join
${schemaAssessment}."table" t on t.id = r.table_id
where t.props ->> 'name' in
('sustainableDevelopment15_1_1', 'sustainableDevelopment15_2_1_1', 'sustainableDevelopment15_2_1_3',
'sustainableDevelopment15_2_1_4')
and r.props ->> 'variableName' is not null) as d
where d.id = r.id
`)
}

0 comments on commit da2fe66

Please sign in to comment.