var pmongoose = require("mongoose");
var Photo = require("./schema").Photo;

function newGallery(data, callback) {

	var newPhoto = new Photo(data);

	Photo.create(newPhoto, function(err, data) {
		if (err) {
			return callback(err, null);
		}
		else {
			return callback(null, data);
		}

	});
}

function findGallery(data, callback) {

	var query = {"user": data};

	Photo.findOne(query, function(err, data) {

		if (err) {
			return callback(err);
		}
		else {
			return callback(null, data);
		}
	});
}

function newPhoto(id, update, callback) {

	var query = {"user": id};

	Photo.findOneAndUpdate(query, update, function(err, data) {

		if (err) {
			return callback(err);
		}
		else {
			return callback(null, data);
		}
	});	
}


function deleteURL() {

}

module.exports = {
	newGallery: newGallery,
	findGallery: findGallery,
	newPhoto: newPhoto,
	deleteURL: deleteURL
};
@@ -189,16 +189,17 @@
 data) %7B%0A
+%0A
 %09%09if (er
@@ -434,32 +434,38 @@
 urn callback(err
+, null
 );%0A%09%09%7D%0A%09%09else %7B%0A
@@ -676,16 +676,22 @@
 back(err
+, null
 );%0A%09%09%7D%0A%09
@@ -763,20 +763,367 @@
 leteURL(
-) %7B%0A
+id, photo, callback) %7B%0A%0A%09var url = Object.keys(photo)%5B0%5D;%0A%09console.log(photo);%0A%09var query = %7B%22user%22: id%7D;%0A%09var remove = %7B $pull: %7B%22photos%22: %7B%22url%22: url%7D%7D%7D;%0A%0A%09Photo.findOneAndUpdate(query, remove, function(err, data) %7B%0A%09%09console.log(query, remove, data);%0A%09%09if (err) %7B%0A%09%09%09return callback(err, null);%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09return callback(null, data);%0A%09%09%7D%0A%09%7D);
 %0A%7D%0A%0Amodu

delete function