validation 1
This commit is contained in:
@@ -4,17 +4,17 @@ const restaurantSchema = mongoose.Schema({
|
|||||||
_id: mongoose.Types.ObjectId,
|
_id: mongoose.Types.ObjectId,
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 128,
|
maxlength: 64,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
city: {
|
city: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 128,
|
maxlength: 64,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
adress: {
|
adress: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 128,
|
maxlength: 64,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
location: {
|
location: {
|
||||||
@@ -28,22 +28,52 @@ const restaurantSchema = mongoose.Schema({
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
placesId: String,
|
maxlength: 64,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
placesId: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 128
|
||||||
|
},
|
||||||
imgUrl: {
|
imgUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
|
maxlength: 128
|
||||||
},
|
},
|
||||||
workingHours: {
|
workingHours: {
|
||||||
pn: String,
|
pn: {
|
||||||
wt: String,
|
type: String,
|
||||||
sr: String,
|
maxlength: 24
|
||||||
cz: String,
|
},
|
||||||
pt: String,
|
wt: {
|
||||||
sb: String,
|
type: String,
|
||||||
nd: String,
|
maxlength: 24
|
||||||
|
},
|
||||||
|
sr: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
|
},
|
||||||
|
cz: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
|
},
|
||||||
|
pt: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
|
},
|
||||||
|
sb: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
|
},
|
||||||
|
nd: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
|
},
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
|
maxlength: 400
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
cardPayments: Boolean,
|
cardPayments: Boolean,
|
||||||
@@ -55,25 +85,43 @@ const restaurantSchema = mongoose.Schema({
|
|||||||
delivery: Boolean,
|
delivery: Boolean,
|
||||||
},
|
},
|
||||||
links: {
|
links: {
|
||||||
facebook: String,
|
facebook: {
|
||||||
instagram: String,
|
type: String,
|
||||||
www: String,
|
maxlength: 128
|
||||||
|
},
|
||||||
|
instagram: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 128
|
||||||
|
},
|
||||||
|
www: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 128
|
||||||
|
},
|
||||||
|
},
|
||||||
|
phone: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
},
|
},
|
||||||
phone: String,
|
|
||||||
hidden: Boolean,
|
hidden: Boolean,
|
||||||
subscriptionActive: Boolean,
|
subscriptionActive: Boolean,
|
||||||
subscriptionStarted: Date,
|
subscriptionStarted: Date,
|
||||||
subscriptionDue: Date,
|
subscriptionDue: Date,
|
||||||
indexed: Date,
|
indexed: Date,
|
||||||
categories: [String],
|
categories: [String],
|
||||||
lunchHours: String,
|
lunchHours: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 24
|
||||||
|
},
|
||||||
lunchMenu: [
|
lunchMenu: [
|
||||||
{
|
{
|
||||||
lunchSetName: String,
|
lunchSetName: {
|
||||||
lunchSetPrice: String,
|
type: String,
|
||||||
|
maxlength: 30
|
||||||
|
},
|
||||||
|
lunchSetPrice: Number,
|
||||||
lunchSetDishes: [{
|
lunchSetDishes: [{
|
||||||
dishId: mongoose.Types.ObjectId,
|
dishId: mongoose.Types.ObjectId,
|
||||||
quantity: String
|
quantity: Number
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const {
|
|||||||
checkPassword,
|
checkPassword,
|
||||||
} = require("../services/services.js");
|
} = require("../services/services.js");
|
||||||
const Restaurant = require("../models/restaurant.js");
|
const Restaurant = require("../models/restaurant.js");
|
||||||
|
const { validateRestaurant } = require("../services/validations.js");
|
||||||
|
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ router.post("/", async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const token = req.headers["x-auth-token"];
|
const token = req.headers["x-auth-token"];
|
||||||
const user = validateUserToken(token);
|
const user = validateUserToken(token);
|
||||||
|
validateRestaurant(req.body);
|
||||||
const restaurant = await createRestaurant(req.body).catch((err) => {
|
const restaurant = await createRestaurant(req.body).catch((err) => {
|
||||||
throw newError("Nie udało się zapisać zdjęcia.", 500);
|
throw newError("Nie udało się zapisać zdjęcia.", 500);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,15 +36,24 @@ const validateRegister = function(requestBody){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const validateSearch = function(string){
|
const validateSearch = function(string){
|
||||||
const valid = validator.isLength(string, { max: 64 }) && validator.isAlphanumeric(string)
|
const decodedString = decodeURI(string);
|
||||||
|
const valid = validator.isLength(decodedString, { max: 64 })
|
||||||
if(!valid){
|
if(!valid){
|
||||||
throw newError("Niepoprawne zapytanie", 400)
|
throw newError("Niepoprawne zapytanie", 400)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateRestaurant = function(requestBody){
|
||||||
|
const name = validator.isLength(requestBody.name, { max: 64 })
|
||||||
|
const city = validator.isLength(requestBody.city, { max: 64 })
|
||||||
|
const adress = validator.isLength(requestBody.adress, { max: 64 })
|
||||||
|
const imgURL = validator.isURL(requestBody.imgUrl) && validator.contains(requestBody.imgUrl, "https://menuicdn.fra1.digitaloceanspaces.com/")
|
||||||
|
}
|
||||||
|
|
||||||
// EXPORTS
|
// EXPORTS
|
||||||
|
|
||||||
exports.validateLogin = validateLogin;
|
exports.validateLogin = validateLogin;
|
||||||
exports.validateRegister = validateRegister;
|
exports.validateRegister = validateRegister;
|
||||||
exports.validatePassword = validatePassword;
|
exports.validatePassword = validatePassword;
|
||||||
exports.validateSearch = validateSearch;
|
exports.validateSearch = validateSearch;
|
||||||
|
exports.validateRestaurant = validateRestaurant;
|
||||||
Reference in New Issue
Block a user