const mongoose = require('mongoose') const paginate = require('mongoose-paginate-v2') function image(img) { return '/uploads/images/downloads/' + img } function file(file) { return '/uploads/apps/' + file } const DownloadFilesSchema = mongoose.Schema({ _creator: { type: mongoose.ObjectId, ref: 'User' }, name: String, os: { type: String, enum: ['windows', 'linux', 'mac', 'android', 'ios'] }, file: { type: String, get: file } }) const DownloadSchema = mongoose.Schema({ _creator: { type: mongoose.ObjectId, ref: 'User' }, title: String, short_description: String, description: String, image: { type: String, get: image }, category: mongoose.ObjectId, files: [DownloadFilesSchema] }) DownloadSchema.plugin(paginate) module.exports = mongoose.model('Download', DownloadSchema)