forked from DimiMikadze/orca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dimi Mikadze
committed
Sep 30, 2019
0 parents
commit f9fe43c
Showing
162 changed files
with
21,166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Dependencies | ||
node_modules/ | ||
|
||
# IDE | ||
.idea/ | ||
.vscode/ | ||
|
||
# Misc | ||
.env | ||
.DS_Store | ||
|
||
# Package manager | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# The Wall | ||
|
||
## API GraphQL | ||
|
||
Create `.env` file with the following content | ||
|
||
(replace user, password and SECRET with your custom one) | ||
|
||
``` | ||
# API PORT | ||
API_PORT=4000 | ||
# API URL | ||
API_URL=http://localhost | ||
# CLIENT URL | ||
CLIENT_URL=http://localhost:3000 | ||
# MONGO URL | ||
MONGO_URL=mongodb://tazokochievi:[email protected]:55606/the-wall | ||
# SECRET | ||
SECRET=mskfasjnfakjsnfkjasnfjkasnfjkansjk | ||
# CLOUDINARY | ||
CLOUDINARY_CLOUD_NAME=drwkapa8p | ||
CLOUDINARY_API_KEY=292887744273742 | ||
CLOUDINARY_SECRET=kUsxrMtHmnO6eBe0JHRRAn_aFp4 | ||
``` | ||
|
||
npm install dependencies `npm i` | ||
start server `npm start` | ||
|
||
## Client React App | ||
|
||
Create `.env` file with the following content | ||
|
||
``` | ||
# API URL | ||
REACT_APP_API_URL=http://localhost:4000/graphql | ||
``` | ||
|
||
npm install dependencies `npm i` | ||
start server `npm start` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# API Post | ||
API_PORT=4000 | ||
|
||
# Front end URL | ||
FRONTEND_URL=http://localhost:3000 | ||
|
||
# MongoDB URL from mlab.com or Local one | ||
MONGO_URL=mongodb://demo:[email protected]:21099/create-social-network | ||
|
||
# Secret | ||
SECRET=Super!@Strong!!@::!Secret | ||
|
||
# Cloudinary CDN | ||
CLOUDINARY_CLOUD_NAME=dkkf9iqnd | ||
CLOUDINARY_API_KEY=345283128864692 | ||
CLOUDINARY_SECRET=lx3iSxt-1c_LO5ma3P_RLT8TF3Q | ||
|
||
# Mail Provider | ||
MAIL_SERVICE="Gmail" # Email services | ||
MAIL_USER="[email protected]" # Email address | ||
MAIL_PASS="password" # Email password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* We are using ESM ECMAScript module loader | ||
* to use import/export syntax without using babel or any other compiler | ||
* https://github.com/standard-things/esm | ||
*/ | ||
|
||
require = require("esm")(module); | ||
|
||
module.exports = require("./server.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* Comments schema that has reference to Post and user schemas | ||
*/ | ||
const commentSchema = Schema( | ||
{ | ||
comment: { | ||
type: String, | ||
required: true | ||
}, | ||
post: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Post" | ||
}, | ||
author: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
} | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
export default mongoose.model("Comment", commentSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* Follow schema that has references to User schema | ||
*/ | ||
const followSchema = Schema( | ||
{ | ||
user: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
}, | ||
follower: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
} | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
export default mongoose.model("Follow", followSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* Like schema that has references to Post and User schema | ||
*/ | ||
const likeSchema = Schema( | ||
{ | ||
post: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Post" | ||
}, | ||
user: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
} | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
export default mongoose.model("Like", likeSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* Notification schema that has references to User, Like, Follow and Comment schemas | ||
*/ | ||
const notificationSchema = Schema( | ||
{ | ||
author: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
}, | ||
user: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
}, | ||
post: Schema.Types.ObjectId, | ||
like: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Like" | ||
}, | ||
follow: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Follow" | ||
}, | ||
comment: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Comment" | ||
}, | ||
seen: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
export default mongoose.model("Notification", notificationSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* Post schema that has references to User, Like and Comment schemas | ||
*/ | ||
const postSchema = Schema( | ||
{ | ||
title: String, | ||
image: String, | ||
imagePublicId: String, | ||
author: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
}, | ||
likes: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Like" | ||
} | ||
], | ||
comments: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Comment" | ||
} | ||
] | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
export default mongoose.model("Post", postSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import mongoose from "mongoose"; | ||
import bcrypt from "bcryptjs"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
/** | ||
* User schema that has references to Post, Like, Comment, Follow and Notification schemas | ||
*/ | ||
const userSchema = new Schema( | ||
{ | ||
fullName: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
lowercase: true, | ||
trim: true, | ||
unique: true | ||
}, | ||
username: { | ||
type: String, | ||
required: true, | ||
lowercase: true, | ||
trim: true, | ||
unique: true | ||
}, | ||
passwordResetToken: String, | ||
passwordResetTokenExpiry: Date, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
image: String, | ||
imagePublicId: String, | ||
coverImage: String, | ||
coverImagePublicId: String, | ||
posts: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Post" | ||
} | ||
], | ||
likes: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Like" | ||
} | ||
], | ||
comments: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Comment" | ||
} | ||
], | ||
followers: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Follow" | ||
} | ||
], | ||
following: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Follow" | ||
} | ||
], | ||
notifications: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Notification" | ||
} | ||
] | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
/** | ||
* Hashes the users password when saving it to DB | ||
*/ | ||
userSchema.pre("save", function(next) { | ||
if (!this.isModified("password")) { | ||
return next(); | ||
} | ||
|
||
bcrypt.genSalt(10, (err, salt) => { | ||
if (err) return next(err); | ||
|
||
bcrypt.hash(this.password, salt, (err, hash) => { | ||
if (err) return next(err); | ||
|
||
this.password = hash; | ||
next(); | ||
}); | ||
}); | ||
}); | ||
|
||
export default mongoose.model("User", userSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import User from "./User"; | ||
import Post from "./Post"; | ||
import Like from "./Like"; | ||
import Follow from "./Follow"; | ||
import Comment from "./Comment"; | ||
import Notification from "./Notification"; | ||
|
||
export default { | ||
User, | ||
Post, | ||
Like, | ||
Follow, | ||
Comment, | ||
Notification | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Models | ||
|
||
Models are fancy constructors compiled from Schema definitions. An instance of a model is called a document. Models are responsible for creating and reading documents from the underlying MongoDB database. | ||
|
||
https://mongoosejs.com/docs/models.html | ||
|
||
### Referencing documents in other collections | ||
|
||
https://mongoosejs.com/docs/populate.html |
Oops, something went wrong.