Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation #148

Open
wants to merge 181 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
b08070a
added test to readme
pablisch May 9, 2023
d9cdd4a
Added button to signup screen
pablisch May 11, 2023
e970f48
Merge pull request #1 from ManuelaIacobovici/pablo
ManuelaIacobovici May 11, 2023
27865c8
TDD AddPost component and test passes
pablisch May 11, 2023
3d0f920
Display posts with newest post first
tomcarmichael May 11, 2023
acaf173
Merged with main
tomcarmichael May 11, 2023
2be9bbd
new posts creating and all tests passing
pablisch May 11, 2023
0e25a01
.then handling handleSubmit. Test passing
pablisch May 11, 2023
ddc6a66
post being created but posts not refreshing
pablisch May 11, 2023
c1556ff
clear commented code
pablisch May 11, 2023
b8e90a1
Co-authored-by: Daniel John <[email protected]>
carolrs May 11, 2023
4656570
removing videos
carolrs May 11, 2023
548905c
tidy white space
pablisch May 11, 2023
91ec34b
css for navbar
carolrs May 12, 2023
ef755da
edits from PR review 1
pablisch May 12, 2023
fab3412
Merge pull request #3 from ManuelaIacobovici/mlpj/new/create-post
pablisch May 12, 2023
d035d8e
Added username in signup, and tests pass
pablisch May 12, 2023
cc69384
completed add username
pablisch May 12, 2023
5e7a956
Merge pull request #5 from ManuelaIacobovici/tcpj/new/add-username
pablisch May 12, 2023
b28e756
AddPost.js | Enabled page refresh upon clicking 'Post'
djohn06 May 12, 2023
f42e9aa
Merge branch 'main' into NavBar
carolrs May 13, 2023
a20da22
changes requested
carolrs May 13, 2023
5eae4dd
changed as requested
carolrs May 13, 2023
bd9b000
test orderByDate passing
carolrs May 14, 2023
a530dfb
Merge pull request #4 from ManuelaIacobovici/NavBar
carolrs May 14, 2023
e06fcca
Merge pull request #6 from ManuelaIacobovici/DjMi/new/RerenderPosts
djohn06 May 15, 2023
25ad1da
validation for email
carolrs May 15, 2023
705a63a
Merged with main
tomcarmichael May 15, 2023
ff70014
Merge pull request #2 from ManuelaIacobovici/tcjr/new/posts_by_date_o…
tomcarmichael May 15, 2023
0248d7e
Publishing branch
djohn06 May 15, 2023
1234d64
Package.json
djohn06 May 15, 2023
9bd9e45
Merge branch 'main' into DjPj/new/AddComment
djohn06 May 15, 2023
d7debaa
added comments array into schema for users
pablisch May 15, 2023
85ecb39
Fixed breaking tests due to username: required being added to Users s…
tomcarmichael May 15, 2023
8cd5b86
Added patch route to routes
pablisch May 15, 2023
ab16663
Added post controller update
pablisch May 15, 2023
ec6acb6
partial implementation, displays timestamp and user Object ID
tomcarmichael May 15, 2023
0d254bf
nav logout button to work, deleted feed logout button
ManuelaIacobovici May 15, 2023
7acd85f
Co-authored-by: Daniel John <[email protected]>
ManuelaIacobovici May 15, 2023
ecc0854
Impelement functionality to display post username and timestamp
tomcarmichael May 15, 2023
b3a431a
Add formatting to display of username and timestamp for posts
tomcarmichael May 15, 2023
93d979b
updated post to patch in AddComment
pablisch May 15, 2023
f32ecc1
update to AddComment controller and comp
pablisch May 15, 2023
b8b5c7e
Update to AddComment component to fix token
pablisch May 15, 2023
17280a1
added username to navbar
ManuelaIacobovici May 15, 2023
d5e56f5
Some CSS to ease the eyes
pablisch May 15, 2023
bfde89f
Add AuthorUserID to new post in posts conroller before saving to DB...
tomcarmichael May 15, 2023
4754ab4
remove erroneous comment. Comment block in posts controller still to …
tomcarmichael May 15, 2023
80ba62e
added username to the navbar
ManuelaIacobovici May 16, 2023
87ba3f9
Remove errnoeuous commented out code block in posts.js
tomcarmichael May 16, 2023
8a7d2a5
tiny css button and input changes
pablisch May 16, 2023
7af127c
Merge pull request #7 from ManuelaIacobovici/mijr/navbar/view
ManuelaIacobovici May 16, 2023
8a8d2c7
Merge with main locally
tomcarmichael May 16, 2023
396f729
Merge pull request #8 from ManuelaIacobovici/tcac/display-username
tomcarmichael May 16, 2023
423df85
Merge branch 'main' into DjPj/new/AddComment
pablisch May 16, 2023
4fef3ed
Merge pull request #9 from ManuelaIacobovici/DjPj/new/AddComment
pablisch May 16, 2023
463c8fb
Removed redundant comma line 12 post model
tomcarmichael May 16, 2023
e48cbdf
Merge pull request #11 from ManuelaIacobovici/tomcarmichael-patch-1
pablisch May 16, 2023
7b5bbdf
Co-authored-by: Tom Carmichael-Mhanna <[email protected]
carolrs May 16, 2023
e1b705c
Add author to comments object and display both
pablisch May 16, 2023
c834ceb
Merge branch 'main' into tcpjmi/fix.add-comments
pablisch May 16, 2023
3fac572
add likes d.b/controller and test for likes
carolrs May 16, 2023
1af9699
Merge pull request #10 from ManuelaIacobovici/NavBar
carolrs May 16, 2023
fc794fe
remove comments and add setNewComment("")
pablisch May 16, 2023
0d27392
Merge pull request #12 from ManuelaIacobovici/tcpjmi/fix.add-comments
pablisch May 16, 2023
81e34ab
Merge branch 'main' into TJA/Likes
carolrs May 16, 2023
6a6dc87
Merge pull request #13 from ManuelaIacobovici/TJA/Likes
carolrs May 16, 2023
f83c12c
username login and logout to login page
pablisch May 16, 2023
4398f48
indentation fix on navbar file
pablisch May 16, 2023
ab04b4a
Update post component unit test so mock post object structure matches…
tomcarmichael May 16, 2023
1ae22bf
adding testing for likes in the models.
carolrs May 16, 2023
cdac3fc
Fix broken feed component unit test, mocking complete post object in …
tomcarmichael May 16, 2023
57a6099
testing for comments
carolrs May 16, 2023
c0f2247
Partial fix of all frontend cypress test, AddComment test outstanding
tomcarmichael May 16, 2023
cfc0822
cypress did this not me!
pablisch May 16, 2023
ebfd0d7
Updated cypresss screenshot for AddComment test
tomcarmichael May 17, 2023
3b1922a
testing avatar
carolrs May 17, 2023
c989a65
Merge pull request #14 from ManuelaIacobovici/pj/fix/username-login
pablisch May 17, 2023
c57c4a9
Local merge with main
tomcarmichael May 17, 2023
1054a2c
Merge pull request #15 from ManuelaIacobovici/tc/testing
tomcarmichael May 17, 2023
6e9390a
Fix failing tests for addComment and addPost
tomcarmichael May 17, 2023
62765c7
add --runInBand flag to npm run test script in backend package.json..
tomcarmichael May 17, 2023
c85ec49
Fix LoginForm test now that we log in with username not email
tomcarmichael May 17, 2023
ed054cf
Fixed e2e signing in test now that sign-in asks for username instead …
tomcarmichael May 17, 2023
095b620
Uncomment window.location.reload() in AddPost.js
tomcarmichael May 17, 2023
d2cad3b
feature setup
tomcarmichael May 17, 2023
c161eb2
Merge pull request #17 from ManuelaIacobovici/tcpj/addCommentTest
tomcarmichael May 17, 2023
4ad75d3
Merge branch 'TJA/Likes' into pj/add/css
pablisch May 17, 2023
8667275
Merge branch 'main' into testing
carolrs May 17, 2023
d7a3974
Merge pull request #18 from ManuelaIacobovici/testing
carolrs May 17, 2023
9adbbb2
correct folder structure error and remove old comments
tomcarmichael May 17, 2023
7633f11
Merge branch 'main' into pj/add/css
pablisch May 17, 2023
17ac584
added labels to input fields for signup and login
ManuelaIacobovici May 17, 2023
8eb9442
trying to merge my branch with main
ManuelaIacobovici May 17, 2023
01362ce
ammended AddLikes in posts controller to use req.user_id & return new…
tomcarmichael May 17, 2023
3b2f8d5
some css on the navbar component
pablisch May 17, 2023
02ef7ff
refactored
ManuelaIacobovici May 17, 2023
64137a4
Co-authored-by: Jamie Richardson <[email protected]
carolrs May 17, 2023
0366b8b
Write intiial code for Likes component
tomcarmichael May 17, 2023
da168b2
single navbar return
ManuelaIacobovici May 17, 2023
54b659b
Merge pull request #19 from ManuelaIacobovici/manuela
ManuelaIacobovici May 17, 2023
6bfb621
Merge pull request #20 from ManuelaIacobovici/midj/fix/navbuttons
ManuelaIacobovici May 17, 2023
ad7c326
navbar css fonts
pablisch May 17, 2023
aff82d7
Merge branch 'main' into pj/add/css
pablisch May 17, 2023
7a6e2be
Basic css for most of site
pablisch May 17, 2023
05d1ec0
fixed the login signup button context thing
pablisch May 17, 2023
0a375fa
Iterate on likes component
tomcarmichael May 18, 2023
6a21b5b
Adjusted NavBar component cypress test to reflect changes and pass tests
tomcarmichael May 18, 2023
6ca21ef
review changes
pablisch May 18, 2023
ee6f91a
Merge branch 'pj/add/css' of https://github.com/ManuelaIacobovici/ace…
pablisch May 18, 2023
a6642fa
Merge pull request #21 from ManuelaIacobovici/pj/add/css
pablisch May 18, 2023
e68b78c
warning fix
pablisch May 18, 2023
9953b36
Merge pull request #22 from ManuelaIacobovici/pj/fix/warning
pablisch May 18, 2023
6b3fe73
Change thumbs up images and correct folder structure
tomcarmichael May 18, 2023
c0ffcb8
Merge with main and resolve conflicts in post component
tomcarmichael May 18, 2023
31522a2
added missing e2e folder in cypress dir
tomcarmichael May 18, 2023
be355c1
fixed two failing tests on the backend - token generator which now t…
tomcarmichael May 18, 2023
aa56549
Merge branch 'main' into testing
carolrs May 18, 2023
c67ffca
Updated AddLikes function in posts controller to look for 'article_id…
tomcarmichael May 18, 2023
a3db32a
taking out the comments
carolrs May 18, 2023
f93840e
continue implementation of like
tomcarmichael May 18, 2023
985714f
adjust posts controller addLikes to take article_id as body param
tomcarmichael May 18, 2023
bcd3ed1
Likes can be added from the front end, display does not yet update
tomcarmichael May 18, 2023
a9a5e54
Merge pull request #23 from ManuelaIacobovici/testing
carolrs May 18, 2023
97cc185
Correct the logic for displaying right like button if user has liked …
tomcarmichael May 18, 2023
86b66d3
Like thumb image is refreshed automatically after user has liked
tomcarmichael May 18, 2023
e739d5d
Update likes label to be singular with just one like
tomcarmichael May 18, 2023
0153799
Working password validation
djohn06 May 18, 2023
13676ec
Update likes component
tomcarmichael May 18, 2023
450e54a
adjust size of liked thumb image
tomcarmichael May 18, 2023
b1f98b9
Write and pass component test for Likes
tomcarmichael May 18, 2023
aa165b6
New posts refresh Feed
pablisch May 18, 2023
a7b3e22
feed reloads when new comment is made
pablisch May 18, 2023
ca3081a
Fix failing test for AddPost and AddComment
tomcarmichael May 18, 2023
1bd9a6f
Local merge with main
tomcarmichael May 18, 2023
f292b74
validation for existing email
carolrs May 18, 2023
e485c7a
Fix cypress e2e tests with valid password
tomcarmichael May 18, 2023
231feec
Fix broken backend tests
tomcarmichael May 18, 2023
20d62a0
Create passing tests for email validation is spec/controllers/users
tomcarmichael May 18, 2023
e3e5c0a
Resolve merge conflict with main
tomcarmichael May 18, 2023
5a25d7f
Merge pull request #24 from ManuelaIacobovici/Dj/new/passwordValidation
djohn06 May 18, 2023
ba21d36
Supplied props to AddPost and AddComment component tests
tomcarmichael May 18, 2023
1981541
Correct token generator test in backend
tomcarmichael May 18, 2023
28534c5
comments collapse and css for changes
pablisch May 18, 2023
5cd01db
package.json changes
pablisch May 18, 2023
7deeb1f
remove redundant comment and console log as per review suggestions
tomcarmichael May 18, 2023
5961c0f
Merge pull request #25 from ManuelaIacobovici/tc/displayLikes
tomcarmichael May 18, 2023
d923d84
tests pass... no, really!
pablisch May 18, 2023
d3e85ed
Merge branch 'main' into pj/new/collapse-comments
pablisch May 18, 2023
21ca2f4
Merge branch 'main' into pablo-test
pablisch May 18, 2023
ca2f6b5
Merge pull request #27 from ManuelaIacobovici/pablo-test
pablisch May 18, 2023
b430ff4
Reformat like button and comments slightly
tomcarmichael May 18, 2023
ed3ebc3
Merge branch 'main' into pj/new/collapse-comments
pablisch May 18, 2023
97f75e9
duplicate code fix
pablisch May 18, 2023
4dacd0f
Create failing test for e2e making a post
tomcarmichael May 18, 2023
4b0ffd2
merge with main
tomcarmichael May 18, 2023
2592d80
Merge with main
carolrs May 18, 2023
bb4859f
e2e test for making a post passes after merge with re render feature …
tomcarmichael May 18, 2023
66ccbb0
update gitignore
carolrs May 18, 2023
a1484a6
fix merge
carolrs May 18, 2023
0f13583
Merge branch 'main' into validation
carolrs May 18, 2023
cade7c6
fixing tests import
carolrs May 18, 2023
e6b6ef6
Merge pull request #29 from ManuelaIacobovici/pj/new/collapse-comments
pablisch May 18, 2023
461e97a
testing for validation when email exist
carolrs May 18, 2023
586f500
deleted unecessary code
pablisch May 18, 2023
05074b1
some nonsense just because
pablisch May 18, 2023
7dce234
deleted commeted and unwanted logs
pablisch May 19, 2023
9dfe5cf
merge with main
tomcarmichael May 19, 2023
e0fcd12
Merge pull request #30 from ManuelaIacobovici/tc/testMakingAPost
tomcarmichael May 19, 2023
50b776c
Merge pull request #31 from ManuelaIacobovici/pj/cleanup/rubbish
pablisch May 19, 2023
65755f7
Merge pull request #26 from ManuelaIacobovici/validation
carolrs May 19, 2023
06e5c09
Upload Image
carolrs May 19, 2023
972415c
Merge pull request #32 from ManuelaIacobovici/validation
carolrs May 19, 2023
e3d81a4
Merge branch 'main' into validation
carolrs May 19, 2023
232e1db
css all over
pablisch May 19, 2023
d004f64
Merge branch 'main' into pj/fix/comments-expand
pablisch May 19, 2023
c878dc6
login route fix
pablisch May 19, 2023
b6ec4cf
Merge pull request #35 from ManuelaIacobovici/pj/fix/login-route
pablisch May 19, 2023
27a442e
Merge pull request #33 from ManuelaIacobovici/pj/fix/comments-expand
pablisch May 19, 2023
a20e74c
fix issue
carolrs May 19, 2023
00c530a
Merge branch 'main' into validation
carolrs May 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
.idea/
.DS_Store

