Hello I’m new to learning about postgresql, and I’m to redo some old projects from the Odin project that uses postgresql instead of mongodb to practice. I’m stuck on trying to get a express-validator custom function to validate rather a user exist in my database’s table or not.
The custom validator function is written like this.
> .custom(async (val) =>{
> const query = 'SELECT 1 FROM users WHERE id = $1 LIMIT 1';
> const values = [val];
> try{
> const user = await pool.query(query, values);
> if(user.rowCount === 0) {
> throw new Error("that user already exist!");
> }
> } catch (err){
> console.error('Error checking if user exists', err);
> throw new Error('Database error while checking user existence');
> }
> }),
when I submit the form the to its “signup” post route, this error pops up the console.
the Schema for my ‘user’ table looks like this.
disregard status the value for that is always ‘guest’ when a user is created in the table.
What’s the issue with my code.
here a link to the full code.
https://github.com/rsteward117/members-only