Skip to content

Commit

Permalink
Merge pull request #29 from GSG-G10/17-get-users
Browse files Browse the repository at this point in the history
create end point to get all users #17
  • Loading branch information
Mu7ammadAbed authored Oct 27, 2021
2 parents 4650057 + 21930ac commit ae9944e
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 48 deletions.
3 changes: 3 additions & 0 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const getAllUsers = require('./users/getAllUsers');

module.exports = { getAllUsers };
13 changes: 13 additions & 0 deletions server/controllers/users/getAllUsers.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions server/controllers/users/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const getAllUsers = require('./getAllUsers');

module.exports = { getAllUsers };
4 changes: 0 additions & 4 deletions server/database/config/adminsFack Data.sql

This file was deleted.

6 changes: 0 additions & 6 deletions server/database/config/agentsFackData.sql

This file was deleted.

5 changes: 3 additions & 2 deletions server/database/config/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
module.exports = { dbBuild };
File renamed without changes.
43 changes: 43 additions & 0 deletions server/database/config/fakeData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
insert into admins (username, password , email) values ('ameera', 'F1A1CC71ED10594F97B1B6CF94A00727', '[email protected]');
insert into admins (username, password , email) values ('haroon', 'F1A1CC71ED10594F97B1B6CF94A00727', '[email protected]');
insert into admins (username, password , email) values ('elham', 'F1A1CC71ED10594F97B1B6CF94A00727', '[email protected]');
insert into admins (username, password , email) values ('sallah', 'F1A1CC71ED10594F97B1B6CF94A00727', '[email protected]');
insert into agents (name, email, password , phone, avater) values ('Kai', '[email protected]', '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', '[email protected]', '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', '[email protected]', '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', '[email protected]', '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', '[email protected]', '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', '[email protected]', '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');
27 changes: 0 additions & 27 deletions server/database/config/imagesFackData.sql

This file was deleted.

6 changes: 0 additions & 6 deletions server/database/config/realStateFackData.sql

This file was deleted.

6 changes: 3 additions & 3 deletions server/database/connection.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,4 +22,4 @@ const options = {
connectionString: dbUrl,
ssl: { rejectUnauthorized: false },
};
module.exports = new Pool(options);
module.exports = new Pool(options);
5 changes: 5 additions & 0 deletions server/database/quieres/getAllUsersQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const connection = require('../connection');

const getAllUsersQuery = () => connection.query('SELECT * FROM agents');

module.exports = getAllUsersQuery;
6 changes: 6 additions & 0 deletions server/database/quieres/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const getAllUsersQuery = require('./getAllUsersQuery');

module.exports = {
getAllUsersQuery,

};
3 changes: 3 additions & 0 deletions server/routes/index.js
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 18 additions & 0 deletions server/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit ae9944e

Please sign in to comment.