Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose');
- const Schema = mongoose.Schema;
- const logoSchema = require('./site-sections/logo');
- var sectionSchema = new Schema(
- {
- show: { type: Boolean, default: true },
- order: Number
- },
- { discriminatorKey: 'type' }
- );
- const siteSchema = new Schema({
- _user: { type: Schema.Types.ObjectId, ref: 'User' },
- type: { type: String, required: true },
- title: { type: String, default: '' },
- name: { type: String, required: true },
- password: { type: String, default: '' },
- caching: { type: Number, default: 1 },
- unique_id: { type: String, required: true },
- sections: [sectionSchema]
- });
- const sectionArray = siteSchema.path('sections');
- const headerSchema = new Schema({
- image: { type: String, default: '' },
- title: { type: String, default: '' },
- sub_title: { type: String, default: '' },
- show: { type: Boolean, default: true },
- logo: logoSchema
- });
- sectionArray.discriminator('header', headerSchema);
- const textSchema = new Schema({
- text: String
- });
- sectionArray.discriminator('text', textSchema);
- module.exports = mongoose.model('site', siteSchema);
- const Site = require('../../models/site');
- exports.update = async function(req, res, next) {
- console.log(req.body);
- if (req.body.unique_site_id) {
- Site.update(
- {
- unique_id: req.body.unique_site_id,
- _user: req.user.id,
- 'sections.type': 'header'
- },
- {
- $set: {
- ['sections.$.' + req.body.key]: req.body.value
- }
- },
- function(err, status) {
- if (err) {
- console.log(err);
- return res.status(500).send();
- }
- console.log(status);
- return res.status(200).send();
- }
- );
- }
- };
Add Comment
Please, Sign In to add comment