Skip to content

Commit 0ecc6bd

Browse files
authored
Merge pull request #10 from GeneralMagicio/add/status-for-videos
Add status field to videos collection for content moderation
2 parents 00c19d2 + 514cb07 commit 0ecc6bd

5 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎config/migrations.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ const migrations = [
108108
console.log('❌ userId index did not exist or could not be dropped');
109109
}
110110
}
111+
},
112+
{
113+
version: '1.2.0',
114+
description: 'Add status field to video schema for content moderation',
115+
up: async () => {
116+
const db = mongoose.connection.db;
117+
console.log('Using database:', db.databaseName);
118+
119+
// No need to modify existing documents - new fields are optional with default values
120+
// Mongoose schema will handle validation and default values for new uploads
121+
console.log('✅ Schema updated to support status field with enum [rejected, pending, approved]');
122+
console.log('📋 Note: Existing documents preserved. New uploads can optionally specify status (defaults to "pending")');
123+
},
124+
down: async () => {
125+
const db = mongoose.connection.db;
126+
const collection = db.collection('videos');
127+
128+
// Remove status field from existing documents
129+
try {
130+
const result = await collection.updateMany({}, { $unset: { status: "" } });
131+
console.log(`❌ Status field removed from ${result.modifiedCount} documents`);
132+
} catch (error) {
133+
console.log('❌ Could not remove status field:', error.message);
134+
}
135+
}
111136
}
112137
];
113138

‎middleware/validation.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const videoUploadSchema = Joi.object({
44
userId: Joi.string().optional().trim().min(1).max(100), // Make optional
55
latitude: Joi.number().required().min(-90).max(90),
66
longitude: Joi.number().required().min(-180).max(180),
7-
type: Joi.string().optional().valid('before', 'after') // Make optional
7+
type: Joi.string().optional().valid('before', 'after'), // Make optional
8+
status: Joi.string().optional().valid('rejected', 'pending', 'approved') // Make optional
89
});
910

1011
const validateVideoUpload = (req, res, next) => {

‎models/Video.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ const videoSchema = new mongoose.Schema({
3030
required: false, // Make optional for backward compatibility
3131
index: true
3232
},
33+
status: {
34+
type: String,
35+
required: false, // Make optional for backward compatibility
36+
enum: ['rejected', 'pending', 'approved'],
37+
default: 'pending'
38+
},
3339
gpsCoordinates: {
3440
latitude: {
3541
type: Number,

‎routes/videos.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const videoService = new VideoService();
99

1010
router.post('/upload', upload.single('video'), validateVideoUpload, async (req, res) => {
1111
try {
12-
const { userId, latitude, longitude, type } = req.body;
12+
const { userId, latitude, longitude, type, status } = req.body;
1313
const file = req.file;
1414

1515
if (!file) {
1616
return sendBadRequest(res, 'No video file provided');
1717
}
1818

19-
const uploadData = await videoService.uploadVideo(file, userId, latitude, longitude, type);
19+
const uploadData = await videoService.uploadVideo(file, userId, latitude, longitude, type, status);
2020
return sendCreated(res, 'Video uploaded successfully to IPFS', uploadData);
2121

2222
} catch (error) {

‎services/videoService.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class VideoService {
77
// Using S3-compatible API instead of invalid RPC endpoint
88
}
99

10-
async uploadVideo(file, userId, latitude, longitude, type) {
10+
async uploadVideo(file, userId, latitude, longitude, type, status) {
1111
console.log('Starting video upload process...', {
1212
userId,
1313
originalFilename: file.originalname,
@@ -50,6 +50,9 @@ class VideoService {
5050
if (userId) {
5151
videoData.userId = userId;
5252
}
53+
if (status) {
54+
videoData.status = status;
55+
}
5356

5457
console.log('Video data to save:', videoData);
5558

0 commit comments

Comments
 (0)