diff --git a/back/dist/Loader/db.js b/back/dist/Loader/db.js new file mode 100644 index 00000000..3d6940a4 --- /dev/null +++ b/back/dist/Loader/db.js @@ -0,0 +1,32 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +const config_1 = __importDefault(require("../config")); +const connectDB = () => __awaiter(void 0, void 0, void 0, function* () { + try { + yield mongoose_1.default.connect(config_1.default.mongoURI, { + useNewUrlParser: true, + useCreateIndex: true, + useUnifiedTopology: true, + }); + console.log("Mongoose Connected ..."); + } + catch (err) { + console.error(err.message); + process.exit(1); + } +}); +exports.default = connectDB; +//# sourceMappingURL=db.js.map \ No newline at end of file diff --git a/back/dist/Loader/db.js.map b/back/dist/Loader/db.js.map new file mode 100644 index 00000000..fde7e7ac --- /dev/null +++ b/back/dist/Loader/db.js.map @@ -0,0 +1 @@ +{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/Loader/db.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wDAAgC;AAChC,uDAA+B;AAE/B,MAAM,SAAS,GAAG,GAAS,EAAE;IAC3B,IAAI;QACF,MAAM,kBAAQ,CAAC,OAAO,CAAC,gBAAM,CAAC,QAAQ,EAAE;YACtC,eAAe,EAAE,IAAI;YACrB,cAAc,EAAE,IAAI;YACpB,kBAAkB,EAAE,IAAI;SACzB,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;KACvC;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAA,CAAC;AAEF,kBAAe,SAAS,CAAC"} \ No newline at end of file diff --git a/back/dist/api/auth.js b/back/dist/api/auth.js new file mode 100644 index 00000000..60926f9d --- /dev/null +++ b/back/dist/api/auth.js @@ -0,0 +1,86 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); +const bcryptjs_1 = __importDefault(require("bcryptjs")); +const config_1 = __importDefault(require("../config")); +const express_validator_1 = require("express-validator"); +const router = express_1.default.Router(); +const auth_1 = __importDefault(require("../middleware/auth")); +const User_1 = __importDefault(require("../models/User")); +/** + * @route Post api/auth + * @desc Authenticate user & get token(로그인) + * @access Public + */ +router.post("/", [ + express_validator_1.check("email", "Please include a valid email").isEmail(), + express_validator_1.check("password", "Password is required").exists(), +], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { email, password } = req.body; + try { + let user = yield User_1.default.findOne({ email }); + if (!user) { + res.status(400).json({ + errors: [{ msg: "Invalid Credentials" }], + }); + } + // Encrpyt password + const isMatch = yield bcryptjs_1.default.compare(password, user.password); + if (!isMatch) { + res.status(400).json({ + errors: [{ msg: "Invalid Credentials" }], + }); + } + // Return jsonwebtoken + const payload = { + user: { + id: user.id, + }, + }; + jsonwebtoken_1.default.sign(payload, config_1.default.jwtSecret, { expiresIn: 36000 }, (err, token) => { + if (err) + throw err; + res.json({ token }); + }); + } + catch (err) { + console.error(err.message); + res.status(500).send("Server Error"); + } +})); +/* + * @route GET api/auth + * @desc Test Route + * @access Public + */ +router.get("/", auth_1.default, function (req, res) { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield User_1.default.findById(req.body.user.id).select("-password"); + res.json(user); + } + catch (err) { + console.error(err.message); + res.status(500).send("Server Err"); + } + }); +}); +module.exports = router; +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/back/dist/api/auth.js.map b/back/dist/api/auth.js.map new file mode 100644 index 00000000..1babb69e --- /dev/null +++ b/back/dist/api/auth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/api/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAqD;AACrD,gEAA+B;AAC/B,wDAA8B;AAC9B,uDAA+B;AAC/B,yDAA4D;AAE5D,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;AAEhC,8DAAsC;AACtC,0DAAkC;AAElC;;;;GAIG;AACH,MAAM,CAAC,IAAI,CACT,GAAG,EACH;IACE,yBAAK,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC,OAAO,EAAE;IACxD,yBAAK,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC,MAAM,EAAE;CACnD,EACD,CAAO,GAAY,EAAE,GAAa,EAAE,EAAE;IACpC,MAAM,MAAM,GAAG,oCAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,C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C,OAAO,CAAC,CAAC;QAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;KACtC;AACH,CAAC,CAAA,CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,cAAI,EAAE,UAAgB,GAAY,EAAE,GAAa;;QAC/D,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,cAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACvE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAChB;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACpC;IACH,CAAC;CAAA,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/back/dist/api/post.js b/back/dist/api/post.js new file mode 100644 index 00000000..648228cc --- /dev/null +++ b/back/dist/api/post.js @@ -0,0 +1,222 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = require("express"); +const express_validator_1 = require("express-validator"); +const auth_1 = __importDefault(require("../middleware/auth")); +const User_1 = __importDefault(require("../models/User")); +const Post_1 = __importDefault(require("../models/Post")); +const router = express_1.Router(); +/** + * @route POST api/posts + * @desc Create a post + * @access Private + */ +router.post("/", auth_1.default, [express_validator_1.check("text", "Text is required").not().isEmpty()], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { text } = req.body; + try { + const user = yield User_1.default.findById(req.body.user.id).select("-password"); + const newPost = new Post_1.default({ + text: text, + name: user.name, + avatar: user.avatar, + user: user.id, + }); + const post = yield newPost.save(); + res.json(post); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +/** + * @route GET api/posts + * @desc Get all posts + * @access Private + */ +router.get("/", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const posts = yield Post_1.default.find().sort({ date: -1 }); + res.json(posts); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +/** + * @route GET api/posts/:id + * @desc Get post by ID + * @access Private + */ +router.get("/:id", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const post = yield Post_1.default.findById(req.params.id); + if (!post) { + return res.status(404).json({ msg: "Post not found" }); + } + res.json(post); + } + catch (error) { + console.error(error.message); + if (error.kind === "ObjectId") { + return res.status(404).json({ msg: "Post not found" }); + } + res.status(500).send("Server Error"); + } +})); +/** + * @route DELETE api/posts/:id + * @desc Delete a post + * @access Private + */ +router.delete("/:id", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const post = yield Post_1.default.findById(req.params.id); + if (!post) { + return res.status(404).json({ msg: "Post not found" }); + } + if (post.user.toString() !== req.body.user.id) { + return res.status(401).json({ msg: "User not Authorized" }); + } + yield post.remove(); + res.json({ msg: "Post Removed" }); + } + catch (error) { + console.error(error.message); + if (error.kind === "ObjectId") { + return res.status(404).json({ msg: "Post not found" }); + } + res.status(500).send("Server Error"); + } +})); +/** + * @route PUT api/posts/like/:id + * @desc Like a post + * @access Private + */ +router.put("/like/:id", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const post = yield Post_1.default.findById(req.params.id); + if (!post) { + return res.status(404).json({ msg: "Post not found" }); + } + if (post.likes.filter((like) => like.user.toString() === req.body.user.id) + .length > 0) { + return res.status(400).json({ msg: "Post already liked" }); + } + yield post.likes.unshift({ user: req.body.user.id }); + yield post.save(); + res.json(post.likes); + } + catch (error) { + console.error(error.message); + if (error.kind === "ObjectId") { + return res.status(404).json({ msg: "Post not found" }); + } + res.status(500).send("Server Error"); + } +})); +/** + * @route PUT api/posts/unlike/:id + * @desc Unlike a post + * @access Private + */ +router.put("/unlike/:id", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const post = yield Post_1.default.findById(req.params.id); + if (!post) { + return res.status(404).json({ msg: "Post not found" }); + } + if (post.likes.filter((like) => like.user.toString() === req.body.user.id) + .length === 0) { + return res.status(400).json({ msg: "Post has not yet been liked" }); + } + const removeIndex = post.likes + .map((like) => like.user) + .indexOf(req.body.user.id); + post.likes.splice(removeIndex, 1); + yield post.save(); + res.json(post.likes); + } + catch (error) { + console.error(error.message); + if (error.kind === "ObjectId") { + return res.status(404).json({ msg: "Post not found" }); + } + res.status(500).send("Server Error"); + } +})); +/** + * @route POST api/posts/comment/:id + * @desc Comment a post + * @access Private + */ +router.post("/comment/:id", auth_1.default, [express_validator_1.check("text", "Text is required").not().isEmpty()], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + try { + const user = yield User_1.default.findById(req.body.user.id).select("-password"); + const post = yield Post_1.default.findById(req.params.id); + const newComment = { + text: req.body.text, + name: user.name, + avatar: user.avatar, + user: req.body.user.id, + }; + post.comments.unshift(newComment); + yield post.save(); + res.json(post.comments); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +/** + * @route DELETE api/posts/comment/:id/:comment_id + * @desc Delete comment + * @access Private + */ +router.delete("/comment/:id/:comment_id", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const post = yield Post_1.default.findById(req.params.id); + const comment = post.comments.find((comment) => comment._id.toString() === req.params.comment_id); + if (!comment) { + return res.status(400).json({ msg: " Comment does not exist" }); + } + if (comment.user.toString() !== req.body.user.id) { + return res.status(401).json({ msg: "User not Authorized" }); + } + const removeIndex = post.comments + .map((comment) => comment.user.toString()) + .indexOf(req.body.user.id); + post.comments.splice(removeIndex, 1); + yield post.save(); + res.json(post.comments); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +module.exports = router; +//# sourceMappingURL=post.js.map \ No newline at end of file diff --git a/back/dist/api/post.js.map b/back/dist/api/post.js.map new file mode 100644 index 00000000..3087773c --- /dev/null +++ b/back/dist/api/post.js.map @@ -0,0 +1 @@ +{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/api/post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAoD;AACpD,yDAA4D;AAE5D,8DAAsC;AACtC,0DAAkC;AAClC,0DAAkC;AAIlC,MAAM,MAAM,GAAG,gBAAM,EAAE,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,IAAI,CACT,GAAG,EACH,cAAI,EACJ,CAAC,yBAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,EACnD,CAAO,GAAY,EAAE,GAAa,EAAE,EAAE;IACpC,MAAM,MAAM,GAAG,oCAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;QACrB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC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AAE;YACZ,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,yBAAyB,EAAE,CAAC,CAAC;SACjE;QAED,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;YAChD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,qBAAqB,EAAE,CAAC,CAAC;SAC7D;QACD,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ;aAC9B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;aACzC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACrC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACzB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;KACtC;AACH,CAAC,CAAA,CAAC,CAAC;AACH,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/back/dist/api/profile.js b/back/dist/api/profile.js new file mode 100644 index 00000000..05d43e81 --- /dev/null +++ b/back/dist/api/profile.js @@ -0,0 +1,237 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = require("express"); +const request_1 = __importDefault(require("request")); +const express_validator_1 = require("express-validator"); +const config_1 = __importDefault(require("../config")); +const auth_1 = __importDefault(require("../middleware/auth")); +const Profile_1 = __importDefault(require("../models/Profile")); +const router = express_1.Router(); +/** + * @route GET api/profile + * @desc Get all profiles + * @access Public + */ +router.get("/", (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const profiles = yield Profile_1.default.find().populate("user", ["name", "avatar"]); + res.json(profiles); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +/** + * @route GET api/profile/user/:user_id + * @desc Get profile by user ID + * @access Public + */ +router.get("/user/:user_id", (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const profile = yield Profile_1.default.findOne({ + user: req.params.user_id, + }).populate("user", ["name", "avatar"]); + if (!profile) + return res.status(400).json({ msg: "Profile not found" }); + res.json(profile); + } + catch (error) { + console.error(error.message); + if (error.kind == "ObjectId") { + return res.status(400).json({ msg: "Profile not found" }); + } + res.status(500).send("Server Error"); + } +})); +/** + * @route GET api/profile/github/:username + * @desc Get user repos from github + * @access Public + */ +router.get("/github/:username", (req, res) => { + try { + const options = { + uri: `https://api.github.com/users/${req.params.username}/repos?per_page=5&sort=created:asc&client_id=${config_1.default.githubClientId}&client_secret=${config_1.default.githubSecret}`, + method: "GET", + headers: { "user-agent": "node.js" }, + }; + request_1.default(options, (error, response, body) => { + if (error) + console.error(error); + if (response.statusCode != 200) { + res.status(404).json({ msg: "No github profile found" }); + } + res.json(JSON.parse(body)); + }); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +}); +/** + * @route GET api/profile/me + * @desc Get current users profile + * @access Private + */ +router.get("/me", auth_1.default, (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const profile = yield Profile_1.default.findOne({ + user: req.body.user.id, + }).populate("user", ["name", "avatar"]); + if (!profile) { + return res.status(400).json({ msg: "There is no profile for this user" }); + } + res.json(profile); + } + catch (err) { + console.error(err.message); + res.status(500).send("Server Error"); + } +})); +/** + * @route POST api/profile + * @desc Create or update user profile + * @access Private + */ +router.post("/", auth_1.default, [ + express_validator_1.check("status", "Status is required").not().isEmpty(), + express_validator_1.check("skills", "Skills is required").not().isEmpty(), +], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { company, website, location, bio, status, githubusername, skills, youtube, facebook, twitter, linkedin, instagram, user, } = req.body; + // Build profile object + let profileFields = { + user: user.id, + }; + if (company) + profileFields.company = company; + if (website) + profileFields.website = website; + if (location) + profileFields.location = location; + if (bio) + profileFields.bio = bio; + if (status) + profileFields.status = status; + if (githubusername) + profileFields.githubusername = githubusername; + if (skills) { + profileFields.skills = skills.split(",").map((skill) => skill.trim()); + } + // Build social object + if (youtube) + profileFields.social.youtube = youtube; + if (facebook) + profileFields.social.facebook = facebook; + if (twitter) + profileFields.social.twitter = twitter; + if (linkedin) + profileFields.social.linkedin = linkedin; + if (instagram) + profileFields.social.instagram = instagram; + try { + let profile = yield Profile_1.default.findOne({ user: user.id }); + if (profile) { + // Update + profile = yield Profile_1.default.findOneAndUpdate({ user: user.id }, { $set: { value: profileFields } }, { new: true }); + return res.json(profile); + } + // Create + profile = new Profile_1.default(profileFields); + yield profile.save(); + res.json(profile); + } + catch (err) { + console.error(err.message); + status(500).send("Server Error."); + } +})); +/** + * @route PUT api/profile/experience + * @desc Add profile experience + * @access Private + */ +router.put("/experience", auth_1.default, [ + express_validator_1.check("title", "Title is required").not().isEmpty(), + express_validator_1.check("company", "Company is required").not().isEmpty(), + express_validator_1.check("from", "From data is required").not().isEmpty(), +], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { title, company, location, from, to, current, description, } = req.body; + const newExp = { + title, + company, + location, + from, + to, + current, + description, + }; + try { + const profile = yield Profile_1.default.findOne({ user: req.body.user.id }); + profile.experience.unshift(newExp); + yield profile.save(); + res.json(profile); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +/** + * @route PUT api/profile/education + * @desc Add profile education + * @access Private + */ +router.put("/education", auth_1.default, [ + express_validator_1.check("school", "School is required").not().isEmpty(), + express_validator_1.check("degree", "Degree is required").not().isEmpty(), + express_validator_1.check("fieldofstudy", "Field of study is required").not().isEmpty(), +], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { school, degree, fieldofstudy, from, to, current, description, user, } = req.body; + const newEdu = { + school, + degree, + fieldofstudy, + from, + to, + current, + description, + }; + try { + const profile = yield Profile_1.default.findOne({ user: user.id }); + profile.education.unshift(newEdu); + yield profile.save(); + res.json(profile); + } + catch (error) { + console.error(error.message); + res.status(500).send("Server Error"); + } +})); +module.exports = router; +//# sourceMappingURL=profile.js.map \ No newline at end of file diff --git a/back/dist/api/profile.js.map b/back/dist/api/profile.js.map new file mode 100644 index 00000000..02176a5b --- /dev/null +++ b/back/dist/api/profile.js.map @@ -0,0 +1 @@ +{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/api/profile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAoD;AACpD,sDAA8B;AAC9B,yDAA4D;AAC5D,uDAA+B;AAE/B,8DAAsC;AACtC,gEAAwC;AAGxC,MAAM,MAAM,GAAG,gBAAM,EAAE,CAAC;AAExB;;;;GAI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AAC;KACzD;IACD,MAAM,EACJ,MAAM,EACN,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,EAAE,EACF,OAAO,EACP,WAAW,EACX,IAAI,GACL,GAAG,GAAG,CAAC,IAAI,CAAC;IAEb,MAAM,MAAM,GAAG;QACb,MAAM;QACN,MAAM;QACN,YAAY;QACZ,IAAI;QACJ,EAAE;QACF,OAAO;QACP,WAAW;KACZ,CAAC;IAEF,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,iBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACnB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;KACtC;AACH,CAAC,CAAA,CACF,CAAC;AACF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/back/dist/api/users.js b/back/dist/api/users.js new file mode 100644 index 00000000..8f6c80b8 --- /dev/null +++ b/back/dist/api/users.js @@ -0,0 +1,80 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const gravatar_1 = __importDefault(require("gravatar")); +const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); +const bcryptjs_1 = __importDefault(require("bcryptjs")); +const config_1 = __importDefault(require("../config")); +const express_validator_1 = require("express-validator"); +const router = express_1.default.Router(); +const User_1 = __importDefault(require("../models/User")); +/** + * @route Post api/users + * @desc Register User + * @access Public + */ +router.post("/", [ + express_validator_1.check("name", "Name is required").not().isEmpty(), + express_validator_1.check("email", "Please include a valid email").isEmail(), + express_validator_1.check("password", "Please enter a password with 6 or more characters").isLength({ min: 6 }), +], (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const errors = express_validator_1.validationResult(req); + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { name, email, password } = req.body; + try { + // See if user exists + let user = yield User_1.default.findOne({ email }); + if (user) { + res.status(400).json({ + errors: [{ msg: "User already exists" }], + }); + } + // Get users gravatar + const avatar = gravatar_1.default.url(email, { + s: "200", + r: "pq", + d: "mm", + }); + user = new User_1.default({ + name, + email, + avatar, + password, + }); + // Encrpyt password + const salt = yield bcryptjs_1.default.genSalt(10); + user.password = yield bcryptjs_1.default.hash(password, salt); + yield user.save(); + // Return jsonwebtoken + const payload = { + user: { + id: user.id, + }, + }; + jsonwebtoken_1.default.sign(payload, config_1.default.jwtSecret, { expiresIn: 36000 }, (err, token) => { + if (err) + throw err; + res.json({ token }); + }); + } + catch (err) { + console.error(err.message); + res.status(500).send("Server Error"); + } +})); +module.exports = router; +//# sourceMappingURL=users.js.map \ No newline at end of file diff --git a/back/dist/api/users.js.map b/back/dist/api/users.js.map new file mode 100644 index 00000000..d43a66ac --- /dev/null +++ b/back/dist/api/users.js.map @@ -0,0 +1 @@ +{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/api/users.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sD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AC,EAAE,IAAI;SACR,CAAC,CAAC;QAEH,IAAI,GAAG,IAAI,cAAI,CAAC;YACd,IAAI;YACJ,KAAK;YACL,MAAM;YACN,QAAQ;SACT,CAAC,CAAC;QAEH,mBAAmB;QACnB,MAAM,IAAI,GAAG,MAAM,kBAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,MAAM,kBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAElD,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAElB,sBAAsB;QACtB,MAAM,OAAO,GAAG;YACd,IAAI,EAAE;gBACJ,EAAE,EAAE,IAAI,CAAC,EAAE;aACZ;SACF,CAAC;QACF,sBAAG,CAAC,IAAI,CACN,OAAO,EACP,gBAAM,CAAC,SAAS,EAChB,EAAE,SAAS,EAAE,KAAK,EAAE,EACpB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACb,IAAI,GAAG;gBAAE,MAAM,GAAG,CAAC;YACnB,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACtB,CAAC,CACF,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;KACtC;AACH,CAAC,CAAA,CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/back/dist/config/index.js b/back/dist/config/index.js new file mode 100644 index 00000000..13cf2af0 --- /dev/null +++ b/back/dist/config/index.js @@ -0,0 +1,31 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const dotenv_1 = __importDefault(require("dotenv")); +// Set the NODE_ENV to 'development' by default +process.env.NODE_ENV = process.env.NODE_ENV || "development"; +const envFound = dotenv_1.default.config(); +if (envFound.error) { + // This error should crash whole process + throw new Error("⚠️ Couldn't find .env file ⚠️"); +} +exports.default = { + /** + * Your favorite port + */ + port: parseInt(process.env.PORT, 10), + /** + * That long string from mlab + */ + mongoURI: process.env.MONGODB_URI, + /** + * Your secret sauce + */ + jwtSecret: process.env.JWT_SECRET, + jwtAlgorithm: process.env.JWT_ALGO, + githubClientId: process.env.GITHUB_CLIENT_ID, + githubSecret: process.env.GITHUB_SECRET, +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/back/dist/config/index.js.map b/back/dist/config/index.js.map new file mode 100644 index 00000000..a313c076 --- /dev/null +++ b/back/dist/config/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,+CAA+C;AAC/C,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAE7D,MAAM,QAAQ,GAAG,gBAAM,CAAC,MAAM,EAAE,CAAC;AACjC,IAAI,QAAQ,CAAC,KAAK,EAAE;IAClB,wCAAwC;IAExC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;CACpD;AAED,kBAAe;IACb;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IAEpC;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;IAEjC;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;IACjC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;IAElC,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;IAC5C,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;CACxC,CAAC"} \ No newline at end of file diff --git a/back/dist/index.js b/back/dist/index.js new file mode 100644 index 00000000..56d0d503 --- /dev/null +++ b/back/dist/index.js @@ -0,0 +1,39 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const app = express_1.default(); +const db_1 = __importDefault(require("./Loader/db")); +// Connect Database +db_1.default(); +app.use(express_1.default.urlencoded()); +app.use(express_1.default.json()); +// Define Routes +app.use("/api/users", require("./api/users")); +app.use("/api/profile", require("./api/profile")); +app.use("/api/posts", require("./api/post")); +app.use("/api/auth", require("./api/auth")); +// error handler +app.use(function (err, req, res, next) { + // set locals, only providing error in development + res.locals.message = err.message; + res.locals.error = req.app.get("env") === "production" ? err : {}; + // render the error page + res.status(err.status || 500); + res.render("error"); +}); +app + .listen(5000, () => { + console.log(` + ################################################ + 🛡️ Server listening on port: 5000 🛡️ + ################################################ + `); +}) + .on("error", (err) => { + console.error(err); + process.exit(1); +}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/back/dist/index.js.map b/back/dist/index.js.map new file mode 100644 index 00000000..f5e10e63 --- /dev/null +++ b/back/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,MAAM,GAAG,GAAG,iBAAO,EAAE,CAAC;AACtB,qDAAoC;AAEpC,mBAAmB;AACnB,YAAS,EAAE,CAAC;AAEZ,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAC9B,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAExB,gBAAgB;AAChB,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AAC9C,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;AAClD,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;AAC7C,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;AAE5C,gBAAgB;AAChB,GAAG,CAAC,GAAG,CAAC,UAAU,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI;IACnC,kDAAkD;IAClD,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IACjC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAElE,wBAAwB;IACxB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;IAC9B,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC,CAAC,CAAC;AAEH,GAAG;KACA,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC;;;;GAIb,CAAC,CAAC;AACH,CAAC,CAAC;KACD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/back/dist/interfaces/IComment.js b/back/dist/interfaces/IComment.js new file mode 100644 index 00000000..4d354d19 --- /dev/null +++ b/back/dist/interfaces/IComment.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IComment.js.map \ No newline at end of file diff --git a/back/dist/interfaces/IComment.js.map b/back/dist/interfaces/IComment.js.map new file mode 100644 index 00000000..3d47827f --- /dev/null +++ b/back/dist/interfaces/IComment.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IComment.js","sourceRoot":"","sources":["../../src/interfaces/IComment.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/IEducation.js b/back/dist/interfaces/IEducation.js new file mode 100644 index 00000000..cd3e463e --- /dev/null +++ b/back/dist/interfaces/IEducation.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IEducation.js.map \ No newline at end of file diff --git a/back/dist/interfaces/IEducation.js.map b/back/dist/interfaces/IEducation.js.map new file mode 100644 index 00000000..521683d0 --- /dev/null +++ b/back/dist/interfaces/IEducation.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IEducation.js","sourceRoot":"","sources":["../../src/interfaces/IEducation.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/IExperience.js b/back/dist/interfaces/IExperience.js new file mode 100644 index 00000000..17e94a5a --- /dev/null +++ b/back/dist/interfaces/IExperience.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IExperience.js.map \ No newline at end of file diff --git a/back/dist/interfaces/IExperience.js.map b/back/dist/interfaces/IExperience.js.map new file mode 100644 index 00000000..f327580d --- /dev/null +++ b/back/dist/interfaces/IExperience.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IExperience.js","sourceRoot":"","sources":["../../src/interfaces/IExperience.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/ILike.js b/back/dist/interfaces/ILike.js new file mode 100644 index 00000000..c13788ca --- /dev/null +++ b/back/dist/interfaces/ILike.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=ILike.js.map \ No newline at end of file diff --git a/back/dist/interfaces/ILike.js.map b/back/dist/interfaces/ILike.js.map new file mode 100644 index 00000000..84423ddf --- /dev/null +++ b/back/dist/interfaces/ILike.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ILike.js","sourceRoot":"","sources":["../../src/interfaces/ILike.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/IPost.js b/back/dist/interfaces/IPost.js new file mode 100644 index 00000000..209c411d --- /dev/null +++ b/back/dist/interfaces/IPost.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IPost.js.map \ No newline at end of file diff --git a/back/dist/interfaces/IPost.js.map b/back/dist/interfaces/IPost.js.map new file mode 100644 index 00000000..da7144c2 --- /dev/null +++ b/back/dist/interfaces/IPost.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IPost.js","sourceRoot":"","sources":["../../src/interfaces/IPost.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/IProfile.js b/back/dist/interfaces/IProfile.js new file mode 100644 index 00000000..ff55a4b5 --- /dev/null +++ b/back/dist/interfaces/IProfile.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IProfile.js.map \ No newline at end of file diff --git a/back/dist/interfaces/IProfile.js.map b/back/dist/interfaces/IProfile.js.map new file mode 100644 index 00000000..d17f29a4 --- /dev/null +++ b/back/dist/interfaces/IProfile.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IProfile.js","sourceRoot":"","sources":["../../src/interfaces/IProfile.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/ISocial.js b/back/dist/interfaces/ISocial.js new file mode 100644 index 00000000..fe710d61 --- /dev/null +++ b/back/dist/interfaces/ISocial.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=ISocial.js.map \ No newline at end of file diff --git a/back/dist/interfaces/ISocial.js.map b/back/dist/interfaces/ISocial.js.map new file mode 100644 index 00000000..2341d49c --- /dev/null +++ b/back/dist/interfaces/ISocial.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ISocial.js","sourceRoot":"","sources":["../../src/interfaces/ISocial.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/interfaces/IUser.js b/back/dist/interfaces/IUser.js new file mode 100644 index 00000000..6d13f68e --- /dev/null +++ b/back/dist/interfaces/IUser.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=IUser.js.map \ No newline at end of file diff --git a/back/dist/interfaces/IUser.js.map b/back/dist/interfaces/IUser.js.map new file mode 100644 index 00000000..61beb22c --- /dev/null +++ b/back/dist/interfaces/IUser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IUser.js","sourceRoot":"","sources":["../../src/interfaces/IUser.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/back/dist/middleware/auth.js b/back/dist/middleware/auth.js new file mode 100644 index 00000000..468dc320 --- /dev/null +++ b/back/dist/middleware/auth.js @@ -0,0 +1,25 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); +const config_1 = __importDefault(require("../config")); +exports.default = (req, res, next) => { + // Get token from header + const token = req.header("x-auth-token"); + // Check if not token + if (!token) { + return res.status(401).json({ msg: "No token, authorization denied" }); + } + // Verify token + try { + const decoded = jsonwebtoken_1.default.verify(token, config_1.default.jwtSecret); + req.body.user = decoded.user; + next(); + } + catch (err) { + res.status(401).json({ msg: "Token is not valid" }); + } +}; +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/back/dist/middleware/auth.js.map b/back/dist/middleware/auth.js.map new file mode 100644 index 00000000..04abc5db --- /dev/null +++ b/back/dist/middleware/auth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":";;;;;AAAA,gEAA+B;AAC/B,uDAA+B;AAE/B,kBAAe,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAChC,wBAAwB;IACxB,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEzC,qBAAqB;IACrB,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,gCAAgC,EAAE,CAAC,CAAC;KACxE;IAED,eAAe;IACf,IAAI;QACF,MAAM,OAAO,GAAG,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,gBAAM,CAAC,SAAS,CAAC,CAAC;QAEpD,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC7B,IAAI,EAAE,CAAC;KACR;IAAC,OAAO,GAAG,EAAE;QACZ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,oBAAoB,EAAE,CAAC,CAAC;KACrD;AACH,CAAC,CAAC"} \ No newline at end of file diff --git a/back/dist/models/Post.js b/back/dist/models/Post.js new file mode 100644 index 00000000..b98f97ab --- /dev/null +++ b/back/dist/models/Post.js @@ -0,0 +1,58 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +const PostSchema = new mongoose_1.default.Schema({ + user: { + type: mongoose_1.default.SchemaTypes.ObjectId, + ref: "User", + }, + text: { + type: String, + required: true, + }, + name: { + type: String, + }, + avatar: { + type: String, + }, + likes: [ + { + user: { + type: mongoose_1.default.Types.ObjectId, + ref: "User", + }, + }, + ], + comments: [ + { + user: { + type: mongoose_1.default.Types.ObjectId, + ref: "User", + }, + text: { + type: String, + required: true, + }, + name: { + type: String, + }, + avatar: { + type: String, + }, + date: { + type: Date, + default: Date.now, + }, + }, + ], + date: { + type: Date, + default: Date.now, + }, +}); +exports.default = mongoose_1.default.model("Post", PostSchema); +//# sourceMappingURL=Post.js.map \ No newline at end of file diff --git a/back/dist/models/Post.js.map b/back/dist/models/Post.js.map new file mode 100644 index 00000000..166823b4 --- /dev/null +++ b/back/dist/models/Post.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Post.js","sourceRoot":"","sources":["../../src/models/Post.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAGhC,MAAM,UAAU,GAAG,IAAI,kBAAQ,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,kBAAQ,CAAC,WAAW,CAAC,QAAQ;QACnC,GAAG,EAAE,MAAM;KACZ;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;KACb;IACD,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;KACb;IACD,KAAK,EAAE;QACL;YACE,IAAI,EAAE;gBACJ,IAAI,EAAE,kBAAQ,CAAC,KAAK,CAAC,QAAQ;gBAC7B,GAAG,EAAE,MAAM;aACZ;SACF;KACF;IACD,QAAQ,EAAE;QACR;YACE,IAAI,EAAE;gBACJ,IAAI,EAAE,kBAAQ,CAAC,KAAK,CAAC,QAAQ;gBAC7B,GAAG,EAAE,MAAM;aACZ;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,MAAM;aACb;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM;aACb;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,IAAI,CAAC,GAAG;aAClB;SACF;KACF;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI,CAAC,GAAG;KAClB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAQ,CAAC,KAAK,CAA4B,MAAM,EAAE,UAAU,CAAC,CAAC"} \ No newline at end of file diff --git a/back/dist/models/Profile.js b/back/dist/models/Profile.js new file mode 100644 index 00000000..cc2ad6ff --- /dev/null +++ b/back/dist/models/Profile.js @@ -0,0 +1,119 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +const ProfileSchema = new mongoose_1.default.Schema({ + user: { + type: mongoose_1.default.SchemaTypes.ObjectId, + ref: "User", + }, + company: { + type: String, + required: true, + }, + website: { + type: String, + }, + location: { + type: String, + required: true, + }, + status: { + type: String, + }, + skills: { + type: [String], + }, + bio: { + type: String, + }, + githubusername: { + type: String, + }, + experience: [ + { + title: { + type: String, + required: true, + }, + company: { + type: String, + required: true, + }, + location: { + type: String, + required: true, + }, + from: { + type: Date, + required: true, + }, + to: { + type: Date, + }, + current: { + type: Boolean, + default: false, + }, + description: { + type: String, + }, + }, + ], + education: [ + { + school: { + type: String, + required: true, + }, + degree: { + type: String, + required: true, + }, + fieldofstudy: { + type: String, + }, + from: { + type: Date, + required: true, + }, + to: { + type: Date, + }, + current: { + type: Boolean, + default: false, + }, + description: { + type: String, + }, + }, + ], + social: [ + { + youtube: { + type: String, + }, + twitter: { + type: String, + }, + facebook: { + type: String, + }, + linkedin: { + type: String, + }, + instagram: { + type: String, + }, + }, + ], + date: { + type: Date, + default: Date.now, + }, +}); +exports.default = mongoose_1.default.model("Profile", ProfileSchema); +//# sourceMappingURL=Profile.js.map \ No newline at end of file diff --git a/back/dist/models/Profile.js.map b/back/dist/models/Profile.js.map new file mode 100644 index 00000000..87bc32e7 --- /dev/null +++ b/back/dist/models/Profile.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Profile.js","sourceRoot":"","sources":["../../src/models/Profile.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAGhC,MAAM,aAAa,GAAG,IAAI,kBAAQ,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE;QACJ,IAAI,EAAE,kBAAQ,CAAC,WAAW,CAAC,QAAQ;QACnC,GAAG,EAAE,MAAM;KACZ;IACD,OAAO,EAAE;QACP,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,OAAO,EAAE;QACP,IAAI,EAAE,MAAM;KACb;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;KACb;IACD,MAAM,EAAE;QACN,IAAI,EAAE,CAAC,MAAM,CAAC;KACf;IACD,GAAG,EAAE;QACH,IAAI,EAAE,MAAM;KACb;IACD,cAAc,EAAE;QACd,IAAI,EAAE,MAAM;KACb;IACD,UAAU,EAAE;QACV;YACE,KAAK,EAAE;gBACL,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI;gBACV,QAAQ,EAAE,IAAI;aACf;YACD,EAAE,EAAE;gBACF,IAAI,EAAE,IAAI;aACX;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,KAAK;aACf;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,MAAM;aACb;SACF;KACF;IACD,SAAS,EAAE;QACT;YACE,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,IAAI;aACf;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE,MAAM;aACb;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI;gBACV,QAAQ,EAAE,IAAI;aACf;YACD,EAAE,EAAE;gBACF,IAAI,EAAE,IAAI;aACX;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,KAAK;aACf;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,MAAM;aACb;SACF;KACF;IACD,MAAM,EAAE;QACN;YACE,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM;aACb;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM;aACb;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,MAAM;aACb;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,MAAM;aACb;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,MAAM;aACb;SACF;KACF;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI,CAAC,GAAG;KAClB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAQ,CAAC,KAAK,CAC3B,SAAS,EACT,aAAa,CACd,CAAC"} \ No newline at end of file diff --git a/back/dist/models/User.js b/back/dist/models/User.js new file mode 100644 index 00000000..a4451a84 --- /dev/null +++ b/back/dist/models/User.js @@ -0,0 +1,30 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +const UserSchema = new mongoose_1.default.Schema({ + name: { + type: String, + required: true, + }, + email: { + type: String, + required: true, + unique: true, + }, + password: { + type: String, + required: true, + }, + avatar: { + type: String, + }, + date: { + type: Date, + default: Date.now, + }, +}); +exports.default = mongoose_1.default.model("User", UserSchema); +//# sourceMappingURL=User.js.map \ No newline at end of file diff --git a/back/dist/models/User.js.map b/back/dist/models/User.js.map new file mode 100644 index 00000000..2ead732f --- /dev/null +++ b/back/dist/models/User.js.map @@ -0,0 +1 @@ +{"version":3,"file":"User.js","sourceRoot":"","sources":["../../src/models/User.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAGhC,MAAM,UAAU,GAAG,IAAI,kBAAQ,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE;QACL,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,IAAI;KACb;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;KACb;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI,CAAC,GAAG;KAClB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAQ,CAAC,KAAK,CAA4B,MAAM,EAAE,UAAU,CAAC,CAAC"} \ No newline at end of file