Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //create the poetry
  2. self.app.post('/poetry', function(req, res) {
  3. res.setHeader('Content-Type', 'application/json; charset=utf-8');
  4. if (self.db.error) { // Check if db has errors
  5. res.send(self.getError(self.db_error));
  6. } else {
  7. var titulo = req.body.titulo;
  8. var autor = req.body.autor;
  9. var poesia = req.body.poesia;
  10. var dataDeCriacao = req.body.dataDeCriacao;
  11. var tags = req.body.tags;
  12. var email = req.body.email;
  13. self.db.collection('poetry', function(err, collection) {
  14. if (err) {
  15. res.send(self.getError(err));
  16. } else {
  17. // Find user with same email
  18. collection.find({ "email" : email }).toArray(function(err, data) {
  19. if (err) {
  20. res.send(self.getError(err));
  21. } else {
  22. if (data.length > 0) {
  23. // There is at least one user. Not sucessfull.
  24. res.send(self.getError("Usuário já cadastrado."));
  25. } else {
  26. collection.insert({
  27. "titulo" : email,
  28. "autor" : password,
  29. "poesia" : name,
  30. "dataDeCriacao" : dataDeCriacao,
  31. "tags" : tags
  32. }, function(err, doc) {
  33. if (err) {
  34. res.send(self.getError(err));
  35. } else {
  36. res.send(self.getSuccess(null));
  37. }
  38. });
  39. }
  40. }
  41. });
  42. }
  43. });
  44. }
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement