summaryrefslogtreecommitdiff
path: root/api/db/_deleteCurrentChallenge.ts
blob: 1f597bcc1fd458d920e36ae9c85a3ac016401ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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}`);
  }
}