import { Pool } from 'pg';
import { hash } from 'bcrypt'

export default defineEventHandler(async (event) => {
    try {
        const pool = new Pool({
            user: "de-user10",
            host: 'de-db.ptk.itiscaf.ru',
            database: 'de-user10',
            port: 5441,
            password: 'fGz0uG18uK'
        })

        const body = await readBody(event);

        let { fullname, login, phone, email, password} = body;

        const hash_password = hash(password, 10);

        const res = await pool.query('INSERT INTO users( fullname, login, phone, email, password ) VALUES($1, $2, $3, $4, $5) RETURNING id', 
            [fullname, login, phone, email, hash_password]
        );

        setCookie(event, 'online', JSON.stringify({fullname, login, phone, email}))
    } catch (error) {
        console.log('server signUp error', error);
        
    }


})