-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.js
More file actions
57 lines (55 loc) · 1.95 KB
/
schema.js
File metadata and controls
57 lines (55 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Joi = require("joi");
const review = require("./models/review");
// Schema to validate 'listing' data server-side to prevent users from submitting undesired data
// via external tools like Hoppscotch, Postman, Thunder Client, etc.
module.exports.listingSchema = Joi.object({
listing: Joi.object({
title: Joi.string().required(),
description: Joi.string().required(),
location: Joi.string().required(),
country: Joi.string().required(),
price: Joi.number().required().min(0),
// image: Joi.object({
// url: Joi.string().allow("", null), // Allows an empty string or null for optional image URLs
// }),
//* Newer version of verifying the images (by chatgpt)
image: Joi.any(), // or remove it completely from validation if you're not validating it at this stage
categories: Joi.array()
.items(
Joi.string().valid(
"pools",
"trending",
"farms",
"top cities",
"camping",
"castles",
"skating",
"hotels",
"beach",
"igloos",
"mountains",
"rooms",
"ski-in/out",
"boats",
"creative spaces",
"caravans",
"arctic",
"nature",
"golfing",
"urban",
"cabins",
"snowboarding",
"luxury",
"cozy"
)
)
.default([]),
}).required(),
});
// Schema to validate 'review' data
module.exports.reviewSchema = Joi.object({
review: Joi.object({
rating: Joi.number().required().min(1).max(5),
comment: Joi.string().required(),
}).required(),
});