Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 91f9cec

Browse files
version 1.0.0
0 parents commit 91f9cec

File tree

201 files changed

+15159
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+15159
-0
lines changed

‎.gitignore‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Airbnb Clone

‎apis/changeRoomVisibility.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import express from 'express';
2+
import Room from '../models/room.js';
3+
4+
const changeRoomVisibility = express.Router();
5+
6+
changeRoomVisibility.use(express.json());
7+
changeRoomVisibility.use(express.urlencoded({ extended: true }));
8+
9+
changeRoomVisibility.patch('/', async (req, res) => {
10+
try {
11+
const roomList = await Room.findOneAndUpdate({
12+
'roomId': req.body.roomId }, { 'hidden': req.body.hidden });
13+
14+
res.status(200).send({ success: true });
15+
} catch (error) {
16+
res.status(404).send({
17+
success: false,
18+
error: `${error.name}: ${error.message}`
19+
});
20+
}
21+
});
22+
23+
export default changeRoomVisibility;

‎apis/rooms.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import express from 'express';
2+
import Room from '../models/room.js';
3+
4+
const rooms = express.Router();
5+
6+
rooms.use(express.json());
7+
rooms.use(express.urlencoded({ extended: true }));
8+
9+
rooms.get('/', async (req, res) => {
10+
try {
11+
const roomList = await Room.find({});
12+
13+
res.status(200).send(roomList);
14+
} catch (error) {
15+
res.status(404).send({ error: `${error.name}: ${error.message}` });
16+
}
17+
});
18+
19+
rooms.get('/roomId', async (req, res) => {
20+
try {
21+
const roomIds = await Room.find({}, { '_id': 0, 'roomId': 1 });
22+
23+
return res.status(200).send(roomIds);
24+
} catch (error) {
25+
return res.status(404).send(`${error.name}: ${error.message}`);
26+
}
27+
});
28+
29+
rooms.get('/:roomId', async (req, res) => {
30+
try {
31+
const room = await Room.findOne({ 'roomId': req.params.roomId });
32+
33+
res.status(200).send(room);
34+
} catch (error) {
35+
res.status(404).send({ error: `${error.name}: ${error.message}` });
36+
}
37+
});
38+
39+
export default rooms;

‎apis/sendOTP.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import express from 'express';
2+
import middlewares from '../middlewares/validateUser.js';
3+
4+
const sendOTP = express.Router();
5+
6+
sendOTP.use(express.json());
7+
sendOTP.use(express.urlencoded({ extended: true }));
8+
9+
sendOTP.post('/', middlewares, (req, res) => {
10+
res.status(200).send({ emailSent: true });
11+
});
12+
13+
export default sendOTP;

‎apis/toggleWishlist.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import express from 'express';
2+
import User from '../models/user.js';
3+
import token from '../services/token.js';
4+
5+
const toggleWishlist = express.Router();
6+
7+
toggleWishlist.use(express.json());
8+
toggleWishlist.use(express.urlencoded({ extended: true }));
9+
10+
toggleWishlist.patch('/', async (req, res) => {
11+
try {
12+
const roomId = Number(req.body.roomId);
13+
14+
if (req.body.add) {
15+
await User.updateOne({ '_id': token.getUserId(req.cookies) },
16+
{
17+
$push: { 'wishlist': roomId }
18+
});
19+
} else {
20+
await User.updateOne({ '_id': token.getUserId(req.cookies) },
21+
{
22+
$pull: { 'wishlist': roomId }
23+
});
24+
}
25+
26+
res.status(200).send({ success: true });
27+
} catch (error) {
28+
res.status(404).send({
29+
success: false,
30+
error: `${error.name}: ${error.message}`
31+
});
32+
}
33+
});
34+
35+
export default toggleWishlist;

