46 lines
960 B
JavaScript
46 lines
960 B
JavaScript
const mongoose = require('mongoose');
|
|
const { MAX_TAGS } = require('../lib/tagConfig');
|
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
const photoSchema = new Schema({
|
|
filename: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
path: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
variants: {
|
|
medium: { type: String },
|
|
thumb: { type: String },
|
|
},
|
|
caption: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
tags: {
|
|
type: [String],
|
|
required: true,
|
|
validate: [
|
|
{
|
|
validator: (arr) => Array.isArray(arr) && arr.length > 0 && arr.length <= MAX_TAGS,
|
|
message: `Tags must include between 1 and ${MAX_TAGS} items.`
|
|
}
|
|
]
|
|
},
|
|
hash: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
index: true
|
|
}
|
|
}, {
|
|
timestamps: true,
|
|
});
|
|
|
|
const Photo = mongoose.model('Photo', photoSchema);
|
|
|
|
module.exports = Photo;
|