summaryrefslogtreecommitdiff
path: root/api/db/_deleteCurrentChallenge.ts
diff options
context:
space:
mode:
authorJoe Carstairs <jcarstairs@scottlogic.com>2024-01-22 14:59:51 +0000
committerJoe Carstairs <jcarstairs@scottlogic.com>2024-01-29 10:51:49 +0000
commit19b4835bea200099bae15bc02edd5e4cafa2c46c (patch)
treef58a0124b361c16b51a55ebe68fcf52845438270 /api/db/_deleteCurrentChallenge.ts
parentedcb9577e28dc312f48d5ab3f5ecc8eeffd8db56 (diff)
verifyRegistrationResponse is single-responsibility!
Diffstat (limited to 'api/db/_deleteCurrentChallenge.ts')
-rw-r--r--api/db/_deleteCurrentChallenge.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/api/db/_deleteCurrentChallenge.ts b/api/db/_deleteCurrentChallenge.ts
new file mode 100644
index 0000000..1f597bc
--- /dev/null
+++ b/api/db/_deleteCurrentChallenge.ts
@@ -0,0 +1,15 @@
+import { sql } from '@vercel/postgres';
+import { CURRENT_CHALLENGES } from './_tables';
+
+export default async function deleteCurrentChallenge(userId: string) {
+ const query = `
+ DELETE FROM ${CURRENT_CHALLENGES.name}
+ WHERE ${CURRENT_CHALLENGES.fields.userId} = '${userId}'
+ `;
+
+ try {
+ await sql.query(query);
+ } catch (err) {
+ throw new Error(`Failed to delete current challenge for user with ID ${userId} in database. Query was ${query.replace(/\s+/g, ' ')}. ${err}`);
+ }
+}