|
1 | 1 | import { Router } from 'express'
|
2 | 2 | import format from 'pg-format'
|
3 |
| -import { coalesceRowsToArray, toTransaction } from '../lib/helpers' |
| 3 | +import { toTransaction } from '../lib/helpers' |
4 | 4 | import { RunQuery } from '../lib/connectionPool'
|
5 | 5 | import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
|
6 | 6 | import { Tables } from '../lib/interfaces'
|
@@ -61,7 +61,7 @@ router.patch('/:id', async (req, res) => {
|
61 | 61 | const payload: Tables.Policy = { ...req.body }
|
62 | 62 | const previousPolicy: Tables.Policy = await getPolicyById(pcConnection, id)
|
63 | 63 | const nameChange = !!payload.name && payload.name != previousPolicy.name
|
64 |
| - let updates = { ...payload } |
| 64 | + const updates = { ...payload } |
65 | 65 | if (!updates.name) updates.name = previousPolicy.name
|
66 | 66 | if (!updates.schema) updates.schema = previousPolicy.schema
|
67 | 67 | if (!updates.table) updates.table = previousPolicy.table
|
@@ -115,7 +115,7 @@ const getAllSql = (sqlTemplates) => {
|
115 | 115 | }
|
116 | 116 | const getPolicyById = async (connection: string, id: number) => {
|
117 | 117 | const { policies } = sqlTemplates
|
118 |
| - let sql = ` |
| 118 | + const sql = ` |
119 | 119 | with policies as (${policies})
|
120 | 120 | select * from policies
|
121 | 121 | where policies.id = ${id}
|
@@ -191,10 +191,10 @@ const alterSql = ({
|
191 | 191 | check?: string
|
192 | 192 | roles?: string[]
|
193 | 193 | }) => {
|
194 |
| - let alter = format(`ALTER POLICY %I ON %I.%I`, name, schema, table) |
195 |
| - let newDefinition = definition !== undefined ? `${alter} USING (${definition});` : '' |
196 |
| - let newCheck = check !== undefined ? `${alter} WITH CHECK (${check});` : '' |
197 |
| - let newRoles = roles !== undefined ? `${alter} TO (${roles.join(',')});` : '' |
| 194 | + const alter = format(`ALTER POLICY %I ON %I.%I`, name, schema, table) |
| 195 | + const newDefinition = definition !== undefined ? `${alter} USING (${definition});` : '' |
| 196 | + const newCheck = check !== undefined ? `${alter} WITH CHECK (${check});` : '' |
| 197 | + const newRoles = roles !== undefined ? `${alter} TO (${roles.join(',')});` : '' |
198 | 198 |
|
199 | 199 | return `
|
200 | 200 | ${newDefinition}
|
|
0 commit comments