‎apis/validateEmail.js‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import express from 'express';
2+
import { check, validationResult } from 'express-validator';
3+
import { validate } from 'deep-email-validator';
4+
import User from '../models/user.js';
5+
6+
const validateEmail = express.Router();
7+
8+
validateEmail.use(express.json());
9+
validateEmail.use(express.urlencoded({ extended: true }));
10+
11+
const rules = [
12+
check('email').trim().toLowerCase().notEmpty().escape().isEmail().normalizeEmail().custom(async (email) => {
13+
const valid = (await validate(email)).valid;
14+
15+
if (!valid) throw new Error(`${email} doesn't exist, Please Enter a valid Email.`);
16+
}),
17+
];
18+
19+
const checkEmail = (req, res, next) => {
20+
const error = validationResult(req);
21+
22+
if (!error.isEmpty()) return res.status(200).send({ 'valid': false, 'found': false }); else next();
23+
};
24+
25+
const findUser = async (req, res, next) => {
26+
const email = (req.query.email ? req.query.email : req.body.email);
27+
28+
const user = await User.findOne({ 'email': email }, { '_id': 1 });
29+
30+
if (user) return res.status(200).send({ 'valid': true, 'found': true });
31+
else next();
32+
};
33+
34+
// const middleware = [ rules, checkEmail, findUser ];
35+
36+
const middleware = [ findUser ];
37+
38+
validateEmail.get('/', middleware, (req, res) => {
39+
res.status(200).send({ 'valid': true, 'found': false });
40+
});
41+
42+
validateEmail.post('/', middleware, (req, res) => {
43+
res.status(200).send({ 'valid': true, 'found': false });
44+
});
45+
46+
export default validateEmail;

‎apis/validateOTP.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import express from 'express';
2+
import bcrypt from 'bcrypt';
3+
import Temp from '../models/temp.js';
4+
import User from '../models/user.js';
5+
6+
const validateOTP = express.Router();
7+
8+
validateOTP.use(express.json());
9+
validateOTP.use(express.urlencoded({ extended: true }));
10+
11+
validateOTP.post('/', async (req, res) => {
12+
try {
13+
const tempUser = await Temp.findOne({ email: req.body.email }, {
14+
'_id': 0,
15+
});
16+
17+
if (!bcrypt.compareSync(req.body.otp, tempUser.otp)) {
18+
return res.status(200).send({ isOtpValid: false });
19+
}
20+
21+
await User.create({
22+
'name': tempUser.name,
23+
'dateOfBirth': tempUser.dateOfBirth,
24+
'email': tempUser.email,
25+
'password': tempUser.password,
26+
'createdAt': tempUser.createdAt
27+
});
28+
29+
await Temp.deleteOne({ email: tempUser.email });
30+
31+
res.status(200).send({ isOtpValid: true });
32+
} catch (error) {
33+
return res.status(400).send({
34+
error: `${error.name}: ${error.message}`
35+
});
36+
}
37+
});
38+
39+
export default validateOTP;

‎apis/validatePassword.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import express from 'express';
2+
import bcrypt from 'bcrypt';
3+
import User from '../models/user.js';
4+
5+
const validatePassword = express.Router();
6+
7+
validatePassword.use(express.json());
8+
validatePassword.use(express.urlencoded({ extended: true }));
9+
10+
validatePassword.post('/', async (req, res) => {
11+
try {
12+
const user = await User.findOne({ email: req.body.email }, {
13+
'_id': 0,
14+
'password': 1
15+
});
16+
17+
if (bcrypt.compareSync(req.body.password, user.password)) {
18+
return res.status(200).send({ correctPassword: true });
19+
}
20+
21+
return res.status(200).send({ correctPassword: false });
22+
} catch (error) {
23+
return res.status(400).send({
24+
error: `${error.name}: ${error.message}`
25+
});
26+
}
27+
});
28+
29+
export default validatePassword;

‎connections/database.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import mongoose from 'mongoose';
2+
3+
const connectDatabase = async (url) => {
4+
await mongoose.connect(url).catch((error) => {
5+
if (error) console.error(`${error.name}: ${error.message}`);
6+
});
7+
};
8+
9+
export default { connectDatabase };

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /