Skip to content

Commit

Permalink
edite fack data & sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
ElhamFadel committed Oct 26, 2021
2 parents faf3b41 + 4650057 commit e38cfa3
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 13
"ecmaVersion": "latest"
},
"rules": {
}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
.env
.vscode
package-lock.json
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"git.ignoreLimitWarning": true,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "client",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:5000",
"dependencies": {
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"bcrypt": "^5.0.1",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"cross": "^1.0.0",
"env2": "^2.2.2",
"express": "^4.17.1",
"joi": "^17.4.2",
"jsonwebtoken": "^8.5.1",
"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",
Expand Down
31 changes: 31 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const express = require('express');
const { join } = require('path');
const compression = require('compression');
const cookieParser = require('cookie-parser');
const router = require('./routes');

const { env: { PORT, NODE_ENV } } = process;

const app = express();

app.set('port', PORT || 5000);

app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(compression());
app.use(cookieParser());
app.disable('x-powered-by');
app.use('/api/v1/', router);

if (NODE_ENV === 'development') {
app.get('/', (req, res) => {
res.json({ message: 'server running' });
});
}
if (NODE_ENV === 'production') {
app.use(express.static(join(__dirname, '..', 'client', 'build')));
app.get('*', (req, res) => {
res.sendFile(join(__dirname, '..', 'client', 'build', 'index.html'));
});
}
module.exports = app;
4 changes: 4 additions & 0 deletions server/controllers/errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const notFoundError = require('./notFoundError');
const serverError = require('./serverError');

module.exports = { serverError, notFoundError };
6 changes: 6 additions & 0 deletions server/controllers/errors/notFoundError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable no-unused-vars */
const notFoundError = (req, res, next) => {
res.status(404).json({ message: 'Page Not Found' });
};

module.exports = notFoundError;
6 changes: 6 additions & 0 deletions server/controllers/errors/serverError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable no-unused-vars */
const serverError = (req, res, next, err) => {
res.status(500).json({ message: 'Server Error' });
};

module.exports = serverError;
7 changes: 4 additions & 3 deletions server/controllers/users/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const signup = require('./signup');
module.exports ={
signup
}

module.exports = {
signup,
};
32 changes: 21 additions & 11 deletions server/controllers/users/signup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
const { hash } = require('bcrypt');
const signupSchema = require("../../utils/validation/signUpSchema")
const signUpQuery = require("../../database/quieres/account/signUp")

module.exports = sync (req, res, next) => {
const signupSchema = require('../../utils/validation/signUpSchema');
const signUpQuery = require('../../database/quieres/account/signUp');

module.exports = async (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);}
const {
error, value: {
password, email, username, phone,
},
} = 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]) {
return res.status(400).json({ error: 'username or phone already exists' });
}
req.user = { username, email, phone };
next();
} catch (err) {
console.log(err);
// next(err);
}
};

4 changes: 4 additions & 0 deletions server/database/config/adminsFack Data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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]');
6 changes: 6 additions & 0 deletions server/database/config/agentsFackData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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');
25 changes: 25 additions & 0 deletions server/database/config/fakeData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--
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', '663-871-7450'),
('Allina', '[email protected]', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '630-385-8312');

INSERT INTO admins (username, password , email) VALUES ('ameera', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '[email protected]'),
('haroon', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '[email protected]'),
('elham', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '[email protected]'),
('sallah', '$2b$10$oNaAu46EHAyOCiufPgchaOQDq5opRxSFHB20m.e3wzDBlM5Yzztf2', '[email protected]');

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 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 change: 1 addition & 0 deletions server/database/config/imagesFackData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions server/database/config/realStateFackData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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);
9 changes: 5 additions & 4 deletions server/database/connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('env2')('.env');
const {Pool} = require('pg');
const { Pool } = require('pg');

const {
NODE_ENV, DATABASE_URL_DEV, DATABASE_URL, DATABASE_URL_TEST,
} = process.env;
Expand All @@ -20,6 +20,7 @@ switch (NODE_ENV) {
}
const options = {
connectionString: dbUrl,
ssl: { rejectUnauthorized: false },
ssl: false,

};
module.exports = new Pool(options);
module.exports = new Pool(options);
5 changes: 3 additions & 2 deletions server/database/quieres/account/signUp.js
Original file line number Diff line number Diff line change
@@ -1,2 +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)',[userName,email,phone,password])
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]);
8 changes: 8 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const app = require('./app');

const port = app.get('port');

app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`server is running at http://localhost:${port}`);
});
11 changes: 10 additions & 1 deletion server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
const signupControllers = require('../controllers/users/');
const router = require('express').Router();
const signup = require('../controllers/users/signup');
// const createToken = require('../controllers/middleware/auth/createToken');
const { notFoundError, serverError } = require('../controllers/errors');

router.post('/signup', signup);

router.use(notFoundError);
router.use(serverError);
module.exports = router;
12 changes: 6 additions & 6 deletions server/utils/validation/signUpSchema.js
Original file line number Diff line number Diff line change
@@ -1,9 +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(),
})
username: joi.string().required(),
email: joi.string().email().required(),
password: joi.string().min(5).required(),
// like +911234567890
phone: joi.string().length(10).required(),
});

0 comments on commit e38cfa3

Please sign in to comment.