Skip to content

Commit e0eba38

Browse files
Merge pull request #212 from learnsoftwaredevelopment/improve-software-model
Improved `software` model with `shortDescription`, `pricing`, `videoLink` and `twitterUsername` fields
2 parents c83bc19 + 967a532 commit e0eba38

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

models/software.js

+33
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const softwareSchema = new mongoose.Schema(
2626
trim: true,
2727
default: '0.0.0',
2828
},
29+
shortDescription: {
30+
type: String,
31+
trim: true,
32+
maxlength: 100,
33+
required: [true, 'Software short description is required'],
34+
},
2935
description: {
3036
type: String,
3137
trim: true,
@@ -52,6 +58,12 @@ const softwareSchema = new mongoose.Schema(
5258
type: Boolean,
5359
required: true,
5460
},
61+
pricing: {
62+
type: String,
63+
trim: true,
64+
lowercase: true,
65+
required: [true, 'Software pricing is required'],
66+
},
5567
buildOn: {
5668
type: [
5769
{
@@ -82,6 +94,27 @@ const softwareSchema = new mongoose.Schema(
8294
],
8395
default: [],
8496
},
97+
videoLink: {
98+
type: String,
99+
validate: [
100+
(value) => {
101+
if (value) {
102+
return isURL(value, {
103+
protocols: ['http', 'https'],
104+
host_whitelist: ['youtube.com', 'vimeo.com'],
105+
});
106+
}
107+
return true;
108+
},
109+
'A valid video url is required (Only youtube.com or vimeo.com are supported)',
110+
],
111+
default: '',
112+
},
113+
twitterUsername: {
114+
type: String,
115+
trim: true,
116+
lowercase: true,
117+
},
85118
query: {
86119
isEnabled: {
87120
type: Boolean,
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
POST http://localhost:3001/api/software/
22
Content-Type: application/json
3-
Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNhbXBsZSIsImlkIjoiNWY4ZGEzODcwODlmZmY0ZGIwNmJjMGFmIiwiaWF0IjoxNjAzODkzMzExfQ.ARy4EKDMzJqd4DcZyWXP5hygSQ9A2Bw1YfMQ-Nb03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"SampleSoftware8",
7-
"description": "A sample software",
6+
"name": "MyApp3",
7+
"shortDescription": "MyApp3 Short descrption",
8+
"description": "A sample software long description",
89
"homePage": "http://example.com",
910
"platform": "Windows",
10-
"isActiveDevelopment": true
11+
"isActiveDevelopment": true,
12+
"pricing": "free"
1113
}

tests/utils/api/softwareTestUtils.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ const Software = require('../../../models/software');
22

33
const sampleSoftwareInDb1 = {
44
name: 'SampleSoftware',
5+
shortDescription: 'A sample short description 1',
56
description: 'A sample software 1',
67
homePage: 'http://example.com',
78
platform: 'Windows',
9+
pricing: 'free',
810
isActiveDevelopment: true,
911
};
1012

1113
const sampleSoftwareInDb2 = {
1214
name: 'SampleSoftware2',
15+
shortDescription: 'A sample short description 2',
1316
description: 'A sample software 1',
1417
homePage: 'http://apple.com',
1518
platform: 'MacOS',
19+
pricing: 'paid',
1620
isActiveDevelopment: false,
1721
};
1822

0 commit comments

Comments
 (0)