1
1
const mongoose = require ( 'mongoose' ) ;
2
2
const { isURL } = require ( 'validator' ) ;
3
3
const uniqueValidator = require ( 'mongoose-unique-validator' ) ;
4
+ const { ALLOWED_VIDEO_HOST_WHITELIST } = require ( '../utils/config' ) ;
4
5
5
6
const softwareSchema = new mongoose . Schema (
6
7
{
@@ -26,6 +27,12 @@ const softwareSchema = new mongoose.Schema(
26
27
trim : true ,
27
28
default : '0.0.0' ,
28
29
} ,
30
+ shortDescription : {
31
+ type : String ,
32
+ trim : true ,
33
+ maxlength : 100 ,
34
+ required : [ true , 'Software short description is required' ] ,
35
+ } ,
29
36
description : {
30
37
type : String ,
31
38
trim : true ,
@@ -34,9 +41,10 @@ const softwareSchema = new mongoose.Schema(
34
41
homePage : {
35
42
type : String ,
36
43
validate : [
37
- ( value ) => isURL ( value , {
38
- protocols : [ 'http' , 'https' ] ,
39
- } ) ,
44
+ ( value ) =>
45
+ isURL ( value , {
46
+ protocols : [ 'http' , 'https' ] ,
47
+ } ) ,
40
48
'A valid url is required' ,
41
49
] ,
42
50
required : [ true , 'Software homepage url is required' ] ,
@@ -51,6 +59,12 @@ const softwareSchema = new mongoose.Schema(
51
59
type : Boolean ,
52
60
required : true ,
53
61
} ,
62
+ pricing : {
63
+ type : String ,
64
+ trim : true ,
65
+ lowercase : true ,
66
+ required : [ true , 'Software pricing is required' ] ,
67
+ } ,
54
68
buildOn : {
55
69
type : [
56
70
{
@@ -64,21 +78,45 @@ const softwareSchema = new mongoose.Schema(
64
78
developedBy : {
65
79
type : [
66
80
{
67
- type : mongoose . Schema . Types . ObjectId ,
68
- ref : 'User' ,
81
+ type : String ,
82
+ trim : true ,
83
+ lowercase : true ,
69
84
} ,
70
85
] ,
71
86
default : [ ] ,
72
87
} ,
73
88
maintainedBy : {
74
89
type : [
75
90
{
76
- type : mongoose . Schema . Types . ObjectId ,
77
- ref : 'User' ,
91
+ type : String ,
92
+ trim : true ,
93
+ lowercase : true ,
78
94
} ,
79
95
] ,
80
96
default : [ ] ,
81
97
} ,
98
+ videoLink : {
99
+ type : String ,
100
+ validate : [
101
+ ( value ) => {
102
+ if ( value ) {
103
+ return isURL ( value , {
104
+ protocols : [ 'http' , 'https' ] ,
105
+ host_whitelist : ALLOWED_VIDEO_HOST_WHITELIST ,
106
+ } ) ;
107
+ }
108
+ return true ;
109
+ } ,
110
+ 'A valid video url is required (Only youtube.com or vimeo.com are supported)' ,
111
+ ] ,
112
+ default : '' ,
113
+ } ,
114
+ twitterUsername : {
115
+ type : String ,
116
+ trim : true ,
117
+ lowercase : true ,
118
+ default : '' ,
119
+ } ,
82
120
query : {
83
121
isEnabled : {
84
122
type : Boolean ,
@@ -87,19 +125,21 @@ const softwareSchema = new mongoose.Schema(
87
125
updateUrl : {
88
126
type : String ,
89
127
validate : [
90
- ( value ) => isURL ( value , {
91
- protocols : [ 'http' , 'https' ] ,
92
- } ) || value === '' ,
128
+ ( value ) =>
129
+ isURL ( value , {
130
+ protocols : [ 'http' , 'https' ] ,
131
+ } ) || value === '' ,
93
132
'A valid update url is required' ,
94
133
] ,
95
134
default : '' ,
96
135
} ,
97
136
downloadUrl : {
98
137
type : String ,
99
138
validate : [
100
- ( value ) => isURL ( value , {
101
- protocols : [ 'http' , 'https' , 'ftp' ] ,
102
- } ) || value === '' ,
139
+ ( value ) =>
140
+ isURL ( value , {
141
+ protocols : [ 'http' , 'https' , 'ftp' ] ,
142
+ } ) || value === '' ,
103
143
'A valid download url is required' ,
104
144
] ,
105
145
default : '' ,
0 commit comments