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