diff --git a/.gitignore b/.gitignore index c00eaef7..7d9af9b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ api/.env api/node_modules/ dist/ node_modules/ -public/img/users/ +public/img/ diff --git a/README.md b/README.md index 5eeaabe0..457128bc 100644 --- a/README.md +++ b/README.md @@ -60,21 +60,34 @@ Yarn : `yarn add vesan` ## Content -Available API Files : -- **UserModel** *(Schema MongoDB)* -- **UserCtrl** *(Controller)* -- **UserRoute** *(Route)* +Available API Files (UNDER CONSTRUCTION) : +- **ArticleModel, ReviewModel, PostModel, CommentModel, UserModel** *(Schemas MongoDB)* +- **ArticleCtrl, ReviewCtrl, PostCtrl, CommentCtrl, UserCtrl** *(Controllers)* +- **ArticleRoute, ReviewRoute, PostRoute, CommentRoute, UserRoute** *(Routes)* -Available Views : +Available Views (UNDER CONSTRUCTION) : - **HomeView** *(Home)* +- **ShopView** *(Shop)* +- **ArticleView** *(Article of Shop)* +- **BlogView** *(Blog)* +- **PostView** *(Post of Blog)* - **ContactView** *(Contact)* - **LoginView** *(Login & Forgot Password)* - **AdminView** *(Admin with the 2 Components)* - **ErrorView** *(Error)* -Available Components : +Available Components (UNDER CONSTRUCTION) : +- **CreateArticle** *(Create Article)* +- **ListArticles** *(Update & Delete Article)* +- **CreateReview** *(Create Review)* +- **ListReviews** *(Update & Delete Review)* +- **CreatePost** *(Create Post)* +- **ListPosts** *(Update & Delete Post)* +- **CreateComment** *(Create Comment)* +- **ListComments** *(Update & Delete Comment)* - **CreateUser** *(Create User)* - **ListUsers** *(Update & Delete User)* + --- ## Documentation diff --git a/api/.env.example b/api/.env.example index 4cb6470d..6fea78cc 100644 --- a/api/.env.example +++ b/api/.env.example @@ -3,6 +3,18 @@ AUTH_ID = "Invalid Id !" AUTH_REQ = "Invalid Request !" +GENERATE_LENGTH = 18 +GENERATE_NUMBERS = true +GENERATE_SYMBOLS = true +GENERATE_STRICT = true + +IMG_URL = "../public/img/" +IMG_EXT = "webp" +IMG_WIDTH = 100 +IMG_HEIGHT = 100 +IMG_FIT = "cover" +IMG_POSITION = "top" + JWT = "your-json-web-token" JWT_DURATION = "72h" @@ -22,7 +34,15 @@ PASS_MIN = 8 USER_EMAIL = "Invalid email !" USER_PASS = "Invalid password !" -# APP +# VESAN + +ARTICLE_CREATED = "Article created !" +ARTICLE_DELETED = "Article deleted !" +ARTICLE_UPDATED = "Article updated !" + +COMMENT_CREATED = "Comment created !" +COMMENT_DELETED = "Comment deleted !" +COMMENT_UPDATED = "Comment updated !" DB = "your-db-username-password-and-host" @@ -31,6 +51,18 @@ MONGO_SUCCESS = "Connection to MongoDB successful!" PORT = 3000 +POST_CREATED = "Post created !" +POST_DELETED = "Post deleted !" +POST_UPDATED = "Post updated !" + +REVIEW_CREATED = "Review created !" +REVIEW_DELETED = "Review deleted !" +REVIEW_UPDATED = "Review updated !" + +ROUTE_ARTICLE = "/api/articles" +ROUTE_COMMENT = "/api/comments" +ROUTE_POST = "/api/posts" +ROUTE_REVIEW = "/api/reviews" ROUTE_USER = "/api/users" USER_CREATED = "User created !" diff --git a/api/app.js b/api/app.js index b352c4cb..b42bce35 100644 --- a/api/app.js +++ b/api/app.js @@ -6,7 +6,12 @@ const helmet = require("helmet"); const sanitize = require("express-mongo-sanitize"); const rateLimit = require("express-rate-limit"); const cors = require("cors"); -const userRoute = require("./route/UserRoute"); + +const articleRoute = require("./route/ArticleRoute"); +const reviewRoute = require("./route/ReviewRoute"); +const postRoute = require("./route/PostRoute"); +const commentRoute = require("./route/CommentRoute"); +const userRoute = require("./route/UserRoute"); require("dotenv").config(); @@ -14,6 +19,7 @@ require("dotenv").config(); * MONGODB */ mongoose + .set('strictQuery', true) .connect(process.env.DB, { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => console.log(process.env.MONGO_SUCCESS)) .catch(() => console.log(process.env.MONGO_FAIL)); @@ -40,6 +46,10 @@ const limiter = rateLimit({ /** * ROUTES */ +app.use(process.env.ROUTE_ARTICLE, articleRoute, limiter); +app.use(process.env.ROUTE_REVIEW, reviewRoute, limiter); +app.use(process.env.ROUTE_POST, postRoute, limiter); +app.use(process.env.ROUTE_COMMENT, commentRoute, limiter); app.use(process.env.ROUTE_USER, userRoute, limiter); module.exports = app; diff --git a/api/controller/ArticleCtrl.js b/api/controller/ArticleCtrl.js new file mode 100644 index 00000000..3189dfac --- /dev/null +++ b/api/controller/ArticleCtrl.js @@ -0,0 +1,143 @@ +"use strict"; + +const formidable = require("formidable"); +const fs = require("fs"); +const nem = require("nemjs"); +const accents = require("remove-accents"); + +const ArticleModel = require("../model/ArticleModel"); + +require("dotenv").config(); + +const form = formidable({ + uploadDir: process.env.IMG_URL + "articles/", + keepExtensions: true +}); + +/** + * GET IMAGE NAME + * @param {string} name + */ +exports.getImgName = (name) => { + + return accents.remove(name).replace(" ", "-").toLowerCase() + "-" + Date.now() + "." + process.env.IMG_EXT; +} + +/** + * GET ARTICLE + * @param {string} name + * @param {string} description + * @param {string} image + * @param {number} price + * @returns + */ +exports.getArticle = (name, description, image, price) => { + + return { + name: name, + description: description, + image: image, + price: price + } +} + +/** + * LIST ARTICLES + * @param {object} req + * @param {object} res + */ +exports.listArticles = (req, res) => { + ArticleModel + .find() + .then((articles) => res.status(200).json(articles)) + .catch((error) => res.status(400).json({ error })); +}; + +//! ****************************** CRUD ****************************** + +/** + * CREATE ARTICLE + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.createArticle = (req, res, next) => { + form.parse(req, (err, fields, files) => { + + if (err) { + next(err); + return; + } + + let image = this.getImgName(fields.name); + nem.createImage(files.image.newFilename, image); + + let article = new ArticleModel(this.getArticle(fields.name, fields.description, image, fields.price)); + + fs.unlink(process.env.IMG_URL + "articles/" + files.image.newFilename, () => { + article + .save() + .then(() => res.status(201).json({ message: process.env.ARTICLE_CREATED })) + .catch((error) => res.status(400).json({ error })); + }); + }) +}; + +/** + * UPDATE ARTICLE + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.updateArticle = (req, res, next) => { + form.parse(req, (err, fields) => { + + if (err) { + next(err); + return; + } + + let image = fields.image; + + if (Object.keys(files).length !== 0) { + image = this.getImgName(fields.name); + nem.createImage(files.image.newFilename, image); + + ArticleModel + .findOne({ _id: req.params.id }) + .then((article) => + fs.unlink(process.env.IMG_URL + "articles/" + article.image, () => { + fs.unlink(process.env.IMG_URL + "articles/" + files.image.newFilename, () => { + console.log("Image ok !"); + }) + }) + ) + } + + let article = this.getArticle(fields.name, fields.description, image, fields.price); + + ArticleModel + .updateOne({ _id: req.params.id }, { ...article, _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.ARTICLE_UPDATED })) + .catch((error) => res.status(400).json({ error })); + }) +}; + +/** + * DELETE ARTICLE + * @param {object} req + * @param {object} res + */ +exports.deleteArticle = (req, res) => { + ArticleModel + .findOne({ _id: req.params.id }) + .then(article => { + fs.unlink(process.env.IMG_URL + "articles/" + article.image, () => { + ArticleModel + .deleteOne({ _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.ARTICLE_DELETED })) + .catch((error) => res.status(400).json({ error })); + }); + }) + .catch(error => res.status(500).json({ error })); +}; diff --git a/api/controller/CommentCtrl.js b/api/controller/CommentCtrl.js new file mode 100644 index 00000000..894e1af0 --- /dev/null +++ b/api/controller/CommentCtrl.js @@ -0,0 +1,79 @@ +"use strict"; + +const formidable = require("formidable"); + +const CommentModel = require("../model/CommentModel"); + +require("dotenv").config(); + +const form = formidable(); + +/** + * LIST COMMENTS + * @param {object} req + * @param {object} res + */ +exports.listComments = (req, res) => { + CommentModel + .find() + .then((comments) => res.status(200).json(comments)) + .catch((error) => res.status(400).json({ error })); +}; + +//! ****************************** CRUD ****************************** + +/** + * CREATE COMMENT + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.createComment = (req, res, next) => { + form.parse(req, (err, fields) => { + + if (err) { + next(err); + return; + } + + let comment = new CommentModel(fields); + + comment + .save() + .then(() => res.status(201).json({ message: process.env.COMMENT_CREATED })) + .catch((error) => res.status(400).json({ error })); + }) +}; + +/** + * UPDATE COMMENT + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.updateComment = (req, res, next) => { + form.parse(req, (err, fields) => { + + if (err) { + next(err); + return; + } + + CommentModel + .updateOne({ _id: req.params.id }, { ...fields, _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.COMMENT_UPDATED })) + .catch((error) => res.status(400).json({ error })); + }) +}; + +/** + * DELETE COMMENT + * @param {object} req + * @param {object} res + */ +exports.deleteComment = (req, res) => { + CommentModel + .deleteOne({ _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.COMMENT_DELETED })) + .catch((error) => res.status(400).json({ error })) +}; diff --git a/api/controller/PostCtrl.js b/api/controller/PostCtrl.js new file mode 100644 index 00000000..044f84f7 --- /dev/null +++ b/api/controller/PostCtrl.js @@ -0,0 +1,141 @@ +"use strict"; + +const formidable = require("formidable"); +const fs = require("fs"); +const nem = require("nemjs"); +const accents = require("remove-accents"); + +const PostModel = require("../model/PostModel"); + +require("dotenv").config(); + +const form = formidable({ + uploadDir: process.env.IMG_URL + "posts/", + keepExtensions: true +}); + +/** + * GET IMAGE NAME + * @param {string} name + */ +exports.getImgName = (name) => { + + return accents.remove(name).toLowerCase() + "-" + Date.now() + "." + process.env.IMG_EXT; +} + +/** + * GET POST + * @param {string} title + * @param {string} text + * @param {string} image + * @returns + */ +exports.getPost = (title, text, image) => { + + return { + title: title, + text: text, + image: image + } +} + +/** + * LIST POSTS + * @param {object} req + * @param {object} res + */ +exports.listPosts = (req, res) => { + PostModel + .find() + .then((posts) => res.status(200).json(posts)) + .catch((error) => res.status(400).json({ error })); +}; + +//! ****************************** CRUD ****************************** + +/** + * CREATE POST + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.createPost = (req, res, next) => { + form.parse(req, (err, fields, files) => { + + if (err) { + next(err); + return; + } + + let image = this.getImgName(fields.title); + nem.createImage(files.image.newFilename, image); + + let post = new PostModel(this.getPost(fields.title, fields.text, image)); + + fs.unlink(process.env.IMG_URL + "posts/" + files.image.newFilename, () => { + post + .save() + .then(() => res.status(201).json({ message: process.env.POST_CREATED })) + .catch((error) => res.status(400).json({ error })); + }); + }) +}; + +/** + * UPDATE POST + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.updatePost = (req, res, next) => { + form.parse(req, (err, fields) => { + + if (err) { + next(err); + return; + } + + let image = fields.image; + + if (Object.keys(files).length !== 0) { + image = this.getImgName(fields.title); + nem.createImage(files.image.newFilename, image); + + PostModel + .findOne({ _id: req.params.id }) + .then((post) => + fs.unlink(process.env.IMG_URL + "posts/" + post.image, () => { + fs.unlink(process.env.IMG_URL + "posts/" + files.image.newFilename, () => { + console.log("Image ok !"); + }) + }) + ) + } + + let post = this.getPost(fields.title, fields.text, image); + + PostModel + .updateOne({ _id: req.params.id }, { ...post, _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.POST_UPDATED })) + .catch((error) => res.status(400).json({ error })); + }) +}; + +/** + * DELETE POST + * @param {object} req + * @param {object} res + */ +exports.deletePost = (req, res) => { + PostModel + .findOne({ _id: req.params.id }) + .then(post => { + fs.unlink(process.env.IMG_URL + "posts/" + post.image, () => { + PostModel + .deleteOne({ _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.POST_DELETED })) + .catch((error) => res.status(400).json({ error })); + }); + }) + .catch(error => res.status(500).json({ error })); +}; diff --git a/api/controller/ReviewCtrl.js b/api/controller/ReviewCtrl.js new file mode 100644 index 00000000..02930d29 --- /dev/null +++ b/api/controller/ReviewCtrl.js @@ -0,0 +1,79 @@ +"use strict"; + +const formidable = require("formidable"); + +const ReviewModel = require("../model/ReviewModel"); + +require("dotenv").config(); + +const form = formidable(); + +/** + * LIST REVIEWS + * @param {object} req + * @param {object} res + */ +exports.listReviews = (req, res) => { + ReviewModel + .find() + .then((reviews) => res.status(200).json(reviews)) + .catch((error) => res.status(400).json({ error })); +}; + +//! ****************************** CRUD ****************************** + +/** + * CREATE REVIEW + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.createReview = (req, res, next) => { + form.parse(req, (err, fields) => { + + if (err) { + next(err); + return; + } + + let review = new ReviewModel(fields); + + review + .save() + .then(() => res.status(201).json({ message: process.env.REVIEW_CREATED })) + .catch((error) => res.status(400).json({ error })); + }) +}; + +/** + * UPDATE REVIEW + * @param {object} req + * @param {object} res + * @param {function} next + */ +exports.updateReview = (req, res, next) => { + form.parse(req, (err, fields) => { + + if (err) { + next(err); + return; + } + + ReviewModel + .updateOne({ _id: req.params.id }, { ...fields, _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.REVIEW_UPDATED })) + .catch((error) => res.status(400).json({ error })); + }) +}; + +/** + * DELETE REVIEW + * @param {object} req + * @param {object} res + */ +exports.deleteReview = (req, res) => { + ReviewModel + .deleteOne({ _id: req.params.id }) + .then(() => res.status(200).json({ message: process.env.REVIEW_DELETED })) + .catch((error) => res.status(400).json({ error })) +}; diff --git a/api/controller/UserCtrl.js b/api/controller/UserCtrl.js index 6bef9db2..dc36ac3d 100644 --- a/api/controller/UserCtrl.js +++ b/api/controller/UserCtrl.js @@ -10,7 +10,7 @@ const UserModel = require("../model/UserModel"); require("dotenv").config(); const form = formidable({ - uploadDir: process.env.IMG_URL, + uploadDir: process.env.IMG_URL + "users/", keepExtensions: true }); @@ -172,7 +172,7 @@ exports.createUser = (req, res, next) => { .then((hash) => { let user = new UserModel(this.getUser(fields.name, fields.email, image, hash)); - fs.unlink(process.env.IMG_URL + files.image.newFilename, () => { + fs.unlink(process.env.IMG_URL + "users/" + files.image.newFilename, () => { user .save() .then(() => res.status(201).json({ message: process.env.USER_CREATED })) @@ -207,8 +207,8 @@ exports.updateUser = (req, res, next) => { UserModel .findOne({ _id: req.params.id }) .then((user) => - fs.unlink(process.env.IMG_URL + user.image, () => { - fs.unlink(process.env.IMG_URL + files.image.newFilename, () => { + fs.unlink(process.env.IMG_URL + "users/" + user.image, () => { + fs.unlink(process.env.IMG_URL + "users/" + files.image.newFilename, () => { console.log("Image ok !"); }) }) @@ -237,7 +237,7 @@ exports.deleteUser = (req, res) => { UserModel .findOne({ _id: req.params.id }) .then(user => { - fs.unlink(process.env.IMG_URL + user.image, () => { + fs.unlink(process.env.IMG_URL + "users/" + user.image, () => { UserModel .deleteOne({ _id: req.params.id }) .then(() => res.status(200).json({ message: process.env.USER_DELETED })) diff --git a/api/model/ArticleModel.js b/api/model/ArticleModel.js new file mode 100644 index 00000000..1d2b94ce --- /dev/null +++ b/api/model/ArticleModel.js @@ -0,0 +1,35 @@ +"use strict"; + +const mongoose = require("mongoose"); +const uniqueValidator = require("mongoose-unique-validator"); + +const ArticleModel = mongoose.Schema( + { + name: { + type: String, + required: true, + unique: true + }, + description: { + type: String, + required: true, + unique: true + }, + image: { + type: String, + required: true, + unique: true + }, + price: { + type: Number, + required: true + } + }, + { + versionKey: false + } +); + +ArticleModel.plugin(uniqueValidator); + +module.exports = mongoose.model("Article", ArticleModel); diff --git a/api/model/CommentModel.js b/api/model/CommentModel.js new file mode 100644 index 00000000..116ba22e --- /dev/null +++ b/api/model/CommentModel.js @@ -0,0 +1,28 @@ +"use strict"; + +const mongoose = require("mongoose"); +const uniqueValidator = require("mongoose-unique-validator"); + +const CommentModel = mongoose.Schema( + { + text: { + type: String, + required: true + }, + post: { + type: String, + required: true + }, + user: { + type: String, + required: true + } + }, + { + versionKey: false + } +); + +CommentModel.plugin(uniqueValidator); + +module.exports = mongoose.model("Comment", CommentModel); diff --git a/api/model/PostModel.js b/api/model/PostModel.js new file mode 100644 index 00000000..c1f908ad --- /dev/null +++ b/api/model/PostModel.js @@ -0,0 +1,35 @@ +"use strict"; + +const mongoose = require("mongoose"); +const uniqueValidator = require("mongoose-unique-validator"); + +const PostModel = mongoose.Schema( + { + title: { + type: String, + required: true, + unique: true + }, + text: { + type: String, + required: true, + unique: true + }, + image: { + type: String, + required: true, + unique: true + }, + author: { + type: String, + required: true + } + }, + { + versionKey: false + } +); + +PostModel.plugin(uniqueValidator); + +module.exports = mongoose.model("Post", PostModel); diff --git a/api/model/ReviewModel.js b/api/model/ReviewModel.js new file mode 100644 index 00000000..5194c9e7 --- /dev/null +++ b/api/model/ReviewModel.js @@ -0,0 +1,32 @@ +"use strict"; + +const mongoose = require("mongoose"); +const uniqueValidator = require("mongoose-unique-validator"); + +const ReviewModel = mongoose.Schema( + { + text: { + type: String, + required: true + }, + score: { + type: Number, + required: true + }, + article: { + type: String, + required: true + }, + user: { + type: String, + required: true + } + }, + { + versionKey: false + } +); + +ReviewModel.plugin(uniqueValidator); + +module.exports = mongoose.model("Review", ReviewModel); diff --git a/api/package-lock.json b/api/package-lock.json index cc7a54a9..9dfd2540 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -17,7 +17,7 @@ "helmet": "^5.0.2", "mongoose": "^6.2.1", "mongoose-unique-validator": "^3.0.0", - "nemjs": "^0.5.1", + "nemjs": "^0.6.0", "remove-accents": "^0.4.4" } }, @@ -2348,9 +2348,9 @@ } }, "node_modules/nemjs": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/nemjs/-/nemjs-0.5.1.tgz", - "integrity": "sha512-kt9tk1OU9C8B8RYtwnL/Y5ZMV99ozfOUVeLad2BJCjeLM8CD7qvMNLzfUTYWI2PfQVF7kOfGxTxcUkG97vpIpA==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/nemjs/-/nemjs-0.6.0.tgz", + "integrity": "sha512-UHxTu4SG/zixbiTm5h724XY8D17CMtQqD5KuF0mEdKMJOyiMUCgRYdNM3qmd+nbvsttZJGKkkLRwUeT//2ClbQ==", "dependencies": { "bcrypt": "^5.1.0", "dotenv": "^16.0.3", @@ -2359,7 +2359,8 @@ "jsonwebtoken": "^9.0.0", "nodemailer": "^6.8.0", "password-validator": "^5.3.0", - "sharp": "^0.31.3" + "sharp": "^0.31.3", + "valid-url": "^1.0.9" }, "engines": { "node": ">=10.0.0" @@ -3060,6 +3061,11 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/valid-url": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz", + "integrity": "sha512-QQDsV8OnSf5Uc30CKSwG9lnhMPe6exHtTXLRYX8uMwKENy640pU+2BgBL0LRbDh/eYRahNCS7aewCx0wf3NYVA==" + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -4969,9 +4975,9 @@ "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, "nemjs": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/nemjs/-/nemjs-0.5.1.tgz", - "integrity": "sha512-kt9tk1OU9C8B8RYtwnL/Y5ZMV99ozfOUVeLad2BJCjeLM8CD7qvMNLzfUTYWI2PfQVF7kOfGxTxcUkG97vpIpA==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/nemjs/-/nemjs-0.6.0.tgz", + "integrity": "sha512-UHxTu4SG/zixbiTm5h724XY8D17CMtQqD5KuF0mEdKMJOyiMUCgRYdNM3qmd+nbvsttZJGKkkLRwUeT//2ClbQ==", "requires": { "bcrypt": "^5.1.0", "dotenv": "^16.0.3", @@ -4980,7 +4986,8 @@ "jsonwebtoken": "^9.0.0", "nodemailer": "^6.8.0", "password-validator": "^5.3.0", - "sharp": "^0.31.3" + "sharp": "^0.31.3", + "valid-url": "^1.0.9" } }, "node-abi": { @@ -5493,6 +5500,11 @@ "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", "optional": true }, + "valid-url": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz", + "integrity": "sha512-QQDsV8OnSf5Uc30CKSwG9lnhMPe6exHtTXLRYX8uMwKENy640pU+2BgBL0LRbDh/eYRahNCS7aewCx0wf3NYVA==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/api/package.json b/api/package.json index 51dad09f..cfbfbfc4 100644 --- a/api/package.json +++ b/api/package.json @@ -32,7 +32,7 @@ "helmet": "^5.0.2", "mongoose": "^6.2.1", "mongoose-unique-validator": "^3.0.0", - "nemjs": "^0.5.1", + "nemjs": "^0.6.0", "remove-accents": "^0.4.4" }, "author": { diff --git a/api/route/ArticleRoute.js b/api/route/ArticleRoute.js new file mode 100644 index 00000000..75d5597c --- /dev/null +++ b/api/route/ArticleRoute.js @@ -0,0 +1,14 @@ +"use strict"; + +const express = require("express"); +const router = express.Router(); +const nem = require("nemjs"); + +const ArticleCtrl = require("../controller/ArticleCtrl"); + +router.get("/", ArticleCtrl.listArticles); +router.post("/", nem.checkAuth, ArticleCtrl.createArticle); +router.put("/:id", nem.checkAuth, ArticleCtrl.updateArticle); +router.delete("/:id", nem.checkAuth, ArticleCtrl.deleteArticle); + +module.exports = router; diff --git a/api/route/CommentRoute.js b/api/route/CommentRoute.js new file mode 100644 index 00000000..894dcc2c --- /dev/null +++ b/api/route/CommentRoute.js @@ -0,0 +1,14 @@ +"use strict"; + +const express = require("express"); +const router = express.Router(); +const nem = require("nemjs"); + +const CommentCtrl = require("../controller/CommentCtrl"); + +router.get("/", CommentCtrl.listComments); +router.post("/", nem.checkAuth, CommentCtrl.createComment); +router.put("/:id", nem.checkAuth, CommentCtrl.updateComment); +router.delete("/:id", nem.checkAuth, CommentCtrl.deleteComment); + +module.exports = router; diff --git a/api/route/PostRoute.js b/api/route/PostRoute.js new file mode 100644 index 00000000..a996bd4c --- /dev/null +++ b/api/route/PostRoute.js @@ -0,0 +1,14 @@ +"use strict"; + +const express = require("express"); +const router = express.Router(); +const nem = require("nemjs"); + +const PostCtrl = require("../controller/PostCtrl"); + +router.get("/", PostCtrl.listPosts); +router.post("/", nem.checkAuth, PostCtrl.createPost); +router.put("/:id", nem.checkAuth, PostCtrl.updatePost); +router.delete("/:id", nem.checkAuth, PostCtrl.deletePost); + +module.exports = router; diff --git a/api/route/ReviewRoute.js b/api/route/ReviewRoute.js new file mode 100644 index 00000000..c791d529 --- /dev/null +++ b/api/route/ReviewRoute.js @@ -0,0 +1,14 @@ +"use strict"; + +const express = require("express"); +const router = express.Router(); +const nem = require("nemjs"); + +const ReviewCtrl = require("../controller/ReviewCtrl"); + +router.get("/", ReviewCtrl.listReviews); +router.post("/", nem.checkAuth, ReviewCtrl.createReview); +router.put("/:id", nem.checkAuth, ReviewCtrl.updateReview); +router.delete("/:id", nem.checkAuth, ReviewCtrl.deleteReview); + +module.exports = router; diff --git a/api/route/UserRoute.js b/api/route/UserRoute.js index bd664080..41b892c4 100644 --- a/api/route/UserRoute.js +++ b/api/route/UserRoute.js @@ -1,9 +1,10 @@ "use strict"; -const express = require("express"); -const router = express.Router(); -const nem = require("nemjs"); -const UserCtrl = require("../controller/UserCtrl"); +const express = require("express"); +const router = express.Router(); +const nem = require("nemjs"); + +const UserCtrl = require("../controller/UserCtrl"); router.get("/", nem.checkAuth, UserCtrl.listUsers); router.post("/login", UserCtrl.loginUser); diff --git a/constants.js b/constants.js index 8c32a58c..005d0a3b 100644 --- a/constants.js +++ b/constants.js @@ -22,7 +22,7 @@ export default { TOKEN : JSON.parse(localStorage.getItem("userToken")), USER_ID : JSON.parse(localStorage.getItem("userId")), - /* APP */ + /* VESAN */ FORGOT_CONFIRM : "Do you confirm sending a new password ?", FORGOT_SUBJECT : "New Password", diff --git a/package-lock.json b/package-lock.json index 77a76f3c..2b32a5bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,20 @@ { "name": "vesan", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vesan", - "version": "0.1.1", + "version": "0.1.2", "license": "Apache-2.0 License", "dependencies": { "@fortawesome/fontawesome-free": "^6.2.1", "animadio": "^5.6.0", "core-js": "^3.8.3", - "servidio": "^0.4.0", + "servidio": "^0.4.1", "vue": "^3.2.45", - "vue-elt": "^0.5.2", + "vue-elt": "^0.6.0", "vue-router": "^4.1.6" }, "devDependencies": { @@ -9751,9 +9751,9 @@ } }, "node_modules/servidio": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/servidio/-/servidio-0.4.0.tgz", - "integrity": "sha512-YgE91d/FqdYotVjIfzYHm7XpZtP3G5faca1eW+VgRILPsRbUOfW7vjZLR06FkVukVWzy3PbYIiwNLQ+6CaSgHQ==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/servidio/-/servidio-0.4.1.tgz", + "integrity": "sha512-4dMOtmO4VOU4Dp84vars2QUm6H0DssqKZzPl8FUTFCU0kDH4auaUsyk2SH68Srb2IFfJInRrQRj8HHrXpoJlUw==", "dependencies": { "axios": "^1.2.0", "email-validator": "^2.0.4", @@ -10659,9 +10659,9 @@ } }, "node_modules/vue-elt": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/vue-elt/-/vue-elt-0.5.2.tgz", - "integrity": "sha512-bUt9w9XPEeVpV4PtduhNCQEk7JOfrPZFxyl84TNyvft/5TKeaVAUYnCtGjVlnrjTErqcKvU/lMAMz0YQS8JPYA==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/vue-elt/-/vue-elt-0.6.0.tgz", + "integrity": "sha512-YmVbXtM6oS0HlL4bXpJwKJ+0rkmuW557iEZxhuqxtyMxH4eSAqtQaG1OhbgzQSbFEcYo23+8IgaWY274ywgoeQ==", "dependencies": { "@fortawesome/fontawesome-free": "^6.2.1", "animadio": "^5.6.0" @@ -18925,9 +18925,9 @@ } }, "servidio": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/servidio/-/servidio-0.4.0.tgz", - "integrity": "sha512-YgE91d/FqdYotVjIfzYHm7XpZtP3G5faca1eW+VgRILPsRbUOfW7vjZLR06FkVukVWzy3PbYIiwNLQ+6CaSgHQ==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/servidio/-/servidio-0.4.1.tgz", + "integrity": "sha512-4dMOtmO4VOU4Dp84vars2QUm6H0DssqKZzPl8FUTFCU0kDH4auaUsyk2SH68Srb2IFfJInRrQRj8HHrXpoJlUw==", "requires": { "axios": "^1.2.0", "email-validator": "^2.0.4", @@ -19616,9 +19616,9 @@ } }, "vue-elt": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/vue-elt/-/vue-elt-0.5.2.tgz", - "integrity": "sha512-bUt9w9XPEeVpV4PtduhNCQEk7JOfrPZFxyl84TNyvft/5TKeaVAUYnCtGjVlnrjTErqcKvU/lMAMz0YQS8JPYA==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/vue-elt/-/vue-elt-0.6.0.tgz", + "integrity": "sha512-YmVbXtM6oS0HlL4bXpJwKJ+0rkmuW557iEZxhuqxtyMxH4eSAqtQaG1OhbgzQSbFEcYo23+8IgaWY274ywgoeQ==", "requires": { "@fortawesome/fontawesome-free": "^6.2.1", "animadio": "^5.6.0" diff --git a/package.json b/package.json index 7d499f4e..1f850b67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vesan", - "version": "0.1.2", + "version": "0.2.0", "description": "CMS with Vue-Elt, Servidio, Animadio & NemJS", "keywords": [ "cms", @@ -28,9 +28,9 @@ "@fortawesome/fontawesome-free": "^6.2.1", "animadio": "^5.6.0", "core-js": "^3.8.3", - "servidio": "^0.4.0", + "servidio": "^0.4.1", "vue": "^3.2.45", - "vue-elt": "^0.5.2", + "vue-elt": "^0.6.0", "vue-router": "^4.1.6" }, "devDependencies": { diff --git a/src/App.vue b/src/App.vue index edfc7f4a..a29408d5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,7 @@