Skip to content

Commit

Permalink
edit conflict #15
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedsalah7 committed Oct 31, 2021
2 parents ad622a3 + aa8e9f6 commit 4b17a90
Show file tree
Hide file tree
Showing 25 changed files with 196 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
.env
package-lock.json
package-lock.json
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Real Estate is an App that facilitates to access and rent or buy available homes
## Team Members :busts_in_silhouette::-
1. Mohammed haroon
2. MOhammed salah
3. ameera
3. Ameera Abed Alnaser Khalil
4. Elham Fadel


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "cross-env NODE_ENV=production node server",
"dev": "cross-env NODE_ENV=development nodemon server",
"test": "cross-env NODE_ENV=test jest",
"build:db": "NODE_ENV=test node server/database/data/build"
"build:db": "cross-env NODE_ENV=development node server/database/config"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (NODE_ENV === 'production') {
res.sendFile(join(__dirname, '..', 'client', 'build', 'index.html'));
});
}
router.use(notFoundError);
router.use(serverError);
app.use(notFoundError);
app.use(serverError);

module.exports = app;
8 changes: 7 additions & 1 deletion server/controllers/users/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const signup = require('./signup');
const userEstateshandler = require('./userEstates');
const getAllUsers = require('./getAllUsers');
const login = require('./login');

module.exports = { getAllUsers, userEstateshandler, login };
module.exports = {
signup,
getAllUsers,
userEstateshandler,
login,
};
1 change: 1 addition & 0 deletions server/controllers/users/login.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable consistent-return */
const bcrypt = require('bcrypt');
const { loginSchema } = require('../../utils/validation/loginSchema');
Expand Down
24 changes: 24 additions & 0 deletions server/controllers/users/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { hash } = require('bcrypt');
const agentSchema = require('../../utils/validation/agentSchema');
const signUpQuery = require('../../database/quieres/account/signUp');
const { signToken } = require('../../utils');

module.exports = async (req, res, next) => {
try {
const {
error, value: {
password, email, username, phone,
},
} = agentSchema.validate(req.body);
if (error) return res.status(400).json({ message: error.details[0].message });
const hasedPasword = await hash(password, 10);
await signUpQuery(username, email, phone, hasedPasword);
const token = await signToken(email, username, phone);
return res.status(201).cookie('token', token).json({ message: 'user created' });
} catch (err) {
if (err.code === '23505') {
return res.status(400).json({ message: 'The user is already exists' });
}
return next(err);
}
};
2 changes: 1 addition & 1 deletion server/controllers/users/userEstates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const userEstateshandler = async (req, res) => {
data: rows,
});
}
res.status(404).json({
return res.status(404).json({
message: 'enter valid user id',
});
} catch (err) {
Expand Down
5 changes: 3 additions & 2 deletions server/database/config/build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { readFileSync } = require('fs');
const { join } = require('path');

const connection = require('../connection');
const connection = require('./connection');

const dbBuild = () => {
let sql = readFileSync(join(__dirname, 'build.sql')).toString();
sql += readFileSync(join(__dirname, 'fakeData.sql')).toString();
return connection.query(sql);
};
module.exports = { dbBuild };

module.exports = dbBuild;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ switch (NODE_ENV) {
default:
throw new Error('There\'s no environment');
}

const options = {
connectionString: dbUrl,
ssl: { rejectUnauthorized: false },
Expand Down
7 changes: 7 additions & 0 deletions server/database/config/databaseConfig.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE DATABASE housydev;
CREATE USER housyuser WITH superuser password '123456';
ALTER DATABASE housydev OWNER TO housyuser;
-- test db
CREATE DATABASE housytest;
CREATE USER housyuser2 WITH superuser password '123456';
ALTER DATABASE housytest OWNER TO housyuser2;
62 changes: 22 additions & 40 deletions server/database/config/fakeData.sql
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
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 agents (name, email, password , phone)
VALUES ('Kai', '[email protected]', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '677-871-7450'),
('Trixie', '[email protected]', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '0599832685'),
('Allina', '[email protected]', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '630-385-8312');

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 admins (username, password , email) VALUES ('ameera', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'ameera2021abed@gmail.com'),
('haroon', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'hro19502001@gmail.com'),
('elham', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'elham2000fadel@gmail.com'),
('sallah', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'mohmsal96@gmail.com');

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 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),
(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),
(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),
(1, 'sociis natoque penatibus et', 106226.71, 'quis odio consequat', 'Buy', 'House', '15918 Mcguire Point', 'Ranong', 'Thailand', 2, 4, 4, 244, true, 1, false),
(2, '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),
(3, '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 (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');
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'),
(2,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/2.tobiarchitects.1526566679.5654.jpg'),
(3,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/3.tobiarchitects.1526566679.5654.jpg'),
(1,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/4.tobiarchitects.1526566679.5654.jpg'),
(2,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/5.tobiarchitects.1526566679.5654.jpg'),
(3,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/6.tobiarchitects.1526566679.5654.jpg');

13 changes: 13 additions & 0 deletions server/database/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable no-console */
const connection = require('./connection');
const dbBuild = require('./build');

(async () => {
try {
await dbBuild();
console.log('Build Successfully');
connection.end();
} catch (e) {
console.log('Build Failed', e);
}
})();
3 changes: 3 additions & 0 deletions server/database/quieres/account/signUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const connection = require('../../config/connection');

module.exports = (userName, email, phone, password) => connection.query('INSERT INTO agents (name,email,phone,password) VALUES ($1,$2,$3,$4)', [userName, email, phone, password]);
2 changes: 1 addition & 1 deletion server/database/quieres/checkEmailQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const connection = require('../connection');
const connection = require('../config/connection');

const checkEmailQuery = (email) => connection.query('SELECT * FROM agents WHERE email= ($1)', [email]);

Expand Down
2 changes: 1 addition & 1 deletion server/database/quieres/getAllUsersQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const connection = require('../connection');
const connection = require('../config/connection');

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

Expand Down
2 changes: 1 addition & 1 deletion server/database/quieres/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const userEstatesQuery = require('./UserEstatesQuiery');
const userEstatesQuery = require('./userEstatesQuiery');
const getAllUsersQuery = require('./getAllUsersQuery');
const checkEmailQuery = require('./checkEmailQuery');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const connection = require('../connection');
const connection = require('../config/connection');

module.exports = (userId) => connection.query('SELECT * FROM estates WHERE agent_id = $1', [userId]);
7 changes: 7 additions & 0 deletions server/routes/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const router = require('express').Router();
const { logout, login } = require('../controllers');

router.get('/logout', logout);
router.post('/login', login);

module.exports = router;
Empty file added server/routes/estate.js
Empty file.
11 changes: 5 additions & 6 deletions server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const router = require('express').Router();
const { userEstateshandler } = require('../controllers');
const { getAllUsers, logout, login } = require('../controllers');

router.get('/users/:userId/estates', userEstateshandler);
router.post('/login', login);
router.get('/users', getAllUsers);
router.get('/logout', logout);
const auth = require('./auth');
const users = require('./users');

router.use('/', auth);
router.use('/users', users);

module.exports = router;
9 changes: 9 additions & 0 deletions server/routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const router = require('express').Router();
const { userEstateshandler, getAllUsers } = require('../controllers');
const signup = require('../controllers/users/signup');

router.post('/signup', signup);
router.get('/:userId/estates', userEstateshandler);
router.get('/', getAllUsers);

module.exports = router;
Loading

0 comments on commit 4b17a90

Please sign in to comment.