From 0bbcb36122414067cb498d1ea57414f9a7d890f2 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Mon, 25 Oct 2021 22:05:34 +0300 Subject: [PATCH 01/23] sign up schema #11 --- server/utils/validation/signUpSchema.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 server/utils/validation/signUpSchema.js diff --git a/server/utils/validation/signUpSchema.js b/server/utils/validation/signUpSchema.js new file mode 100644 index 0000000..3cc9675 --- /dev/null +++ b/server/utils/validation/signUpSchema.js @@ -0,0 +1,9 @@ +const joi = require('joi'); + +module.exports = joi.object({ + name:joi.string().required(), + email: joi.string().email().required(), + password: joi.string().min(5).required(), + //like +911234567890 + phone: joi.string().pattern(/^\+[0-9]{2}[0-9]{9}$/).required(), +}) From a343ca167b8c4e2c5ffc8b63396b1d8a5ad690e0 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Mon, 25 Oct 2021 22:18:00 +0300 Subject: [PATCH 02/23] sign up query #11 --- server/database/quieres/account/signUp.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 server/database/quieres/account/signUp.js diff --git a/server/database/quieres/account/signUp.js b/server/database/quieres/account/signUp.js new file mode 100644 index 0000000..e79cedf --- /dev/null +++ b/server/database/quieres/account/signUp.js @@ -0,0 +1,2 @@ +const connection = require('../../connection') +module.exports = (userName,email,phone,password)=>connection.query('INSERT INTO users (userName,email,phone,password) VALUES ($1,$2,$3,$4)',[userName,email,phone,password]) \ No newline at end of file From 247d7b0ff6b01fa21e669bb9ace575cc294b43f5 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Mon, 25 Oct 2021 23:34:58 +0300 Subject: [PATCH 03/23] edit name table --- server/database/quieres/account/signUp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/database/quieres/account/signUp.js b/server/database/quieres/account/signUp.js index e79cedf..d8648a4 100644 --- a/server/database/quieres/account/signUp.js +++ b/server/database/quieres/account/signUp.js @@ -1,2 +1,2 @@ const connection = require('../../connection') -module.exports = (userName,email,phone,password)=>connection.query('INSERT INTO users (userName,email,phone,password) VALUES ($1,$2,$3,$4)',[userName,email,phone,password]) \ No newline at end of file +module.exports = (userName,email,phone,password)=>connection.query('INSERT INTO agents (name,email,phone,password) VALUES ($1,$2,$3,$4)',[userName,email,phone,password]) \ No newline at end of file From c2c0d2a2be10358cbedb69cba90f54f5c603fb68 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Tue, 26 Oct 2021 07:24:27 +0300 Subject: [PATCH 04/23] signup --- server/controllers/users/index.js | 4 ++++ server/controllers/users/signup.js | 16 ++++++++++++++++ server/routes/index.js | 1 + 3 files changed, 21 insertions(+) create mode 100644 server/controllers/users/signup.js diff --git a/server/controllers/users/index.js b/server/controllers/users/index.js index e69de29..dc07723 100644 --- a/server/controllers/users/index.js +++ b/server/controllers/users/index.js @@ -0,0 +1,4 @@ +const signup = require('./signup'); +module.exports ={ + signup +} diff --git a/server/controllers/users/signup.js b/server/controllers/users/signup.js new file mode 100644 index 0000000..e9cdf8b --- /dev/null +++ b/server/controllers/users/signup.js @@ -0,0 +1,16 @@ +const { hash } = require('bcrypt'); +const signupSchema = require("../../utils/validation/signUpSchema") +const signUpQuery = require("../../database/quieres/account/signUp") + +module.exports = sync (req, res, next) => { + + try { + const {username,email,password,phone} = await signupSchema.validate(req.body); + const hasedPasword = await hash(password, 8); + await signUpQuery(username,email,phone,hasedPasword); + req.user = {username,email,phone}; + next(); + } catch (err) {next(err);} + +}; + diff --git a/server/routes/index.js b/server/routes/index.js index e69de29..7ae6ed1 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -0,0 +1 @@ +const signupControllers = require('../controllers/users/signup'); \ No newline at end of file From faf3b41103232ab0348408b6be4727cd8fd7def4 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Tue, 26 Oct 2021 10:04:01 +0300 Subject: [PATCH 05/23] sign up --- server/controllers/users/signup.js | 1 - server/routes/index.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/server/controllers/users/signup.js b/server/controllers/users/signup.js index e9cdf8b..0bbdeca 100644 --- a/server/controllers/users/signup.js +++ b/server/controllers/users/signup.js @@ -11,6 +11,5 @@ module.exports = sync (req, res, next) => { req.user = {username,email,phone}; next(); } catch (err) {next(err);} - }; diff --git a/server/routes/index.js b/server/routes/index.js index 7ae6ed1..258e089 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1 +1 @@ -const signupControllers = require('../controllers/users/signup'); \ No newline at end of file +const signupControllers = require('../controllers/users/'); From 8e86b40e9b996dd2b914bc262278531a31f6ca84 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Wed, 27 Oct 2021 22:46:22 +0300 Subject: [PATCH 06/23] resolve conflicts #11 --- server/controllers/users/index.js | 11 ++---- server/database/config/fakeData.sql | 46 ----------------------- server/database/config/imagesFackData.sql | 1 - 3 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 server/database/config/imagesFackData.sql diff --git a/server/controllers/users/index.js b/server/controllers/users/index.js index 0293e56..1716e21 100644 --- a/server/controllers/users/index.js +++ b/server/controllers/users/index.js @@ -1,12 +1,9 @@ -<<<<<<< HEAD const signup = require('./signup'); +const userEstateshandler = require('./userEstates'); +const getAllUsers = require('./getAllUsers'); module.exports = { signup, + getAllUsers, + userEstateshandler, }; -======= -const userEstateshandler = require('./userEstates'); -const getAllUsers = require('./getAllUsers'); - -module.exports = { getAllUsers, userEstateshandler }; ->>>>>>> 1c56f7cf651c1916acd88ff05d55b958056b73aa diff --git a/server/database/config/fakeData.sql b/server/database/config/fakeData.sql index 71a729d..c45598f 100644 --- a/server/database/config/fakeData.sql +++ b/server/database/config/fakeData.sql @@ -1,4 +1,3 @@ -<<<<<<< HEAD -- INSERT INTO agents (name, email, password , phone) VALUES ('Kai', 'kallport0@patch.com', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '677-871-7450'), @@ -24,48 +23,3 @@ INSERT INTO images ( estate_id, image) VALUES (1,'https://archello.s3.eu-central (5,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/5.tobiarchitects.1526566679.5654.jpg'), (6,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/6.tobiarchitects.1526566679.5654.jpg'); -======= -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'); ->>>>>>> 1c56f7cf651c1916acd88ff05d55b958056b73aa diff --git a/server/database/config/imagesFackData.sql b/server/database/config/imagesFackData.sql deleted file mode 100644 index 8b13789..0000000 --- a/server/database/config/imagesFackData.sql +++ /dev/null @@ -1 +0,0 @@ - From 7e799194e2673965af1c4fa14d4a31d672fb3f24 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Wed, 27 Oct 2021 23:54:33 +0300 Subject: [PATCH 07/23] sign up with test & validation #11 --- server/app.js | 2 -- server/controllers/errors/serverError.js | 2 +- server/controllers/users/signup.js | 15 +++++---- server/database/quieres/account/signUp.js | 2 +- server/index.js | 1 + server/test/index.test.js | 38 +++++++++++++++++++++++ 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/server/app.js b/server/app.js index d1e1d13..e2da538 100644 --- a/server/app.js +++ b/server/app.js @@ -5,8 +5,6 @@ const cookieParser = require('cookie-parser'); const router = require('./routes'); const { notFoundError, serverError } = require('./controllers/errors'); -require('env2')('.env'); - const { env: { PORT, NODE_ENV } } = process; const app = express(); diff --git a/server/controllers/errors/serverError.js b/server/controllers/errors/serverError.js index 46394ee..0266284 100644 --- a/server/controllers/errors/serverError.js +++ b/server/controllers/errors/serverError.js @@ -1,5 +1,5 @@ /* eslint-disable no-unused-vars */ -const serverError = (req, res, next, err) => { +const serverError = (err, req, res, next) => { res.status(500).json({ message: 'Server Error' }); }; diff --git a/server/controllers/users/signup.js b/server/controllers/users/signup.js index 240e5e4..43fba8d 100644 --- a/server/controllers/users/signup.js +++ b/server/controllers/users/signup.js @@ -1,6 +1,7 @@ const { hash } = require('bcrypt'); const signupSchema = require('../../utils/validation/signUpSchema'); const signUpQuery = require('../../database/quieres/account/signUp'); +const { signToken } = require('../../utils'); module.exports = async (req, res, next) => { try { @@ -11,15 +12,13 @@ module.exports = async (req, res, next) => { } = signupSchema.validate(req.body); if (error) return res.status(400).json({ error: error.details[0].message }); const hasedPasword = await hash(password, 10); - console.log(hasedPasword); - const { rows } = await signUpQuery(username, email, phone, hasedPasword); - if (rows[0]) { + 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({ error: 'username or phone already exists' }); } - req.user = { username, email, phone }; - next(); - } catch (err) { - console.log(err); - // next(err); + return next(err); } }; diff --git a/server/database/quieres/account/signUp.js b/server/database/quieres/account/signUp.js index 18af875..0207f96 100644 --- a/server/database/quieres/account/signUp.js +++ b/server/database/quieres/account/signUp.js @@ -1,3 +1,3 @@ const connection = require('../../connection'); -module.exports = (userName, email, phone, password) => connection.query('INSERT INTO agents (name,email,phone,password) VALUES ($1,$2,$3,$4) RETURNING * ', [userName, email, phone, password]); +module.exports = (userName, email, phone, password) => connection.query('INSERT INTO agents (name,email,phone,password) VALUES ($1,$2,$3,$4)', [userName, email, phone, password]); diff --git a/server/index.js b/server/index.js index 991b1f9..77625cc 100644 --- a/server/index.js +++ b/server/index.js @@ -1,3 +1,4 @@ +require('env2')('.env'); const app = require('./app'); const port = app.get('port'); diff --git a/server/test/index.test.js b/server/test/index.test.js index d5dd994..cf7416e 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -61,3 +61,41 @@ describe('user estates', () => { }); }); }); +describe('test signup endpoint with all cases ', () => { + test('test sign up endpoint when success', (done) => { + request(app) + .post('/api/v1/signup') + .send({ + username: 'test', + password: 'test123456', + email: 'test@gmail.com', + phone: '0597853626', + }) + .expect(201) + .expect((response) => expect(response.header['set-cookie'][0].split('=')[0]).toBe('token')) + .end((err) => { + if (err) { + return done(err); + } + return done(); + }); + }); + + test('test signup username or phone already exists', (done) => { + request(app) + .post('/api/v1/signup') + .send({ + username: 'test', + password: 'test123456', + email: 'test@gmail.com', + phone: '0597853626', + }) + .expect(400) + .end((err) => { + if (err) { + return done(err); + } + return done(); + }); + }); +}); From 5a4f107342a7d77e51a5e7f83b97541dce1a0bca Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Wed, 27 Oct 2021 23:58:11 +0300 Subject: [PATCH 08/23] fix ssl #11 --- server/database/connection.js | 2 +- server/utils/validation/signUpSchema.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/server/database/connection.js b/server/database/connection.js index 6638156..c9fbb78 100644 --- a/server/database/connection.js +++ b/server/database/connection.js @@ -19,7 +19,7 @@ switch (NODE_ENV) { } const options = { connectionString: dbUrl, - ssl: false, + ssl: { rejectUnauthorized: false }, }; module.exports = new Pool(options); diff --git a/server/utils/validation/signUpSchema.js b/server/utils/validation/signUpSchema.js index 8ce7a84..76a5fa6 100644 --- a/server/utils/validation/signUpSchema.js +++ b/server/utils/validation/signUpSchema.js @@ -4,6 +4,5 @@ module.exports = joi.object({ username: joi.string().required(), email: joi.string().email().required(), password: joi.string().min(5).required(), - // like +911234567890 phone: joi.string().length(10).required(), }); From 5f2fd2f7f76e0dc7d404cdede069eefe43b1d915 Mon Sep 17 00:00:00 2001 From: Muhammad Abdulhadi Date: Thu, 28 Oct 2021 15:15:55 +0300 Subject: [PATCH 09/23] fix eslint and userEstateModule --- .eslintrc.json | 2 +- package.json | 2 +- server/app.js | 1 - server/controllers/users/userEstates.js | 2 +- .../quieres/{UserEstatesQuiery.js => userEstatesQuiery.js} | 0 server/index.js | 1 + 6 files changed, 4 insertions(+), 4 deletions(-) rename server/database/quieres/{UserEstatesQuiery.js => userEstatesQuiery.js} (100%) diff --git a/.eslintrc.json b/.eslintrc.json index c00798a..7276943 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,7 @@ "airbnb-base" ], "parserOptions": { - "ecmaVersion": "13" + "ecmaVersion": "latest" }, "rules": { } diff --git a/package.json b/package.json index 26c7405..c3dc9d5 100644 --- a/package.json +++ b/package.json @@ -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": "NODE_ENV=development node server/database/config/build" }, "repository": { "type": "git", diff --git a/server/app.js b/server/app.js index 3d0aac1..7bc115b 100644 --- a/server/app.js +++ b/server/app.js @@ -4,7 +4,6 @@ const compression = require('compression'); const cookieParser = require('cookie-parser'); const { notFoundError, serverError } = require('./controllers/errors'); const router = require('./routes'); -require('env2')('.env'); const { env: { PORT, NODE_ENV } } = process; diff --git a/server/controllers/users/userEstates.js b/server/controllers/users/userEstates.js index 63622a3..5f7a1ae 100644 --- a/server/controllers/users/userEstates.js +++ b/server/controllers/users/userEstates.js @@ -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) { diff --git a/server/database/quieres/UserEstatesQuiery.js b/server/database/quieres/userEstatesQuiery.js similarity index 100% rename from server/database/quieres/UserEstatesQuiery.js rename to server/database/quieres/userEstatesQuiery.js diff --git a/server/index.js b/server/index.js index 991b1f9..77625cc 100644 --- a/server/index.js +++ b/server/index.js @@ -1,3 +1,4 @@ +require('env2')('.env'); const app = require('./app'); const port = app.get('port'); From 260ffe3ffa7034ed7844270588f5783cf96f32b1 Mon Sep 17 00:00:00 2001 From: muhammadharoun Date: Thu, 28 Oct 2021 15:42:23 +0300 Subject: [PATCH 10/23] edit estate function and query --- .eslintrc.json | 2 +- server/app.js | 4 +- server/controllers/estates/editEstate.js | 43 +++++++++++++++++++++ server/controllers/estates/index.js | 3 ++ server/controllers/users/userEstates.js | 1 + server/database/quieres/editEstatesQuery.js | 37 ++++++++++++++++++ server/database/quieres/index.js | 5 ++- server/routes/index.js | 3 ++ server/test/index.test.js | 25 ++++++++++++ 9 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 server/controllers/estates/editEstate.js create mode 100644 server/database/quieres/editEstatesQuery.js diff --git a/.eslintrc.json b/.eslintrc.json index c00798a..92f5c35 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,7 @@ "airbnb-base" ], "parserOptions": { - "ecmaVersion": "13" + "ecmaVersion":"latest" }, "rules": { } diff --git a/server/app.js b/server/app.js index 3d0aac1..a7ace9c 100644 --- a/server/app.js +++ b/server/app.js @@ -1,10 +1,10 @@ +require('env2')('.env'); const express = require('express'); const { join } = require('path'); const compression = require('compression'); const cookieParser = require('cookie-parser'); const { notFoundError, serverError } = require('./controllers/errors'); const router = require('./routes'); -require('env2')('.env'); const { env: { PORT, NODE_ENV } } = process; @@ -26,6 +26,6 @@ if (NODE_ENV === 'production') { }); } router.use(notFoundError); -router.use(serverError); +// router.use(serverError); module.exports = app; diff --git a/server/controllers/estates/editEstate.js b/server/controllers/estates/editEstate.js new file mode 100644 index 0000000..e9d503c --- /dev/null +++ b/server/controllers/estates/editEstate.js @@ -0,0 +1,43 @@ +/* eslint-disable no-console */ +const { editEstateQuery } = require('../../database/quieres'); + +const editEstate = async (req, res, next) => { + const { estateId } = req.params; + const { + title, + price, + description, + type, + category, + street, + city, + region, + bathrooms, + bedrooms, + rooms, + space, + available, + } = req.body; + try { + await editEstateQuery( + estateId, + title, + price, + description, + type, + category, + street, + city, + region, + bathrooms, + bedrooms, + rooms, + space, + available, + ); + res.json(); + } catch (err) { + next(err); + } +}; +module.exports = editEstate; diff --git a/server/controllers/estates/index.js b/server/controllers/estates/index.js index e69de29..6f71046 100644 --- a/server/controllers/estates/index.js +++ b/server/controllers/estates/index.js @@ -0,0 +1,3 @@ +const editEstate = require('./editEstate'); + +module.exports = { editEstate }; diff --git a/server/controllers/users/userEstates.js b/server/controllers/users/userEstates.js index 63622a3..e29d815 100644 --- a/server/controllers/users/userEstates.js +++ b/server/controllers/users/userEstates.js @@ -1,5 +1,6 @@ const { userEstatesQuery } = require('../../database/quieres/index'); +// eslint-disable-next-line consistent-return const userEstateshandler = async (req, res) => { const { userId } = req.params; diff --git a/server/database/quieres/editEstatesQuery.js b/server/database/quieres/editEstatesQuery.js new file mode 100644 index 0000000..e4d1651 --- /dev/null +++ b/server/database/quieres/editEstatesQuery.js @@ -0,0 +1,37 @@ +/* eslint-disable max-len */ +const connection = require('../connection'); + +const editEstateQuery = (id, + title, + price, + description, + type, + category, + street, + city, + region, + bathrooms, + bedrooms, + rooms, + space, + available) => connection.query( + 'UPDATE estates SET title = $1,price =$2,description=$3,type=$4,category=$5,street=$6,city=$7,region=$8,bathrooms=$9,bedrooms=$10,rooms=$11,space=$12,available=$13 WHERE id = $14;', + [ + title, + price, + description, + type, + category, + street, + city, + region, + bathrooms, + bedrooms, + rooms, + space, + available, + id, + ], +); + +module.exports = editEstateQuery; diff --git a/server/database/quieres/index.js b/server/database/quieres/index.js index 386595b..8100a45 100644 --- a/server/database/quieres/index.js +++ b/server/database/quieres/index.js @@ -1,8 +1,9 @@ -const userEstatesQuery = require('./userEstatesQuiery'); +const userEstatesQuery = require('./UserEstatesQuiery'); const getAllUsersQuery = require('./getAllUsersQuery'); +const editEstateQuery = require('./editEstatesQuery'); module.exports = { getAllUsersQuery, userEstatesQuery, - + editEstateQuery, }; diff --git a/server/routes/index.js b/server/routes/index.js index 92cf993..05ae9ff 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,8 +1,11 @@ const router = require('express').Router(); const { userEstateshandler } = require('../controllers'); const { getAllUsers, logout } = require('../controllers'); +const { editEstate } = require('../controllers/estates'); router.get('/users/:userId/estates', userEstateshandler); +router.put('/estate/:estateId', editEstate); + router.get('/users', getAllUsers); router.get('/logout', logout); diff --git a/server/test/index.test.js b/server/test/index.test.js index d5dd994..0a161a5 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -61,3 +61,28 @@ describe('user estates', () => { }); }); }); + +// describe('edit estates', () => { +// test('edit estates', async () => { +// const res = await supertest(app) +// .get('api/v1/estate/3') +// .send({ +// title: '1', +// price: 10, +// description: 's', +// type: 's', +// category: 's', +// street: 's', +// city: 's', +// region: 's', +// bathrooms: 's', +// bedrooms: 's', +// rooms: 's', +// space: 's', +// available: false, +// }) +// .expect(200) +// .expect('Content-Type', /json/); +// console.log(res); +// }); +// }); From 98fdfa83c17929ef396648e82c40d0b679812f0e Mon Sep 17 00:00:00 2001 From: Muhammad Abdulhadi Date: Thu, 28 Oct 2021 16:20:23 +0300 Subject: [PATCH 11/23] Create build:db script --- .gitignore | 2 +- .vscode/settings.json | 2 +- README.md | 2 +- package.json | 2 +- server/database/config/build.js | 5 +++-- server/database/{ => config}/connection.js | 3 +++ server/database/config/databaseConfig.sql | 7 +++++++ server/database/config/index.js | 13 +++++++++++++ server/database/quieres/getAllUsersQuery.js | 2 +- server/database/quieres/userEstatesQuiery.js | 2 +- server/index.js | 1 - server/test/index.test.js | 4 ++-- 12 files changed, 34 insertions(+), 11 deletions(-) rename server/database/{ => config}/connection.js (95%) create mode 100644 server/database/config/databaseConfig.sql create mode 100644 server/database/config/index.js diff --git a/.gitignore b/.gitignore index 6fe20f0..5693cd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules .env -package-lock.json \ No newline at end of file +package-lock.json diff --git a/.vscode/settings.json b/.vscode/settings.json index c3a7563..6681eb0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,4 +4,4 @@ "editor.codeActionsOnSave": { "source.fixAll.eslint": true } - } \ No newline at end of file +} \ No newline at end of file diff --git a/README.md b/README.md index b0579fa..4a8a767 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index c3dc9d5..84ccd3e 100644 --- a/package.json +++ b/package.json @@ -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=development node server/database/config/build" + "build:db": "cross-env NODE_ENV=development node server/database/config" }, "repository": { "type": "git", diff --git a/server/database/config/build.js b/server/database/config/build.js index 93646ef..a35d117 100644 --- a/server/database/config/build.js +++ b/server/database/config/build.js @@ -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; diff --git a/server/database/connection.js b/server/database/config/connection.js similarity index 95% rename from server/database/connection.js rename to server/database/config/connection.js index e2c8673..572fd03 100644 --- a/server/database/connection.js +++ b/server/database/config/connection.js @@ -1,3 +1,4 @@ +require('env2')('.env'); const { Pool } = require('pg'); const { @@ -17,8 +18,10 @@ switch (NODE_ENV) { default: throw new Error('There\'s no environment'); } + const options = { connectionString: dbUrl, ssl: { rejectUnauthorized: false }, }; + module.exports = new Pool(options); diff --git a/server/database/config/databaseConfig.sql b/server/database/config/databaseConfig.sql new file mode 100644 index 0000000..7e74e32 --- /dev/null +++ b/server/database/config/databaseConfig.sql @@ -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; \ No newline at end of file diff --git a/server/database/config/index.js b/server/database/config/index.js new file mode 100644 index 0000000..b975dc6 --- /dev/null +++ b/server/database/config/index.js @@ -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); + } +})(); diff --git a/server/database/quieres/getAllUsersQuery.js b/server/database/quieres/getAllUsersQuery.js index 24231b0..680e88c 100644 --- a/server/database/quieres/getAllUsersQuery.js +++ b/server/database/quieres/getAllUsersQuery.js @@ -1,4 +1,4 @@ -const connection = require('../connection'); +const connection = require('../config/connection'); const getAllUsersQuery = () => connection.query('SELECT * FROM agents'); diff --git a/server/database/quieres/userEstatesQuiery.js b/server/database/quieres/userEstatesQuiery.js index 811caa3..f1b86ed 100644 --- a/server/database/quieres/userEstatesQuiery.js +++ b/server/database/quieres/userEstatesQuiery.js @@ -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]); diff --git a/server/index.js b/server/index.js index 77625cc..991b1f9 100644 --- a/server/index.js +++ b/server/index.js @@ -1,4 +1,3 @@ -require('env2')('.env'); const app = require('./app'); const port = app.get('port'); diff --git a/server/test/index.test.js b/server/test/index.test.js index d5dd994..fb575b4 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -1,8 +1,8 @@ /* eslint-disable no-undef */ const supertest = require('supertest'); const app = require('../app'); -const { dbBuild } = require('../database/config/build'); -const connection = require('../database/connection'); +const dbBuild = require('../database/config/build'); +const connection = require('../database/config/connection'); beforeEach(() => dbBuild()); afterAll(() => connection.end()); From ef596181d6f920907d61f4373816057dd45d3629 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Thu, 28 Oct 2021 18:36:05 +0300 Subject: [PATCH 12/23] resolve test --- server/app.js | 1 - server/database/config/connection.js | 1 + server/database/config/fakeData.sql | 18 +++++++++--------- server/database/quieres/account/signUp.js | 2 +- server/test/index.test.js | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/server/app.js b/server/app.js index 502c1cf..7bc115b 100644 --- a/server/app.js +++ b/server/app.js @@ -4,7 +4,6 @@ const compression = require('compression'); const cookieParser = require('cookie-parser'); const { notFoundError, serverError } = require('./controllers/errors'); const router = require('./routes'); -const { notFoundError, serverError } = require('./controllers/errors'); const { env: { PORT, NODE_ENV } } = process; diff --git a/server/database/config/connection.js b/server/database/config/connection.js index f30a371..aa91dfe 100644 --- a/server/database/config/connection.js +++ b/server/database/config/connection.js @@ -1,4 +1,5 @@ const { Pool } = require('pg'); +require('env2')('.env'); const { NODE_ENV, DATABASE_URL_DEV, DATABASE_URL, DATABASE_URL_TEST, diff --git a/server/database/config/fakeData.sql b/server/database/config/fakeData.sql index c45598f..4487af6 100644 --- a/server/database/config/fakeData.sql +++ b/server/database/config/fakeData.sql @@ -9,17 +9,17 @@ INSERT INTO admins (username, password , email) VALUES ('ameera', '$2b$10$oNaAu ('elham', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'elham2000fadel@gmail.com'), ('sallah', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'mohmsal96@gmail.com'); -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), -(4, 'sociis natoque penatibus et', '$106226.71', 'quis odio consequat', 'Buy', 'House', '15918 Mcguire Point', 'Ranong', 'Thailand', 2, 4, 4, 244, true, 1, false), - (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), - (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 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 (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'), - (4,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/4.tobiarchitects.1526566679.5654.jpg'), - (5,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/5.tobiarchitects.1526566679.5654.jpg'), - (6,'https://archello.s3.eu-central-1.amazonaws.com/images/2018/05/17/6.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'); diff --git a/server/database/quieres/account/signUp.js b/server/database/quieres/account/signUp.js index 0207f96..80d429c 100644 --- a/server/database/quieres/account/signUp.js +++ b/server/database/quieres/account/signUp.js @@ -1,3 +1,3 @@ -const connection = require('../../connection'); +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]); diff --git a/server/test/index.test.js b/server/test/index.test.js index 7ad3d50..5a724b8 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -63,7 +63,7 @@ describe('user estates', () => { }); describe('test signup endpoint with all cases ', () => { test('test sign up endpoint when success', (done) => { - request(app) + supertest(app) .post('/api/v1/signup') .send({ username: 'test', @@ -82,13 +82,13 @@ describe('test signup endpoint with all cases ', () => { }); test('test signup username or phone already exists', (done) => { - request(app) + supertest(app) .post('/api/v1/signup') .send({ - username: 'test', - password: 'test123456', - email: 'test@gmail.com', - phone: '0597853626', + username: 'Kai', + password: '1234567894455', + email: 'kallport0@patch.com', + phone: '677-871-7450', }) .expect(400) .end((err) => { From 69d93aa161b72f3ff7878aa5291646c25f884091 Mon Sep 17 00:00:00 2001 From: muhammadharoun Date: Fri, 29 Oct 2021 02:29:41 +0300 Subject: [PATCH 13/23] git estates function --- server/controllers/estates/allEstate.js | 14 +++++++ server/controllers/estates/index.js | 3 +- server/controllers/index.js | 5 ++- server/database/quieres/getAllEstateQuery.js | 5 +++ server/database/quieres/index.js | 4 +- server/routes/index.js | 6 ++- server/test/index.test.js | 41 ++++++++++---------- 7 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 server/controllers/estates/allEstate.js create mode 100644 server/database/quieres/getAllEstateQuery.js diff --git a/server/controllers/estates/allEstate.js b/server/controllers/estates/allEstate.js new file mode 100644 index 0000000..bf6ea2c --- /dev/null +++ b/server/controllers/estates/allEstate.js @@ -0,0 +1,14 @@ +const { getAllEstateQuery } = require('../../database/quieres'); + +const getAllEstate = async (req, res, next) => { + try { + const { rows } = await getAllEstateQuery(); + res.json({ + data: rows, + status: 200, + }); + } catch (err) { + next(err); + } +}; +module.exports = getAllEstate; diff --git a/server/controllers/estates/index.js b/server/controllers/estates/index.js index 6f71046..daceed4 100644 --- a/server/controllers/estates/index.js +++ b/server/controllers/estates/index.js @@ -1,3 +1,4 @@ const editEstate = require('./editEstate'); +const getAllEstate = require('./allEstate'); -module.exports = { editEstate }; +module.exports = { editEstate, getAllEstate }; diff --git a/server/controllers/index.js b/server/controllers/index.js index d076472..b55fe97 100644 --- a/server/controllers/index.js +++ b/server/controllers/index.js @@ -1,5 +1,8 @@ const { userEstateshandler } = require('./users'); const getAllUsers = require('./users/getAllUsers'); const logout = require('./logout'); +const { getAllEstate, editEstate } = require('./estates'); -module.exports = { getAllUsers, userEstateshandler, logout }; +module.exports = { + getAllUsers, userEstateshandler, logout, getAllEstate, editEstate, +}; diff --git a/server/database/quieres/getAllEstateQuery.js b/server/database/quieres/getAllEstateQuery.js new file mode 100644 index 0000000..6adbf34 --- /dev/null +++ b/server/database/quieres/getAllEstateQuery.js @@ -0,0 +1,5 @@ +const connection = require('../connection'); + +const getAllUsersQuery = () => connection.query('SELECT * FROM estates;'); + +module.exports = getAllUsersQuery; diff --git a/server/database/quieres/index.js b/server/database/quieres/index.js index 8100a45..d417979 100644 --- a/server/database/quieres/index.js +++ b/server/database/quieres/index.js @@ -1,9 +1,11 @@ -const userEstatesQuery = require('./UserEstatesQuiery'); +const userEstatesQuery = require('./userEstatesQuiery'); const getAllUsersQuery = require('./getAllUsersQuery'); const editEstateQuery = require('./editEstatesQuery'); +const getAllEstateQuery = require('./getAllEstateQuery'); module.exports = { getAllUsersQuery, userEstatesQuery, editEstateQuery, + getAllEstateQuery, }; diff --git a/server/routes/index.js b/server/routes/index.js index 05ae9ff..d6d73f1 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,10 +1,12 @@ const router = require('express').Router(); -const { userEstateshandler } = require('../controllers'); -const { getAllUsers, logout } = require('../controllers'); +const { + getAllUsers, logout, userEstateshandler, getAllEstate, +} = require('../controllers'); const { editEstate } = require('../controllers/estates'); router.get('/users/:userId/estates', userEstateshandler); router.put('/estate/:estateId', editEstate); +router.get('/estates', getAllEstate); router.get('/users', getAllUsers); router.get('/logout', logout); diff --git a/server/test/index.test.js b/server/test/index.test.js index 0a161a5..19c184d 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -63,26 +63,27 @@ describe('user estates', () => { }); // describe('edit estates', () => { -// test('edit estates', async () => { -// const res = await supertest(app) -// .get('api/v1/estate/3') -// .send({ -// title: '1', -// price: 10, -// description: 's', -// type: 's', -// category: 's', -// street: 's', -// city: 's', -// region: 's', -// bathrooms: 's', -// bedrooms: 's', -// rooms: 's', -// space: 's', -// available: false, -// }) +// test('edit estates', async (done) => { +// const result = await supertest(app) +// .put('api/v1/estate/3') // .expect(200) -// .expect('Content-Type', /json/); -// console.log(res); +// .expect('Content-Type', /json/) +// .end((err, res) => { +// if (err) return done(err); +// expect(1).toBe(1); +// return done(); +// }); + +// // return expect(1).toEqual(1); // }); // }); + +describe('Tests Server', () => { + test('get all users', async () => { + const res = await supertest(app) + .get('/api/v1/estates') + .expect(200) + .expect('Content-Type', /json/); + return expect(6).toEqual(res.body.data.length); + }); +}); From e67159e33b08cbd584e43f89daa9472028cc2d5d Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Fri, 29 Oct 2021 06:30:14 +0300 Subject: [PATCH 14/23] change according request --- package.json | 1 - server/database/config/connection.js | 4 +-- server/database/config/fakeData.sql | 2 +- server/index.js | 1 - server/routes/auth.js | 2 -- server/routes/users.js | 2 ++ server/test/index.test.js | 48 +++++++++++++++++----------- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 8530144..84ccd3e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "pg": "^8.7.1" }, "devDependencies": { - "cross-env": "^7.0.3", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.25.2", diff --git a/server/database/config/connection.js b/server/database/config/connection.js index aa91dfe..2e4a695 100644 --- a/server/database/config/connection.js +++ b/server/database/config/connection.js @@ -1,5 +1,5 @@ -const { Pool } = require('pg'); require('env2')('.env'); +const { Pool } = require('pg'); const { NODE_ENV, DATABASE_URL_DEV, DATABASE_URL, DATABASE_URL_TEST, @@ -22,7 +22,5 @@ switch (NODE_ENV) { const options = { connectionString: dbUrl, ssl: { rejectUnauthorized: false }, - }; - module.exports = new Pool(options); diff --git a/server/database/config/fakeData.sql b/server/database/config/fakeData.sql index 4487af6..55c810a 100644 --- a/server/database/config/fakeData.sql +++ b/server/database/config/fakeData.sql @@ -1,7 +1,7 @@ -- INSERT INTO agents (name, email, password , phone) VALUES ('Kai', 'kallport0@patch.com', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '677-871-7450'), - ('Trixie', 'tbeadon1@plala.or.jp', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '663-871-7450'), + ('Trixie', 'tbeadon1@plala.or.jp', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '0599832685'), ('Allina', 'aburford2@tumblr.com', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '630-385-8312'); INSERT INTO admins (username, password , email) VALUES ('ameera', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', 'ameera2021abed@gmail.com'), diff --git a/server/index.js b/server/index.js index 77625cc..991b1f9 100644 --- a/server/index.js +++ b/server/index.js @@ -1,4 +1,3 @@ -require('env2')('.env'); const app = require('./app'); const port = app.get('port'); diff --git a/server/routes/auth.js b/server/routes/auth.js index 04e9bd5..66adcf9 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -1,7 +1,5 @@ const router = require('express').Router(); -const signup = require('../controllers/users/signup'); const { logout } = require('../controllers'); -router.post('/signup', signup); router.get('/logout', logout); module.exports = router; diff --git a/server/routes/users.js b/server/routes/users.js index f9f0322..14f0c13 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -1,6 +1,8 @@ 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); diff --git a/server/test/index.test.js b/server/test/index.test.js index 5a724b8..21eaf18 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -61,10 +61,11 @@ describe('user estates', () => { }); }); }); + describe('test signup endpoint with all cases ', () => { - test('test sign up endpoint when success', (done) => { - supertest(app) - .post('/api/v1/signup') + test('test sign up endpoint when success', async () => { + const res = await supertest(app) + .post('/api/v1/users/signup') .send({ username: 'test', password: 'test123456', @@ -73,17 +74,15 @@ describe('test signup endpoint with all cases ', () => { }) .expect(201) .expect((response) => expect(response.header['set-cookie'][0].split('=')[0]).toBe('token')) - .end((err) => { - if (err) { - return done(err); - } - return done(); - }); + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + message: 'user created', + }); }); - test('test signup username or phone already exists', (done) => { - supertest(app) - .post('/api/v1/signup') + test('test signup error validation phone" length must be 10 characters long ', async () => { + const res = await supertest(app) + .post('/api/v1/users/signup') .send({ username: 'Kai', password: '1234567894455', @@ -91,11 +90,24 @@ describe('test signup endpoint with all cases ', () => { phone: '677-871-7450', }) .expect(400) - .end((err) => { - if (err) { - return done(err); - } - return done(); - }); + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + error: '"phone" length must be 10 characters long', + }); + }); + test('test signup username or phone already exists ', async () => { + const res = await supertest(app) + .post('/api/v1/users/signup') + .send({ + username: 'Kai', + password: '1234567894455', + email: 'kallport0@patch.com', + phone: '0599832683', + }) + .expect(400) + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + error: 'username or phone already exists', + }); }); }); From d535fcdfa624fc746dcbb740cf50220b5f7c964b Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Fri, 29 Oct 2021 18:37:33 +0300 Subject: [PATCH 15/23] sign up --- server/controllers/users/signup.js | 4 ++-- server/test/index.test.js | 23 +++++++++++++++++++++-- server/utils/validation/signUpSchema.js | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/server/controllers/users/signup.js b/server/controllers/users/signup.js index 43fba8d..eb00623 100644 --- a/server/controllers/users/signup.js +++ b/server/controllers/users/signup.js @@ -10,14 +10,14 @@ module.exports = async (req, res, next) => { password, email, username, phone, }, } = signupSchema.validate(req.body); - if (error) return res.status(400).json({ error: error.details[0].message }); + 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({ error: 'username or phone already exists' }); + return res.status(400).json({ message: 'username or phone already exists' }); } return next(err); } diff --git a/server/test/index.test.js b/server/test/index.test.js index 21eaf18..756dc56 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -71,6 +71,7 @@ describe('test signup endpoint with all cases ', () => { password: 'test123456', email: 'test@gmail.com', phone: '0597853626', + confirmedPassword: 'test123456', }) .expect(201) .expect((response) => expect(response.header['set-cookie'][0].split('=')[0]).toBe('token')) @@ -88,11 +89,12 @@ describe('test signup endpoint with all cases ', () => { password: '1234567894455', email: 'kallport0@patch.com', phone: '677-871-7450', + confirmedPassword: '1234567894455', }) .expect(400) .expect('Content-Type', /json/); return expect(res.body).toEqual({ - error: '"phone" length must be 10 characters long', + message: '"phone" length must be 10 characters long', }); }); test('test signup username or phone already exists ', async () => { @@ -103,11 +105,28 @@ describe('test signup endpoint with all cases ', () => { password: '1234567894455', email: 'kallport0@patch.com', phone: '0599832683', + confirmedPassword: '1234567894455', }) .expect(400) .expect('Content-Type', /json/); return expect(res.body).toEqual({ - error: 'username or phone already exists', + message: 'username or phone already exists', + }); + }); + test('test signup confirmpassword ', async () => { + const res = await supertest(app) + .post('/api/v1/users/signup') + .send({ + username: 'test', + password: 'test123456', + email: 'test@gmail.com', + phone: '0597853626', + confirmedPassword: 'test12345', + }) + .expect(400) + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + message: '"confirmedPassword" must be [ref:password]', }); }); }); diff --git a/server/utils/validation/signUpSchema.js b/server/utils/validation/signUpSchema.js index 76a5fa6..a43fc97 100644 --- a/server/utils/validation/signUpSchema.js +++ b/server/utils/validation/signUpSchema.js @@ -5,4 +5,5 @@ module.exports = joi.object({ email: joi.string().email().required(), password: joi.string().min(5).required(), phone: joi.string().length(10).required(), + confirmedPassword: joi.ref('password'), }); From c3ee0e823cc4cb7cb76102111a0d27111269223f Mon Sep 17 00:00:00 2001 From: muhammadharoun Date: Fri, 29 Oct 2021 19:53:41 +0300 Subject: [PATCH 16/23] add changes --- server/app.js | 3 +-- server/controllers/estates/allEstate.js | 5 +---- server/database/connection.js | 1 + 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/server/app.js b/server/app.js index a7ace9c..7bc115b 100644 --- a/server/app.js +++ b/server/app.js @@ -1,4 +1,3 @@ -require('env2')('.env'); const express = require('express'); const { join } = require('path'); const compression = require('compression'); @@ -26,6 +25,6 @@ if (NODE_ENV === 'production') { }); } router.use(notFoundError); -// router.use(serverError); +router.use(serverError); module.exports = app; diff --git a/server/controllers/estates/allEstate.js b/server/controllers/estates/allEstate.js index bf6ea2c..38d59c5 100644 --- a/server/controllers/estates/allEstate.js +++ b/server/controllers/estates/allEstate.js @@ -3,10 +3,7 @@ const { getAllEstateQuery } = require('../../database/quieres'); const getAllEstate = async (req, res, next) => { try { const { rows } = await getAllEstateQuery(); - res.json({ - data: rows, - status: 200, - }); + res.json({ data: rows }); } catch (err) { next(err); } diff --git a/server/database/connection.js b/server/database/connection.js index e2c8673..ee76705 100644 --- a/server/database/connection.js +++ b/server/database/connection.js @@ -3,6 +3,7 @@ const { Pool } = require('pg'); const { NODE_ENV, DATABASE_URL_DEV, DATABASE_URL, DATABASE_URL_TEST, } = process.env; +console.log(DATABASE_URL_TEST); let dbUrl = ''; switch (NODE_ENV) { case 'development': From b17d16f3b5c3eb27dc4a3a7d222d5ec6cf9a0fae Mon Sep 17 00:00:00 2001 From: muhammadharoun Date: Fri, 29 Oct 2021 19:55:24 +0300 Subject: [PATCH 17/23] add env to connection --- server/database/connection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/database/connection.js b/server/database/connection.js index ee76705..7ef7a43 100644 --- a/server/database/connection.js +++ b/server/database/connection.js @@ -1,9 +1,9 @@ +require('env2')('.env'); const { Pool } = require('pg'); const { NODE_ENV, DATABASE_URL_DEV, DATABASE_URL, DATABASE_URL_TEST, } = process.env; -console.log(DATABASE_URL_TEST); let dbUrl = ''; switch (NODE_ENV) { case 'development': From 17c41d3fefecf95d2cc5ee574df9d9c8de78f277 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Fri, 29 Oct 2021 20:03:32 +0300 Subject: [PATCH 18/23] change name schema to agentSchema --- server/controllers/users/signup.js | 4 ++-- server/utils/validation/{signUpSchema.js => agentSchema.js} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename server/utils/validation/{signUpSchema.js => agentSchema.js} (100%) diff --git a/server/controllers/users/signup.js b/server/controllers/users/signup.js index eb00623..ea7120b 100644 --- a/server/controllers/users/signup.js +++ b/server/controllers/users/signup.js @@ -1,5 +1,5 @@ const { hash } = require('bcrypt'); -const signupSchema = require('../../utils/validation/signUpSchema'); +const agentSchema = require('../../utils/validation/agentSchema'); const signUpQuery = require('../../database/quieres/account/signUp'); const { signToken } = require('../../utils'); @@ -9,7 +9,7 @@ module.exports = async (req, res, next) => { error, value: { password, email, username, phone, }, - } = signupSchema.validate(req.body); + } = 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); diff --git a/server/utils/validation/signUpSchema.js b/server/utils/validation/agentSchema.js similarity index 100% rename from server/utils/validation/signUpSchema.js rename to server/utils/validation/agentSchema.js From 2c3e4b945b0dfd31ebc40324779e3b7c1b571b6c Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Sat, 30 Oct 2021 12:42:37 +0300 Subject: [PATCH 19/23] change content responed msg for the best --- server/controllers/users/signup.js | 2 +- server/test/index.test.js | 108 ++++++++++++------------- server/utils/validation/agentSchema.js | 2 +- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/server/controllers/users/signup.js b/server/controllers/users/signup.js index ea7120b..ab56711 100644 --- a/server/controllers/users/signup.js +++ b/server/controllers/users/signup.js @@ -17,7 +17,7 @@ module.exports = async (req, res, next) => { return res.status(201).cookie('token', token).json({ message: 'user created' }); } catch (err) { if (err.code === '23505') { - return res.status(400).json({ message: 'username or phone already exists' }); + return res.status(400).json({ message: 'The user is already exists' }); } return next(err); } diff --git a/server/test/index.test.js b/server/test/index.test.js index 756dc56..69a71a0 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -7,60 +7,60 @@ const connection = require('../database/config/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); - }); -}); +// 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); +// }); +// }); -describe('user estates', () => { - test('get users estates', async () => { - const res = await supertest(app) - .get('/api/v1/users/3/estates') - .expect(200) - .expect('Content-Type', /json/); +// describe('user estates', () => { +// test('get users estates', async () => { +// const res = await supertest(app) +// .get('/api/v1/users/3/estates') +// .expect(200) +// .expect('Content-Type', /json/); - return expect(res.body).toEqual({ - data: [ - { - id: 3, - agent_id: 3, - title: 'rhoncus sed vestibulum', - price: '84726.00', - description: 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', - type: 'Buy', - category: 'House', - street: '0824 Mcguire Way', - city: 'Kungshamn', - region: 'Sweden', - bathrooms: 1, - bedrooms: 3, - rooms: 3, - space: '235', - approved: true, - rate: 5, - available: false, - }, - ], - }); - }); -}); +// return expect(res.body).toEqual({ +// data: [ +// { +// id: 3, +// agent_id: 3, +// title: 'rhoncus sed vestibulum', +// price: '84726.00', +// description: 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', +// type: 'Buy', +// category: 'House', +// street: '0824 Mcguire Way', +// city: 'Kungshamn', +// region: 'Sweden', +// bathrooms: 1, +// bedrooms: 3, +// rooms: 3, +// space: '235', +// approved: true, +// rate: 5, +// available: false, +// }, +// ], +// }); +// }); +// }); -describe('user estates', () => { - test('get users estates', async () => { - const res = await supertest(app) - .get('/api/v1/users/three/estates') - .expect(404) - .expect('Content-Type', /json/); - return expect(res.body).toEqual({ - message: 'enter valid user id', - }); - }); -}); +// describe('user estates', () => { +// test('get users estates', async () => { +// const res = await supertest(app) +// .get('/api/v1/users/three/estates') +// .expect(404) +// .expect('Content-Type', /json/); +// return expect(res.body).toEqual({ +// message: 'enter valid user id', +// }); +// }); +// }); describe('test signup endpoint with all cases ', () => { test('test sign up endpoint when success', async () => { @@ -88,13 +88,13 @@ describe('test signup endpoint with all cases ', () => { username: 'Kai', password: '1234567894455', email: 'kallport0@patch.com', - phone: '677-871-7450', + phone: '677', confirmedPassword: '1234567894455', }) .expect(400) .expect('Content-Type', /json/); return expect(res.body).toEqual({ - message: '"phone" length must be 10 characters long', + message: '"phone" length must be at least 9 characters long', }); }); test('test signup username or phone already exists ', async () => { @@ -110,7 +110,7 @@ describe('test signup endpoint with all cases ', () => { .expect(400) .expect('Content-Type', /json/); return expect(res.body).toEqual({ - message: 'username or phone already exists', + message: 'The user is already exists', }); }); test('test signup confirmpassword ', async () => { diff --git a/server/utils/validation/agentSchema.js b/server/utils/validation/agentSchema.js index a43fc97..6857fe8 100644 --- a/server/utils/validation/agentSchema.js +++ b/server/utils/validation/agentSchema.js @@ -4,6 +4,6 @@ module.exports = joi.object({ username: joi.string().required(), email: joi.string().email().required(), password: joi.string().min(5).required(), - phone: joi.string().length(10).required(), + phone: joi.string().min(9).required(), confirmedPassword: joi.ref('password'), }); From 311435048b881021e16a792cdfde46d8a7e9ca8a Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Sat, 30 Oct 2021 12:43:46 +0300 Subject: [PATCH 20/23] change content responed msg for the best --- server/test/index.test.js | 102 +++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/server/test/index.test.js b/server/test/index.test.js index 69a71a0..daacc1d 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -7,60 +7,60 @@ const connection = require('../database/config/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); -// }); -// }); +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); + }); +}); -// describe('user estates', () => { -// test('get users estates', async () => { -// const res = await supertest(app) -// .get('/api/v1/users/3/estates') -// .expect(200) -// .expect('Content-Type', /json/); +describe('user estates', () => { + test('get users estates', async () => { + const res = await supertest(app) + .get('/api/v1/users/3/estates') + .expect(200) + .expect('Content-Type', /json/); -// return expect(res.body).toEqual({ -// data: [ -// { -// id: 3, -// agent_id: 3, -// title: 'rhoncus sed vestibulum', -// price: '84726.00', -// description: 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', -// type: 'Buy', -// category: 'House', -// street: '0824 Mcguire Way', -// city: 'Kungshamn', -// region: 'Sweden', -// bathrooms: 1, -// bedrooms: 3, -// rooms: 3, -// space: '235', -// approved: true, -// rate: 5, -// available: false, -// }, -// ], -// }); -// }); -// }); + return expect(res.body).toEqual({ + data: [ + { + id: 3, + agent_id: 3, + title: 'rhoncus sed vestibulum', + price: '84726.00', + description: 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', + type: 'Buy', + category: 'House', + street: '0824 Mcguire Way', + city: 'Kungshamn', + region: 'Sweden', + bathrooms: 1, + bedrooms: 3, + rooms: 3, + space: '235', + approved: true, + rate: 5, + available: false, + }, + ], + }); + }); +}); -// describe('user estates', () => { -// test('get users estates', async () => { -// const res = await supertest(app) -// .get('/api/v1/users/three/estates') -// .expect(404) -// .expect('Content-Type', /json/); -// return expect(res.body).toEqual({ -// message: 'enter valid user id', -// }); -// }); -// }); +describe('user estates', () => { + test('get users estates', async () => { + const res = await supertest(app) + .get('/api/v1/users/three/estates') + .expect(404) + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + message: 'enter valid user id', + }); + }); +}); describe('test signup endpoint with all cases ', () => { test('test sign up endpoint when success', async () => { From 161c67210e8f597b24ca41b28ee7367e33043fcb Mon Sep 17 00:00:00 2001 From: muhammadharoun Date: Sun, 31 Oct 2021 00:55:09 +0300 Subject: [PATCH 21/23] fix conflict --- server/database/quieres/editEstatesQuery.js | 2 +- server/database/quieres/getAllEstateQuery.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/database/quieres/editEstatesQuery.js b/server/database/quieres/editEstatesQuery.js index e4d1651..20d381a 100644 --- a/server/database/quieres/editEstatesQuery.js +++ b/server/database/quieres/editEstatesQuery.js @@ -1,5 +1,5 @@ /* eslint-disable max-len */ -const connection = require('../connection'); +const connection = require('../config/connection'); const editEstateQuery = (id, title, diff --git a/server/database/quieres/getAllEstateQuery.js b/server/database/quieres/getAllEstateQuery.js index 6adbf34..e104f7b 100644 --- a/server/database/quieres/getAllEstateQuery.js +++ b/server/database/quieres/getAllEstateQuery.js @@ -1,4 +1,4 @@ -const connection = require('../connection'); +const connection = require('../config/connection'); const getAllUsersQuery = () => connection.query('SELECT * FROM estates;'); From 3b33a2cb1535a1e62e2fb630a474d3ce33c9d2cb Mon Sep 17 00:00:00 2001 From: Muhammad Abdulhadi Date: Sun, 31 Oct 2021 01:50:53 +0300 Subject: [PATCH 22/23] Revert "12 get estates" --- server/controllers/estates/allEstate.js | 11 ----- server/controllers/estates/editEstate.js | 43 -------------------- server/controllers/estates/index.js | 4 -- server/controllers/index.js | 5 +-- server/controllers/users/userEstates.js | 1 - server/database/quieres/editEstatesQuery.js | 37 ----------------- server/database/quieres/getAllEstateQuery.js | 5 --- server/database/quieres/index.js | 5 +-- server/routes/index.js | 9 +--- server/test/index.test.js | 26 ------------ 10 files changed, 4 insertions(+), 142 deletions(-) delete mode 100644 server/controllers/estates/allEstate.js delete mode 100644 server/controllers/estates/editEstate.js delete mode 100644 server/database/quieres/editEstatesQuery.js delete mode 100644 server/database/quieres/getAllEstateQuery.js diff --git a/server/controllers/estates/allEstate.js b/server/controllers/estates/allEstate.js deleted file mode 100644 index 38d59c5..0000000 --- a/server/controllers/estates/allEstate.js +++ /dev/null @@ -1,11 +0,0 @@ -const { getAllEstateQuery } = require('../../database/quieres'); - -const getAllEstate = async (req, res, next) => { - try { - const { rows } = await getAllEstateQuery(); - res.json({ data: rows }); - } catch (err) { - next(err); - } -}; -module.exports = getAllEstate; diff --git a/server/controllers/estates/editEstate.js b/server/controllers/estates/editEstate.js deleted file mode 100644 index e9d503c..0000000 --- a/server/controllers/estates/editEstate.js +++ /dev/null @@ -1,43 +0,0 @@ -/* eslint-disable no-console */ -const { editEstateQuery } = require('../../database/quieres'); - -const editEstate = async (req, res, next) => { - const { estateId } = req.params; - const { - title, - price, - description, - type, - category, - street, - city, - region, - bathrooms, - bedrooms, - rooms, - space, - available, - } = req.body; - try { - await editEstateQuery( - estateId, - title, - price, - description, - type, - category, - street, - city, - region, - bathrooms, - bedrooms, - rooms, - space, - available, - ); - res.json(); - } catch (err) { - next(err); - } -}; -module.exports = editEstate; diff --git a/server/controllers/estates/index.js b/server/controllers/estates/index.js index daceed4..e69de29 100644 --- a/server/controllers/estates/index.js +++ b/server/controllers/estates/index.js @@ -1,4 +0,0 @@ -const editEstate = require('./editEstate'); -const getAllEstate = require('./allEstate'); - -module.exports = { editEstate, getAllEstate }; diff --git a/server/controllers/index.js b/server/controllers/index.js index b55fe97..d076472 100644 --- a/server/controllers/index.js +++ b/server/controllers/index.js @@ -1,8 +1,5 @@ const { userEstateshandler } = require('./users'); const getAllUsers = require('./users/getAllUsers'); const logout = require('./logout'); -const { getAllEstate, editEstate } = require('./estates'); -module.exports = { - getAllUsers, userEstateshandler, logout, getAllEstate, editEstate, -}; +module.exports = { getAllUsers, userEstateshandler, logout }; diff --git a/server/controllers/users/userEstates.js b/server/controllers/users/userEstates.js index 2bd4ecb..5f7a1ae 100644 --- a/server/controllers/users/userEstates.js +++ b/server/controllers/users/userEstates.js @@ -1,6 +1,5 @@ const { userEstatesQuery } = require('../../database/quieres/index'); -// eslint-disable-next-line consistent-return const userEstateshandler = async (req, res) => { const { userId } = req.params; diff --git a/server/database/quieres/editEstatesQuery.js b/server/database/quieres/editEstatesQuery.js deleted file mode 100644 index 20d381a..0000000 --- a/server/database/quieres/editEstatesQuery.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-disable max-len */ -const connection = require('../config/connection'); - -const editEstateQuery = (id, - title, - price, - description, - type, - category, - street, - city, - region, - bathrooms, - bedrooms, - rooms, - space, - available) => connection.query( - 'UPDATE estates SET title = $1,price =$2,description=$3,type=$4,category=$5,street=$6,city=$7,region=$8,bathrooms=$9,bedrooms=$10,rooms=$11,space=$12,available=$13 WHERE id = $14;', - [ - title, - price, - description, - type, - category, - street, - city, - region, - bathrooms, - bedrooms, - rooms, - space, - available, - id, - ], -); - -module.exports = editEstateQuery; diff --git a/server/database/quieres/getAllEstateQuery.js b/server/database/quieres/getAllEstateQuery.js deleted file mode 100644 index e104f7b..0000000 --- a/server/database/quieres/getAllEstateQuery.js +++ /dev/null @@ -1,5 +0,0 @@ -const connection = require('../config/connection'); - -const getAllUsersQuery = () => connection.query('SELECT * FROM estates;'); - -module.exports = getAllUsersQuery; diff --git a/server/database/quieres/index.js b/server/database/quieres/index.js index d417979..386595b 100644 --- a/server/database/quieres/index.js +++ b/server/database/quieres/index.js @@ -1,11 +1,8 @@ const userEstatesQuery = require('./userEstatesQuiery'); const getAllUsersQuery = require('./getAllUsersQuery'); -const editEstateQuery = require('./editEstatesQuery'); -const getAllEstateQuery = require('./getAllEstateQuery'); module.exports = { getAllUsersQuery, userEstatesQuery, - editEstateQuery, - getAllEstateQuery, + }; diff --git a/server/routes/index.js b/server/routes/index.js index d6d73f1..92cf993 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,13 +1,8 @@ const router = require('express').Router(); -const { - getAllUsers, logout, userEstateshandler, getAllEstate, -} = require('../controllers'); -const { editEstate } = require('../controllers/estates'); +const { userEstateshandler } = require('../controllers'); +const { getAllUsers, logout } = require('../controllers'); router.get('/users/:userId/estates', userEstateshandler); -router.put('/estate/:estateId', editEstate); -router.get('/estates', getAllEstate); - router.get('/users', getAllUsers); router.get('/logout', logout); diff --git a/server/test/index.test.js b/server/test/index.test.js index c48257b..fb575b4 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -61,29 +61,3 @@ describe('user estates', () => { }); }); }); - -// describe('edit estates', () => { -// test('edit estates', async (done) => { -// const result = await supertest(app) -// .put('api/v1/estate/3') -// .expect(200) -// .expect('Content-Type', /json/) -// .end((err, res) => { -// if (err) return done(err); -// expect(1).toBe(1); -// return done(); -// }); - -// // return expect(1).toEqual(1); -// }); -// }); - -describe('Tests Server', () => { - test('get all users', async () => { - const res = await supertest(app) - .get('/api/v1/estates') - .expect(200) - .expect('Content-Type', /json/); - return expect(6).toEqual(res.body.data.length); - }); -}); From aa8e9f623851bcd71006991de5d34be9178f6821 Mon Sep 17 00:00:00 2001 From: Muhammad Abdulhadi Date: Sun, 31 Oct 2021 01:23:50 +0200 Subject: [PATCH 23/23] Update app.js --- server/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/app.js b/server/app.js index 7bc115b..7e55586 100644 --- a/server/app.js +++ b/server/app.js @@ -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;