-
Notifications
You must be signed in to change notification settings - Fork 0
/
consultas.js
45 lines (31 loc) · 1.53 KB
/
consultas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require('dotenv').config()
const { Pool } = require('pg')
const connectionString = process.env.STRING;
const pool = new Pool({
connectionString,
})
const insertarUsuario = async (usuario) => {
const result = await pool.query(`INSERT INTO skaters (email, nombre, password, anos_experiencia, especialidad, foto, estado) values ('${usuario.email}', '${usuario.nombre}', '${usuario.password}', '${usuario.experiencia}', '${usuario.especialidad}', '${usuario.foto}', '${usuario.estado}' ) RETURNING * `)
return result.rows
}
const getUsuarios = async () => {
const result = await pool.query('SELECT * from skaters')
return result.rows
}
const getUser = async (email, password) => {
const result = await pool.query(`SELECT * from skaters WHERE email='${email}' AND password='${password}'`)
return result.rows[0]
}
const editUser = async (nuevoUser, id) => {
const result = await pool.query(`UPDATE skaters set nombre='${nuevoUser.nombre}', password='${nuevoUser.password}', anos_experiencia='${nuevoUser.experiencia}', especialidad='${nuevoUser.especialidad}' WHERE id='${id}' RETURNING *`)
return result.rows
}
const editEstado = async (id, estado) => {
const result = await pool.query(`UPDATE skaters SET estado='${estado}' WHERE id='${id}' RETURNING *`)
return result.rows[0]
}
const eliminarUser = async (id) => {
const result = await pool.query(`DELETE FROM skaters WHERE id='${id}'`)
return result.rowCount
}
module.exports = { insertarUsuario, getUsuarios, getUser, editUser, editEstado, eliminarUser }