diff options
Diffstat (limited to 'api/db/_updateAuthenticator.ts')
| -rw-r--r-- | api/db/_updateAuthenticator.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/api/db/_updateAuthenticator.ts b/api/db/_updateAuthenticator.ts index 45d094c..a7e06e3 100644 --- a/api/db/_updateAuthenticator.ts +++ b/api/db/_updateAuthenticator.ts @@ -6,18 +6,20 @@ import { AUTHENTICATORS } from './_tables'; export default async function updateAuthenticator< T extends keyof Omit<Authenticator, 'id'> >(id: string, updatedFields: Pick<Authenticator, T>): Promise<void> { - try { - const assignments = Object.entries(updatedFields) - .filter(([key]) => key !== 'id') // never update the ID - .map(([key, value]) => `${key}=${value}`) - .join(', '); + const assignments = Object.entries(updatedFields) + .filter(([key]) => key !== 'id') // never update the ID + .map(([key, value]) => `${key}=${value}`) + .join(', '); + + const query = ` + UPDATE ${AUTHENTICATORS.name} + SET ${assignments} + WHERE ${AUTHENTICATORS.fields.id} = '${id}'; + `; - await sql.query(` - UPDATE ${AUTHENTICATORS.name} - SET ${assignments} - WHERE ${AUTHENTICATORS.fields.id} = '${id}'; - `); + try { + await sql.query(query); } catch (err) { - throw new Error(`Failed to update authenticator with ID ${id} in database.`, err); + throw new Error(`Failed to update authenticator with ID ${id} in database. Query was ${query.replace(/\s+/g, ' ')}. ${err}`); } } |
