Files
mbmanager-api/components/file/fileModel.js
T
kavehhn 4fc323cd16 ADD: API_URL to env
ADD: DocumentUrls and mainImageUrls field in belonging model
FIX: Indexing bugs for belonging
ADD: getImage endpoint to get private images
ADD: PrivateUrl field as virtual
FIX: Minor bug in bucketDeleteFile service
ADD: Word type to multer file checker
2025-04-27 16:17:17 +03:30

37 lines
888 B
JavaScript

const mongoose = require('mongoose')
const ObjectID = mongoose.Schema.Types.ObjectId
const fileSchema = new mongoose.Schema(
{
fileName: {
type: String,
required: true,
},
owner: {
type: ObjectID,
ref: 'User',
},
fileEndpoint: String,
bucketName: {
type: String,
required: true,
},
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true },
},
{ timestamps: true }
)
fileSchema.virtual('publicUrl').get(function () {
return this.fileEndpoint + '/' + this.bucketName + '/' + this.fileName
})
fileSchema.virtual('privateUrl').get(function () {
return process.env.API_URL + '/api/files/get-image/' + this.bucketName + '/' + this.fileName
})
const File = mongoose.model('file', fileSchema)
module.exports = File