# TypeScript v1 declaration files
typings/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Acebook
# Acebook test

In this project, you are tasked with working on an existing application. A significant part of the challenge will be to familiarise yourself with the codebase you've inherited, as you work to **improve and extend** it.

Expand Down
6 changes: 6 additions & 0 deletions api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ app.use(logger("dev"));
app.use(express.json());
app.use(express.static(path.join(__dirname, "public")));

// avatars is the URL path to access the avatars folder
//display the images in the avatars folder
app.use('/avatars', express.static(path.join(__dirname, 'avatars')));


// middleware function to check for valid tokens
const tokenChecker = (req, res, next) => {

Expand All @@ -43,6 +48,7 @@ app.use("/posts", tokenChecker, postsRouter);
app.use("/tokens", tokensRouter);
app.use("/users", usersRouter);


// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
Expand Down
Binary file added api/avatars/avatar-1684445557794-355625339.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684445706753-820913512.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684445804493-208637956.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684446621323-847301286.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684446976001-133135522.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684488578342-832572094.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684498111864-770689909.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684498694837-402262916.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684499087776-25337143.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684499282078-202831694.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/avatars/avatar-1684499584997-754237290.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 47 additions & 8 deletions api/controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
const Post = require("../models/post");
const TokenGenerator = require("../models/token_generator");
const JWT = require("jsonwebtoken");

const PostsController = {
Index: (req, res) => {
Post.find(async (err, posts) => {
Post.find()
.populate("authorUserID")
.exec(async (err, posts) => {
if (err) {
throw err;
}

const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(200).json({ posts: posts, token: token });
});
},

Create: (req, res) => {
if (!req.user_id) {
return res.status(401).json({ message: "Auth error" });
}
const post = new Post({ ...req.body, authorUserID: req.user_id });
post.save(async (err) => {
if (err) {
throw err;
}
const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(200).json({ posts: posts, token: token });
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(201).json({ message: "OK", token: token });
});
},
Create: (req, res) => {
const post = new Post(req.body);
post.save(async (err) => {
AddLikes: (req, res) => {
Post.findById(req.body.article_id, (err, post) => {
if (err) {
console.log('could not find post')
throw err;
}
post.likes.push(req.body.username);

const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(201).json({ message: 'OK', token: token });
post.save(async (err, post) => {
if (err) {
console.log('could not save the updated post with a new like')
throw err;
}
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(201).json({ message: "OK", post: post, token: token });
});
});
},

Update: async (req, res) => {
try {
const post_id = req.params.id;
console.log(post_id)
const update = req.body;
const updatedPost = await Post.findOneAndUpdate({ _id: post_id }, update, { new: true });
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.json({token})
// res.json({mssg: "You have updated this post!", token: token, updatedPost: updatedPost})
} catch (err) {
res.status(500).json({error: "messed up again!"})
}
},
};

module.exports = PostsController;
5 changes: 3 additions & 2 deletions api/controllers/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const TokenGenerator = require("../models/token_generator")
const SessionsController = {

Create: (req, res) => {
const email = req.body.email;
// const email = req.body.email;
const username = req.body.username;
const password = req.body.password;

User.findOne({ email: email }).then(async (user) => {
User.findOne({ username: username }).then(async (user) => {
if (!user) {
console.log("auth error: user not found")
res.status(401).json({ message: "auth error" });
Expand Down
73 changes: 68 additions & 5 deletions api/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
const User = require("../models/user");
const { validateEmail, validatePassword } = require("../helpers/validation");
const multer = require("multer");

// Configure multer storage
//multer disk storage is used to configure the destination directory and the filename of the uploaded file
const storage = multer.diskStorage({
destination: (req, file, cb) => {
// Specify the destination directory to save the uploaded avatar images
cb(null, "avatars");
},
filename: (req, file, cb) => {
// Generate a unique filename for the uploaded file
//
const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9);
const fileExtension = file.originalname.split(".").pop();
cb(null, "avatar-" + uniqueSuffix + "." + fileExtension);
},
});

// Create multer upload instance
const upload = multer({ storage: storage });

const UsersController = {
Create: (req, res) => {
const user = new User(req.body);
user.save((err) => {
if (err) {
res.status(400).json({message: 'Bad request'})
upload.single("avatar")(req, res, (err) => {
if (err instanceof multer.MulterError) {
res.status(500).json({
message: "Error uploading avatar image",
});
} else if (err) {
res.status(500).json({
message: "Error processing request",
});
} else {
res.status(201).json({ message: 'OK' });
const user = new User(req.body);
if (!validateEmail(user.email)) {
res.status(400).json({
message: "Invalid email address!",
});
} else if (!validatePassword(user.password)) {
res.status(400).json({
message: "Invalid password!",
});
} else {
User.findOne({ email: user.email }).then((check) => {
if (check) {
res.status(400).json({
message: "This Email is already in use!",
});
} else {
if (req.file) {
console.log("FILEEE", req.file);
// req.protocol returns the protocol used (http), so we can use it to construct the full URL
// req.file.filename contains the filename generated by multer
//req.get("host") returns the host name of the server eg. localhost:3000
user.avatar = `${req.protocol}://${req.get("host")}/avatars/${
// req.file.filename contains the filename generated by multer
req.file.filename
}`;
}
//savedUser is the user that was saved in the database
user.save((err, savedUser) => {

if (err) {
res.status(400).json({ message: "Bad request" });
} else {
res.status(201).json({ message: "OK" });
}
});
}
});
}
}
});
},
Expand Down
9 changes: 9 additions & 0 deletions api/helpers/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.validateEmail = (email) => {
//regex to validate email
return String(email).toLocaleLowerCase()
.match(/^([a-z\d\.-]+)@([a-z\d-]+)\.([a-z]{2,12})(\.[a-z]{1,12})?$/)
}
exports.validatePassword = (password) => {
return String(password)
.match(/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{8,20}$/)
}
18 changes: 16 additions & 2 deletions api/models/post.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
const mongoose = require("mongoose");
//const { ObjectId } = require ("mongoose")

const PostSchema = new mongoose.Schema({
message: String
});
message: String,
comments: [], // AddComments: Added comments (empty array) to schema
authorUserID: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: "User"
},
likes: [{
type: String,
default: []
}],
}, {
timestamps: true
}
);

const Post = mongoose.model("Post", PostSchema);

Expand Down
3 changes: 2 additions & 1 deletion api/models/token_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class TokenGenerator {
iat: Math.floor(Date.now() / 1000),

// Set the JWT token to expire in 10 minutes
exp: Math.floor(Date.now() / 1000) + (10 * 60)
// exp: Math.floor(Date.now() / 1000) + (10 * 60) // REAL LINE
exp: Math.floor(Date.now() / 1000) + (100 * 60) // EXTENDED TOKEN LINE
}, secret);
}
}
Expand Down
2 changes: 2 additions & 0 deletions api/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
email: { type: String, required: true },
username: { type: String, required: true },
password: { type: String, required: true },
avatar: { type: String },
});

const User = mongoose.model("User", UserSchema);
Expand Down
Loading