|
8 | 8 | // except according to the terms contained in the LICENSE file. |
9 | 9 |
|
10 | 10 | const { sql } = require('slonik'); |
11 | | - |
| 11 | +const Option = require('../../util/option'); |
12 | 12 |
|
13 | 13 | const getForUser = (userId) => ({ one }) => |
14 | 14 | one(sql` |
@@ -87,37 +87,23 @@ const _writeProperty = (tablename, subject, userId, propertyName, propertyValue) |
87 | 87 | `); |
88 | 88 | }; |
89 | 89 |
|
90 | | - |
91 | | -const _removeProperty = (tablename, subject, userId, propertyName) => ({ maybeOne }) => { |
92 | | - const targetColumns = ['userId', 'propertyName'] |
93 | | - .concat((subject === null) ? [] : ['projectId']) |
94 | | - .map(el => sql.identifier([el])); |
95 | | - |
96 | | - const values = [userId, propertyName] |
97 | | - .concat((subject === null) ? [] : [subject]); |
98 | | - |
99 | | - return maybeOne(sql` |
100 | | - DELETE FROM ${sql.identifier([tablename])} |
101 | | - WHERE |
102 | | - (${sql.join(targetColumns, `, `)}) |
103 | | - = |
104 | | - (${sql.join(values, `, `)}) |
105 | | - RETURNING |
106 | | - 1 AS "deleted_count" |
107 | | - `); |
108 | | -}; |
109 | | - |
110 | | - |
111 | 90 | const writeSiteProperty = (userId, propertyName, propertyValue) => ({ one }) => |
112 | 91 | _writeProperty('user_site_preferences', null, userId, propertyName, propertyValue)({ one }); |
113 | 92 |
|
114 | | -const removeSiteProperty = (userId, propertyName) => ({ maybeOne }) => |
115 | | - _removeProperty('user_site_preferences', null, userId, propertyName)({ maybeOne }); |
116 | | - |
117 | 93 | const writeProjectProperty = (userId, projectId, propertyName, propertyValue) => ({ one }) => |
118 | 94 | _writeProperty('user_project_preferences', projectId, userId, propertyName, propertyValue)({ one }); |
119 | 95 |
|
120 | | -const removeProjectProperty = (userId, projectId, propertyName) => ({ maybeOne }) => |
121 | | - _removeProperty('user_project_preferences', projectId, userId, propertyName)({ maybeOne }); |
| 96 | +const removeSiteProperty = (userId, propertyName) => ({ db }) => db.query(sql` |
| 97 | + DELETE FROM user_site_preferences |
| 98 | + WHERE "userId" = ${userId} |
| 99 | + AND "propertyName" = ${propertyName} |
| 100 | +`).then(({ rowCount }) => Option.of(rowCount || null)); |
| 101 | + |
| 102 | +const removeProjectProperty = (userId, projectId, propertyName) => async ({ db }) => db.query(sql` |
| 103 | + DELETE FROM user_project_preferences |
| 104 | + WHERE "userId" = ${userId} |
| 105 | + AND "propertyName" = ${propertyName} |
| 106 | + AND "projectId" = ${projectId} |
| 107 | +`).then(({ rowCount }) => Option.of(rowCount || null)); |
122 | 108 |
|
123 | 109 | module.exports = { removeSiteProperty, writeSiteProperty, writeProjectProperty, removeProjectProperty, getForUser }; |
0 commit comments