Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addPost(tipo, id, post_id, nombreImagen, res) {
- Usuario.findById(id, (err, myPost) => {
- // AGREGAMOS EL NUEVO POST AL USUARIO
- myPost.post.push({
- tipo: tipo,
- imagen: nombreImagen,
- post_id: post_id
- });
- // GUARDAMOS LOS CAMBIOS EN LA BASE DE DATOS
- myPost.save((err, tipoActualizado) => {
- if (err) {
- return res.status(500).json({
- ok: false,
- mensaje: 'error al guardar post',
- error: err
- })
- }
- subirImagen();
- myPost.password = ":)";
- return res.status(200).json({
- ok: true,
- mensaje: `Imagen actualizada correctamente`,
- tipo: tipoActualizado
- })
- })
- })
- }
- var mongoose = require('mongoose');
- var uniqueValidator = require('mongoose-unique-validator');
- var Schema = mongoose.Schema;
- var usuarioSchema = new Schema({
- nombre: { type: String, required: [true, 'El nombre es necesario'] },
- post: [{
- type: Object,
- required: false,
- default: ''
- }]
- });
- usuarioSchema.plugin(uniqueValidator, { message: '{PATH} debe de ser único' });
Add Comment
Please, Sign In to add comment