module.exports = { _id: '_design/site', version: '1.0.0', appVersion: '1.0.0', hash: 'site_v1_0_0_' + Date.now(), views: { # Активные товары для каталога active_products: { map: ((doc) -> if doc.type == 'product' && doc.active == true emit([doc.category, doc.name], { _id: doc._id, name: doc.name, price: doc.price, oldPrice: doc.oldPrice, sku: doc.sku, image: doc.image, category: doc.category, description: doc.description, attributes: doc.attributes }) ).toString() }, # Опубликованные статьи блога published_articles: { map: ((doc) -> if doc.type == 'blog_article' && doc.published == true emit([doc.createdAt], { _id: doc._id, title: doc.title, slug: doc.slug, excerpt: doc.excerpt, image: doc.image, author: doc.author, createdAt: doc.createdAt, content: doc.content }) ).toString() }, # Активные слайды active_slides: { map: ((doc) -> if doc.type == 'hero_slide' && doc.active == true emit(doc.order, { _id: doc._id, title: doc.title, subtitle: doc.subtitle, image: doc.image, buttonText: doc.buttonText, buttonLink: doc.buttonLink }) ).toString() } }, validates_doc_update: ((newDoc, oldDoc, userCtx) -> # Базовая валидация документов # Запрещаем изменение design документов if newDoc._id && newDoc._id.startsWith('_design/') if oldDoc # existing document throw { forbidden: 'Design documents can only be updated by admins' } # Валидация товаров if newDoc.type == 'product' if !newDoc.name throw { forbidden: 'Product must have a name' } if !newDoc.price || isNaN(parseFloat(newDoc.price)) throw { forbidden: 'Product must have a valid price' } if !newDoc.sku throw { forbidden: 'Product must have SKU' } # Валидация статей блога if newDoc.type == 'blog_article' if !newDoc.title throw { forbidden: 'Blog article must have a title' } if !newDoc.slug throw { forbidden: 'Blog article must have a slug' } return true ).toString() }