hongbo-miao/hongbomiao.com

View on GitHub
api-node/src/dataSources/postgres/utils/insertUser.ts

Summary

Maintainability
A
0 mins
Test Coverage
import bcrypt from 'bcrypt';
import pg from '../pg';
import PostgresInputUser from '../types/PostgresInputUser';
import PostgresUser from '../types/PostgresUser';

const insertUser = async (user: PostgresInputUser): Promise<PostgresUser> => {
  const { email, password, firstName, lastName, bio } = user;

  const [firstUser] = await pg('users')
    .insert({
      email: email.toLowerCase(),
      password: await bcrypt.hash(password, 10),
      first_name: firstName,
      last_name: lastName,
      bio,
    })
    .returning('*');

  return firstUser;
};

export default insertUser;