2025-12-15 07:28:47 +00:00
|
|
|
const mongoose = require('mongoose');
|
|
|
|
|
|
|
|
|
|
const albumSchema = new mongoose.Schema({
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true,
|
|
|
|
|
trim: true,
|
|
|
|
|
index: true
|
|
|
|
|
},
|
|
|
|
|
artist: {
|
|
|
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
|
|
|
ref: 'Artist',
|
|
|
|
|
required: true,
|
|
|
|
|
index: true
|
|
|
|
|
},
|
|
|
|
|
coverImage: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
|
|
|
|
year: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
|
|
|
|
genre: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
// Статистика
|
|
|
|
|
stats: {
|
|
|
|
|
tracks: { type: Number, default: 0 },
|
|
|
|
|
duration: { type: Number, default: 0 }, // в секундах
|
|
|
|
|
plays: { type: Number, default: 0 }
|
|
|
|
|
},
|
|
|
|
|
// Кто добавил альбом
|
|
|
|
|
addedBy: {
|
|
|
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
|
|
|
ref: 'User',
|
|
|
|
|
required: true
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
timestamps: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Индексы для поиска
|
|
|
|
|
albumSchema.index({ title: 'text' });
|
|
|
|
|
albumSchema.index({ artist: 1, createdAt: -1 });
|
|
|
|
|
albumSchema.index({ createdAt: -1 });
|
|
|
|
|
|
|
|
|
|
module.exports = mongoose.model('Album', albumSchema);
|
|
|
|
|
|
2025-12-15 19:51:01 +00:00
|
|
|
|