-
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
0 parents
commit 7dc34fe
Showing
76 changed files
with
14,485 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,13 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
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,43 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# compiled output | ||
/dist | ||
/tmp | ||
/out-tsc | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# misc | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
/libpeerconnection.log | ||
npm-debug.log | ||
yarn-error.log | ||
testem.log | ||
/typings | ||
|
||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
|
||
backend/images | ||
backend/angular |
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,27 @@ | ||
# MeanCourse | ||
|
||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.0.1. | ||
|
||
## Development server | ||
|
||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. | ||
|
||
## Code scaffolding | ||
|
||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. | ||
|
||
## Build | ||
|
||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. | ||
|
||
## Running unit tests | ||
|
||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). | ||
|
||
## Running end-to-end tests | ||
|
||
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). | ||
|
||
## Further help | ||
|
||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). |
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,128 @@ | ||
{ | ||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", | ||
"version": 1, | ||
"newProjectRoot": "projects", | ||
"projects": { | ||
"mean-course": { | ||
"root": "", | ||
"sourceRoot": "src", | ||
"projectType": "application", | ||
"prefix": "app", | ||
"schematics": {}, | ||
"architect": { | ||
"build": { | ||
"builder": "@angular-devkit/build-angular:browser", | ||
"options": { | ||
"outputPath": "backend/angular", | ||
"index": "src/index.html", | ||
"main": "src/main.ts", | ||
"polyfills": "src/polyfills.ts", | ||
"tsConfig": "src/tsconfig.app.json", | ||
"assets": [ | ||
"src/favicon.ico", | ||
"src/assets" | ||
], | ||
"styles": [ | ||
{ | ||
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" | ||
}, | ||
"src/styles.css" | ||
], | ||
"scripts": [] | ||
}, | ||
"configurations": { | ||
"production": { | ||
"fileReplacements": [ | ||
{ | ||
"replace": "src/environments/environment.ts", | ||
"with": "src/environments/environment.prod.ts" | ||
} | ||
], | ||
"optimization": true, | ||
"outputHashing": "all", | ||
"sourceMap": false, | ||
"extractCss": true, | ||
"namedChunks": false, | ||
"aot": true, | ||
"extractLicenses": true, | ||
"vendorChunk": false, | ||
"buildOptimizer": true | ||
} | ||
} | ||
}, | ||
"serve": { | ||
"builder": "@angular-devkit/build-angular:dev-server", | ||
"options": { | ||
"browserTarget": "mean-course:build" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"browserTarget": "mean-course:build:production" | ||
} | ||
} | ||
}, | ||
"extract-i18n": { | ||
"builder": "@angular-devkit/build-angular:extract-i18n", | ||
"options": { | ||
"browserTarget": "mean-course:build" | ||
} | ||
}, | ||
"test": { | ||
"builder": "@angular-devkit/build-angular:karma", | ||
"options": { | ||
"main": "src/test.ts", | ||
"polyfills": "src/polyfills.ts", | ||
"tsConfig": "src/tsconfig.spec.json", | ||
"karmaConfig": "src/karma.conf.js", | ||
"styles": [ | ||
{ | ||
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" | ||
}, | ||
"src/styles.css" | ||
], | ||
"scripts": [], | ||
"assets": [ | ||
"src/favicon.ico", | ||
"src/assets" | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"builder": "@angular-devkit/build-angular:tslint", | ||
"options": { | ||
"tsConfig": [ | ||
"src/tsconfig.app.json", | ||
"src/tsconfig.spec.json" | ||
], | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"mean-course-e2e": { | ||
"root": "e2e/", | ||
"projectType": "application", | ||
"architect": { | ||
"e2e": { | ||
"builder": "@angular-devkit/build-angular:protractor", | ||
"options": { | ||
"protractorConfig": "e2e/protractor.conf.js", | ||
"devServerTarget": "mean-course:serve" | ||
} | ||
}, | ||
"lint": { | ||
"builder": "@angular-devkit/build-angular:tslint", | ||
"options": { | ||
"tsConfig": "e2e/tsconfig.e2e.json", | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"defaultProject": "mean-course" | ||
} |
Binary file not shown.
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,48 @@ | ||
const path = require("path"); | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const mongoose = require("mongoose"); | ||
|
||
const postsRoutes = require("./routes/posts"); | ||
const userRoutes = require("./routes/user"); | ||
|
||
const app = express(); | ||
|
||
mongoose | ||
.connect( | ||
"mongodb+srv://max:" + | ||
process.env.MONGO_ATLAS_PW + | ||
"@cluster0-ntrwp.mongodb.net/node-angular" | ||
) | ||
.then(() => { | ||
console.log("Connected to database!"); | ||
}) | ||
.catch(() => { | ||
console.log("Connection failed!"); | ||
}); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use("/images", express.static(path.join(__dirname, "images"))); | ||
app.use("/", express.static(path.join(__dirname, "angular"))); | ||
|
||
// app.use((req, res, next) => { | ||
// res.setHeader("Access-Control-Allow-Origin", "*"); | ||
// res.setHeader( | ||
// "Access-Control-Allow-Headers", | ||
// "Origin, X-Requested-With, Content-Type, Accept, Authorization" | ||
// ); | ||
// res.setHeader( | ||
// "Access-Control-Allow-Methods", | ||
// "GET, POST, PATCH, PUT, DELETE, OPTIONS" | ||
// ); | ||
// next(); | ||
// }); | ||
|
||
app.use("/api/posts", postsRoutes); | ||
app.use("/api/user", userRoutes); | ||
app.use((req, res, next) => { | ||
res.sendFile(path.join(__dirname, "angular", "index.html")); | ||
}); | ||
|
||
module.exports = app; |
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,115 @@ | ||
const Post = require("../models/post"); | ||
|
||
exports.createPost = (req, res, next) => { | ||
const url = req.protocol + "://" + req.get("host"); | ||
const post = new Post({ | ||
title: req.body.title, | ||
content: req.body.content, | ||
imagePath: url + "/images/" + req.file.filename, | ||
creator: req.userData.userId | ||
}); | ||
post | ||
.save() | ||
.then(createdPost => { | ||
res.status(201).json({ | ||
message: "Post added successfully", | ||
post: { | ||
...createdPost, | ||
id: createdPost._id | ||
} | ||
}); | ||
}) | ||
.catch(error => { | ||
res.status(500).json({ | ||
message: "Creating a post failed!" | ||
}); | ||
}); | ||
}; | ||
|
||
exports.updatePost = (req, res, next) => { | ||
let imagePath = req.body.imagePath; | ||
if (req.file) { | ||
const url = req.protocol + "://" + req.get("host"); | ||
imagePath = url + "/images/" + req.file.filename; | ||
} | ||
const post = new Post({ | ||
_id: req.body.id, | ||
title: req.body.title, | ||
content: req.body.content, | ||
imagePath: imagePath, | ||
creator: req.userData.userId | ||
}); | ||
Post.updateOne({ _id: req.params.id, creator: req.userData.userId }, post) | ||
.then(result => { | ||
if (result.n > 0) { | ||
res.status(200).json({ message: "Update successful!" }); | ||
} else { | ||
res.status(401).json({ message: "Not authorized!" }); | ||
} | ||
}) | ||
.catch(error => { | ||
res.status(500).json({ | ||
message: "Couldn't udpate post!" | ||
}); | ||
}); | ||
}; | ||
|
||
exports.getPosts = (req, res, next) => { | ||
const pageSize = +req.query.pagesize; | ||
const currentPage = +req.query.page; | ||
const postQuery = Post.find(); | ||
let fetchedPosts; | ||
if (pageSize && currentPage) { | ||
postQuery.skip(pageSize * (currentPage - 1)).limit(pageSize); | ||
} | ||
postQuery | ||
.then(documents => { | ||
fetchedPosts = documents; | ||
return Post.count(); | ||
}) | ||
.then(count => { | ||
res.status(200).json({ | ||
message: "Posts fetched successfully!", | ||
posts: fetchedPosts, | ||
maxPosts: count | ||
}); | ||
}) | ||
.catch(error => { | ||
res.status(500).json({ | ||
message: "Fetching posts failed!" | ||
}); | ||
}); | ||
}; | ||
|
||
exports.getPost = (req, res, next) => { | ||
Post.findById(req.params.id) | ||
.then(post => { | ||
if (post) { | ||
res.status(200).json(post); | ||
} else { | ||
res.status(404).json({ message: "Post not found!" }); | ||
} | ||
}) | ||
.catch(error => { | ||
res.status(500).json({ | ||
message: "Fetching post failed!" | ||
}); | ||
}); | ||
}; | ||
|
||
exports.deletePost = (req, res, next) => { | ||
Post.deleteOne({ _id: req.params.id, creator: req.userData.userId }) | ||
.then(result => { | ||
console.log(result); | ||
if (result.n > 0) { | ||
res.status(200).json({ message: "Deletion successful!" }); | ||
} else { | ||
res.status(401).json({ message: "Not authorized!" }); | ||
} | ||
}) | ||
.catch(error => { | ||
res.status(500).json({ | ||
message: "Deleting posts failed!" | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.