Permalink
Browse files

[merge] fix conflicts, remove statics

  • Loading branch information...
1 parent dc6885c commit d7cffb44ac138a158d69333b303d0622faa43421 @edwardhotchkiss committed Mar 17, 2012
Showing with 33 additions and 30 deletions.
  1. +33 −30 models/ShortURL.js
View
@@ -1,57 +1,60 @@
-/*!
-
- Mongoose Model:
- - ShortURL
-
+/**
+ *
+ * Mongoose Model:
+ * - ShortURL
+ *
*/
var mongoose = require('mongoose')
, Schema = mongoose.Schema
- , short = require('../lib/short')
, ObjectId = Schema.ObjectId;
var ShortURLSchema = new Schema({
- id : { type : ObjectId },
- URL : { type : String },
- qr : { type : String },
- hash : { type : String, unique: true },
- hits : { type : Number, default: 0 },
- created_at : { type : Date, default: Date.now },
- uniques : { type : Number, default: 0},
- visitors : { type : [String]}
+ id : { type : ObjectId },
+ URL : { type : String },
+ qr : { type : String },
+ hash : { type : String, unique: true },
+ hits : { type : Number, default: 0 },
+ created_at : { type : Date, default: Date.now },
+ uniques : { type : Number, default: 0},
+ visitors : { type : [String]}
});
-/*!
- @method findByHash
- @param {String} hash
- @param {Function} callback
-*/
+var ShortURL = mongoose.model('ShortURL', ShortURLSchema);
+
+/**
+ * @model ShortURL
+ * @method findByHash
+ * @param {String} hash
+ * @param {Function} callback
+ */
-ShortURLSchema.statics.findByHash = function (hash, options, callback) {
+ShortURL.findByHash = function (hash, options, callback) {
options.hash = hash;
- ShortURLSchema.findOne({ hash: hash }, function (error, URL) {
+ ShortURL.findOne({ hash: hash }, function (error, URL) {
if (error) {
callback(error, null);
} else {
if (URL) {
- ShortURLSchema.updateHitsById(URL, options, callback);
+ ShortURL.updateHitsById(URL, options, callback);
} else {
callback(null, null);
}
}
});
};
-/*!
- @method updatehitsById
- @param {ObjectId} id
- @param {Function} callback
+/**
+ * @model ShortURL
+ * @method updatehitsById
+ * @param {ObjectId} id
+ * @param {Function} callback
*/
-ShortURLSchema.statics.updateHitsById = function (URL, options, callback) {
+ShortURL.updateHitsById = function (URL, options, callback) {
if (options && options.visitor && URL.visitors.indexOf(options.visitor) === -1) {
- ShortURLSchema.update({'hash': options.hash}, {
+ ShortURL.update({'hash': options.hash}, {
$inc: {hits: 1, uniques: 1}, $push: {visitors: options.visitor}}, { multi: true}, function (error) {
if (error) {
callback(error, null);
@@ -60,7 +63,7 @@ ShortURLSchema.statics.updateHitsById = function (URL, options, callback) {
}
});
} else {
- ShortURLSchema.update({'hash': options.hash}, { $inc: {hits: 1}}, { multi: true}, function (error) {
+ ShortURL.update({'hash': options.hash}, { $inc: {hits: 1}}, { multi: true}, function (error) {
if (error) {
callback(error, null);
} else {
@@ -70,6 +73,6 @@ ShortURLSchema.statics.updateHitsById = function (URL, options, callback) {
}
};
-module.exports = short.connection.model('ShortURL', ShortURLSchema);
+module.exports = ShortURL;
/* EOF */

0 comments on commit d7cffb4

Please sign in to comment.