Guest User

Untitled

a guest
Jul 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. function addPost(tipo, id, post_id, nombreImagen, res) {
  2.  
  3. Usuario.findById(id, (err, myPost) => {
  4.  
  5.  
  6. // AGREGAMOS EL NUEVO POST AL USUARIO
  7. myPost.post.push({
  8. tipo: tipo,
  9. imagen: nombreImagen,
  10. post_id: post_id
  11. });
  12.  
  13. // GUARDAMOS LOS CAMBIOS EN LA BASE DE DATOS
  14. myPost.save((err, tipoActualizado) => {
  15.  
  16. if (err) {
  17. return res.status(500).json({
  18. ok: false,
  19. mensaje: 'error al guardar post',
  20. error: err
  21. })
  22. }
  23. subirImagen();
  24. myPost.password = ":)";
  25. return res.status(200).json({
  26. ok: true,
  27. mensaje: `Imagen actualizada correctamente`,
  28. tipo: tipoActualizado
  29. })
  30. })
  31. })
  32. }
  33.  
  34. var mongoose = require('mongoose');
  35. var uniqueValidator = require('mongoose-unique-validator');
  36.  
  37. var Schema = mongoose.Schema;
  38.  
  39. var usuarioSchema = new Schema({
  40.  
  41. nombre: { type: String, required: [true, 'El nombre es necesario'] },
  42. post: [{
  43. type: Object,
  44. required: false,
  45. default: ''
  46. }]
  47. });
  48.  
  49. usuarioSchema.plugin(uniqueValidator, { message: '{PATH} debe de ser único' });
Add Comment
Please, Sign In to add comment