diff --git a/server/controllers/index.js b/server/controllers/index.js index e69de29..b158217 100644 --- a/server/controllers/index.js +++ b/server/controllers/index.js @@ -0,0 +1,3 @@ +const getAllUsers = require('./users/getAllUsers'); + +module.exports = { getAllUsers }; diff --git a/server/controllers/users/getAllUsers.js b/server/controllers/users/getAllUsers.js new file mode 100644 index 0000000..b5cb32f --- /dev/null +++ b/server/controllers/users/getAllUsers.js @@ -0,0 +1,13 @@ +/* eslint-disable no-console */ +const { getAllUsersQuery } = require('../../database/quieres'); + +const getAllUsers = async (req, res, next) => { + try { + const { rows } = await getAllUsersQuery(); + + res.json(({ data: rows })); + } catch (err) { + next(err); + } +}; +module.exports = getAllUsers; diff --git a/server/controllers/users/index.js b/server/controllers/users/index.js index e69de29..afcad12 100644 --- a/server/controllers/users/index.js +++ b/server/controllers/users/index.js @@ -0,0 +1,3 @@ +const getAllUsers = require('./getAllUsers'); + +module.exports = { getAllUsers }; diff --git a/server/database/config/adminsFack Data.sql b/server/database/config/adminsFack Data.sql deleted file mode 100644 index 421b924..0000000 --- a/server/database/config/adminsFack Data.sql +++ /dev/null @@ -1,4 +0,0 @@ -insert into admins (username, password , email) values ('ameera', 'F1A1CC71ED10594F97B1B6CF94A00727', 'ameera2021abed@gmail.com'); -insert into admins (username, password , email) values ('haroon', 'F1A1CC71ED10594F97B1B6CF94A00727', 'hro19502001@gmail.com'); -insert into admins (username, password , email) values ('elham', 'F1A1CC71ED10594F97B1B6CF94A00727', 'elham2000fadel@gmail.com'); -insert into admins (username, password , email) values ('sallah', 'F1A1CC71ED10594F97B1B6CF94A00727', 'mohmsal96@gmail.com'); diff --git a/server/database/config/agentsFackData.sql b/server/database/config/agentsFackData.sql deleted file mode 100644 index 8af4e91..0000000 --- a/server/database/config/agentsFackData.sql +++ /dev/null @@ -1,6 +0,0 @@ -insert into agents (name, email, password , phone, avater) values ('Kai', 'kallport0@patch.com', '6D29E04CD937DC37CB72E42736CA238C', '481-649-8020', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); -insert into agents (name, email, password , phone, avater) values ('Trixie', 'tbeadon1@plala.or.jp', '6D29E04CD937DC37CB72E42736CA238C', '663-871-7450', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); -insert into agents (name, email, password , phone, avater) values ('Allina', 'aburford2@tumblr.com', '6D29E04CD937DC37CB72E42736CA238C', '630-385-8312', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); -insert into agents (name, email, password , phone, avater) values ('Maye', 'mstrass3@yellowpages.com', '6D29E04CD937DC37CB72E42736CA238C', '210-886-2847', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); -insert into agents (name, email, password , phone, avater) values ('Lillian', 'abutrford2@tumblr.com', '6D29E04CD937DC37CB72E42736CA238C', '270-209-1221', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); -insert into agents (name, email, password , phone, avater) values ('Emlyn', 'edrissell5@free.fr', '6D29E04CD937DC37CB72E42736CA238C', '426-753-9984', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); diff --git a/server/database/config/build.js b/server/database/config/build.js index 152437f..93646ef 100644 --- a/server/database/config/build.js +++ b/server/database/config/build.js @@ -2,9 +2,10 @@ const { readFileSync } = require('fs'); const { join } = require('path'); const connection = require('../connection'); + const dbBuild = () => { let sql = readFileSync(join(__dirname, 'build.sql')).toString(); - sql+= readFileSync(join(__dirname, 'fakeData.sql')).toString(); + sql += readFileSync(join(__dirname, 'fakeData.sql')).toString(); return connection.query(sql); }; -module.exports = dbBuild; \ No newline at end of file +module.exports = { dbBuild }; diff --git a/server/database/config/bulid.sql b/server/database/config/build.sql similarity index 100% rename from server/database/config/bulid.sql rename to server/database/config/build.sql diff --git a/server/database/config/fakeData.sql b/server/database/config/fakeData.sql index e69de29..5f62648 100644 --- a/server/database/config/fakeData.sql +++ b/server/database/config/fakeData.sql @@ -0,0 +1,43 @@ +insert into admins (username, password , email) values ('ameera', 'F1A1CC71ED10594F97B1B6CF94A00727', 'ameera2021abed@gmail.com'); +insert into admins (username, password , email) values ('haroon', 'F1A1CC71ED10594F97B1B6CF94A00727', 'hro19502001@gmail.com'); +insert into admins (username, password , email) values ('elham', 'F1A1CC71ED10594F97B1B6CF94A00727', 'elham2000fadel@gmail.com'); +insert into admins (username, password , email) values ('sallah', 'F1A1CC71ED10594F97B1B6CF94A00727', 'mohmsal96@gmail.com'); +insert into agents (name, email, password , phone, avater) values ('Kai', 'kallport0@patch.com', '6D29E04CD937DC37CB72E42736CA238C', '481-649-8020', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); +insert into agents (name, email, password , phone, avater) values ('Trixie', 'tbeadon1@plala.or.jp', '6D29E04CD937DC37CB72E42736CA238C', '663-871-7450', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); +insert into agents (name, email, password , phone, avater) values ('Allina', 'aburford2@tumblr.com', '6D29E04CD937DC37CB72E42736CA238C', '630-385-8312', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); +insert into agents (name, email, password , phone, avater) values ('Maye', 'mstrass3@yellowpages.com', '6D29E04CD937DC37CB72E42736CA238C', '210-886-2847', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); +insert into agents (name, email, password , phone, avater) values ('Lillian', 'abutrford2@tumblr.com', '6D29E04CD937DC37CB72E42736CA238C', '270-209-1221', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); +insert into agents (name, email, password , phone, avater) values ('Emlyn', 'edrissell5@free.fr', '6D29E04CD937DC37CB72E42736CA238C', '426-753-9984', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrVnja3DFheGQjch5AL1n0Rk8nOFHm6Ny60w&usqp=CAU'); +insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (1, 'suscipit ligula in', '190483.22', 'tristique', 'Buy', 'House', '3152 Morningstar Park', 'Edinburgh of the Seven Seas', 'Saint Helena', 2, 1, 1, 194, false, 2, false); +insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (2, 'ipsum primis in', '242471.89', 'est quam pharetra magna ac consequat metus sapien ut nunc vestibulum ante', 'Buy', 'House', '100 Butternut Hill', 'Bern', 'Switzerland', 1, 2, 2, 226, true, 5, true); +insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (3, 'rhoncus sed vestibulum', '84726.00', 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', 'Buy', 'House', '0824 Mcguire Way', 'Kungshamn', 'Sweden', 1, 3, 3, 235, true, 5, false); +insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (4, 'sociis natoque penatibus et', '106226.71', 'quis odio consequat', 'Buy', 'House', '15918 Mcguire Point', 'Ranong', 'Thailand', 2, 4, 4, 244, true, 1, false); +insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (5, 'in faucibus orci luctus', '116162.27', 'parturient montes nascetur ridiculus mus vivamus vestibulum sagittis sapien cum', 'Buy', 'House', '898 Dixon Crossing', 'Gelap', 'Indonesia', 3, 2, 4, 150, false, 3, false); +insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (6, 'vestibulum ante ipsum primis', '194193.55', 'leo odio porttitor id consequat in consequat ut nulla sed', 'Buy', 'House', '0891 7th Park', 'Álimos', 'Greece', 1, 3, 2, 174, false, 1, false); +insert into images ( estate_id, image) values (1,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); +insert into images ( estate_id, image) values (1,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); +insert into images ( estate_id, image) values (1,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); +insert into images ( estate_id, image) values (1,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); + +insert into images ( estate_id, image) values (2,'https://cdn.vox-cdn.com/thumbor/6itLJS9BZ-B5gXPjM1AB_z-ZKVI=/0x0:3000x2000/1200x800/filters:focal(1260x760:1740x1240)/cdn.vox-cdn.com/uploads/chorus_image/image/65890203/iStock_1067331614.7.jpg'); +insert into images ( estate_id, image) values (2,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); +insert into images ( estate_id, image) values (2,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); +insert into images ( estate_id, image) values (2,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); + +insert into images ( estate_id, image) values (3,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSh4O9GCySQw_9C24XfInhq-lYgfnHlRSMB5g&usqp=CAU'); +insert into images ( estate_id, image) values (3,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); +insert into images ( estate_id, image) values (3,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); +insert into images ( estate_id, image) values (3,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); +insert into images ( estate_id, image) values (4,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); +insert into images ( estate_id, image) values (4,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); +insert into images ( estate_id, image) values (4,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); +insert into images ( estate_id, image) values (4,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); + +insert into images ( estate_id, image) values (5,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTsj7rODPg-8QIdi6VONhE84ZFng3D5WpNfbA&usqp=CAU'); +insert into images ( estate_id, image) values (5,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); +insert into images ( estate_id, image) values (5,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); +insert into images ( estate_id, image) values (5,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); +insert into images ( estate_id, image) values (6,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSBOKk95d1JPgPWHYPk_Z2NXd_ntTr-N0E0yQ&usqp=CAU'); +insert into images ( estate_id, image) values (6,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); +insert into images ( estate_id, image) values (6,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); +insert into images ( estate_id, image) values (6,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); diff --git a/server/database/config/imagesFackData.sql b/server/database/config/imagesFackData.sql deleted file mode 100644 index adf591e..0000000 --- a/server/database/config/imagesFackData.sql +++ /dev/null @@ -1,27 +0,0 @@ -insert into images ( estate_id, image) values (1,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); -insert into images ( estate_id, image) values (1,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); -insert into images ( estate_id, image) values (1,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); -insert into images ( estate_id, image) values (1,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); - -insert into images ( estate_id, image) values (2,'https://cdn.vox-cdn.com/thumbor/6itLJS9BZ-B5gXPjM1AB_z-ZKVI=/0x0:3000x2000/1200x800/filters:focal(1260x760:1740x1240)/cdn.vox-cdn.com/uploads/chorus_image/image/65890203/iStock_1067331614.7.jpg'); -insert into images ( estate_id, image) values (2,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); -insert into images ( estate_id, image) values (2,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); -insert into images ( estate_id, image) values (2,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); - -insert into images ( estate_id, image) values (3,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSh4O9GCySQw_9C24XfInhq-lYgfnHlRSMB5g&usqp=CAU'); -insert into images ( estate_id, image) values (3,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); -insert into images ( estate_id, image) values (3,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); -insert into images ( estate_id, image) values (3,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); -insert into images ( estate_id, image) values (4,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); -insert into images ( estate_id, image) values (4,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); -insert into images ( estate_id, image) values (4,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); -insert into images ( estate_id, image) values (4,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); - -insert into images ( estate_id, image) values (5,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTsj7rODPg-8QIdi6VONhE84ZFng3D5WpNfbA&usqp=CAU'); -insert into images ( estate_id, image) values (5,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); -insert into images ( estate_id, image) values (5,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); -insert into images ( estate_id, image) values (5,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); -insert into images ( estate_id, image) values (6,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSBOKk95d1JPgPWHYPk_Z2NXd_ntTr-N0E0yQ&usqp=CAU'); -insert into images ( estate_id, image) values (6,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/1.tobiarchitects.1526566679.5654.jpg'); -insert into images ( estate_id, image) values (6,'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHpF_yr6jMER79FRSejAszXCsyd__87nEF6g&usqp=CAU'); -insert into images ( estate_id, image) values (6,'https://images.unsplash.com/photo-1580587771525-78b9dba3b914?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bHV4dXJ5JTIwaG91c2V8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80'); diff --git a/server/database/config/realStateFackData.sql b/server/database/config/realStateFackData.sql deleted file mode 100644 index 42314f7..0000000 --- a/server/database/config/realStateFackData.sql +++ /dev/null @@ -1,6 +0,0 @@ -insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (1, 'suscipit ligula in', '$190483.22', 'tristique', 'Buy', 'House', '3152 Morningstar Park', 'Edinburgh of the Seven Seas', 'Saint Helena', 2, 1, 1, 194, false, 2, false); -insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (2, 'ipsum primis in', '$242471.89', 'est quam pharetra magna ac consequat metus sapien ut nunc vestibulum ante', 'Buy', 'House', '100 Butternut Hill', 'Bern', 'Switzerland', 1, 2, 2, 226, true, 5, true); -insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (3, 'rhoncus sed vestibulum', '$84726.00', 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', 'Buy', 'House', '0824 Mcguire Way', 'Kungshamn', 'Sweden', 1, 3, 3, 235, true, 5, false); -insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (4, 'sociis natoque penatibus et', '$106226.71', 'quis odio consequat', 'Buy', 'House', '15918 Mcguire Point', 'Ranong', 'Thailand', 2, 4, 4, 244, true, 1, false); -insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (5, 'in faucibus orci luctus', '$116162.27', 'parturient montes nascetur ridiculus mus vivamus vestibulum sagittis sapien cum', 'Buy', 'House', '898 Dixon Crossing', 'Gelap', 'Indonesia', 3, 2, 4, 150, false, 3, false); -insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (6, 'vestibulum ante ipsum primis', '$194193.55', 'leo odio porttitor id consequat in consequat ut nulla sed', 'Buy', 'House', '0891 7th Park', 'Álimos', 'Greece', 1, 3, 2, 174, false, 1, false); diff --git a/server/database/connection.js b/server/database/connection.js index b26aafd..7ef7a43 100644 --- a/server/database/connection.js +++ b/server/database/connection.js @@ -1,6 +1,6 @@ require('env2')('.env'); -const {Pool} = require('pg'); - +const { Pool } = require('pg'); + const { NODE_ENV, DATABASE_URL_DEV, DATABASE_URL, DATABASE_URL_TEST, } = process.env; @@ -22,4 +22,4 @@ const options = { connectionString: dbUrl, ssl: { rejectUnauthorized: false }, }; -module.exports = new Pool(options); \ No newline at end of file +module.exports = new Pool(options); diff --git a/server/database/quieres/getAllUsersQuery.js b/server/database/quieres/getAllUsersQuery.js new file mode 100644 index 0000000..24231b0 --- /dev/null +++ b/server/database/quieres/getAllUsersQuery.js @@ -0,0 +1,5 @@ +const connection = require('../connection'); + +const getAllUsersQuery = () => connection.query('SELECT * FROM agents'); + +module.exports = getAllUsersQuery; diff --git a/server/database/quieres/index.js b/server/database/quieres/index.js index e69de29..61e3b66 100644 --- a/server/database/quieres/index.js +++ b/server/database/quieres/index.js @@ -0,0 +1,6 @@ +const getAllUsersQuery = require('./getAllUsersQuery'); + +module.exports = { + getAllUsersQuery, + +}; diff --git a/server/routes/index.js b/server/routes/index.js index f041226..0c66e24 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,8 +1,11 @@ const express = require('express'); const { notFoundError, serverError } = require('../controllers/errors'); +const { getAllUsers } = require('../controllers'); const router = express.Router(); +router.get('/users', getAllUsers); router.use(notFoundError); router.use(serverError); + module.exports = router; diff --git a/server/test/index.test.js b/server/test/index.test.js new file mode 100644 index 0000000..50c69d0 --- /dev/null +++ b/server/test/index.test.js @@ -0,0 +1,18 @@ +/* eslint-disable no-undef */ +const supertest = require('supertest'); +const app = require('../app'); +const { dbBuild } = require('../database/config/build'); +const connection = require('../database/connection'); + +beforeEach(() => dbBuild()); +afterAll(() => connection.end()); + +describe('Tests Server', () => { + test('get all users', async () => { + const res = await supertest(app) + .get('/api/v1/users') + .expect(200) + .expect('Content-Type', /json/); + return expect(6).toEqual(res.body.data.length); + }); +});