-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongoose-types.js
138 lines (106 loc) · 3.78 KB
/
mongoose-types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';
var util = require('util');
var _ = require('lodash');
exports.mockTypes = function () {
var mongoose = require.main.require('mongoose');
exports.mockTypes_DI(mongoose);
};
exports.mockTypes_DI = function (mongoose) {
var types = {
File: Object,
Picture: Object,
Integer: Number,
GeoPoint: Object,
Text: String,
Html: String
};
_.assign(mongoose.Schema.Types, types);
};
exports.loadTypes = function () {
var mongoose = require.main.require('mongoose');
exports.loadTypes_DI(mongoose);
};
exports.loadTypes_DI = _.once(function (mongoose) {
var File = function File (path, options) {
File.super_.call(this, path, options);
};
util.inherits(File, mongoose.Schema.Types.Mixed);
File.prototype.cast = function (value, doc, init) {
var ret = File.super_.prototype.cast.call(this, value, doc, init);
if (ret && ret.path && CDN_PREFIX) {
var file_parts = ret.path.split('/');
ret.path = file_parts[file_parts.length - 1];
ret.url = CDN_PREFIX + ret.path;
}
return ret;
};
mongoose.Types.File = Object;
mongoose.Schema.Types.File = File;
exports.File = File;
var Picture = function Picture (path, options) {
Picture.super_.call(this, path, options);
};
util.inherits(Picture, mongoose.Schema.Types.Mixed);
Picture.prototype.cast = function (value, doc, init) {
return Picture.super_.prototype.cast.call(this, value, doc, init);
};
mongoose.Types.Picture = Object;
mongoose.Schema.Types.Picture = Picture;
exports.Picture = Picture;
var Filepicker = function Filepicker (path, options) {
Filepicker.super_.call(this, path, options);
};
util.inherits(Filepicker, mongoose.Schema.Types.Mixed);
Filepicker.prototype.cast = function (value, doc, init) {
return Filepicker.super_.prototype.cast.call(this, value, doc, init);
};
mongoose.Types.Filepicker = Object;
mongoose.Schema.Types.Filepicker = Filepicker;
exports.Filepicker = Filepicker;
var Time = function Time (path, options) {
Time.super_.call(this, path, options);
};
util.inherits(Time, mongoose.Schema.Types.String);
Time.prototype.cast = function (value, doc, init) {
return Picture.super_.prototype.cast.call(this, value, doc, init);
};
mongoose.Types.Time = Object;
mongoose.Schema.Types.Time = Time;
exports.Time = Time;
var Integer = function Integer (path, options) {
Integer.super_.call(this, path, options);
};
util.inherits(Integer, mongoose.Schema.Types.Number);
Integer.prototype.cast = function (value, doc, init) {
var num = Integer.super_.prototype.cast.call(this, value, doc, init);
return Math.floor(num);
};
mongoose.Types.Integer = Number;
mongoose.Schema.Types.Integer = Integer;
exports.Integer = Integer;
var GeoPoint = function GeoPoint (path, options) {
GeoPoint.super_.call(this, path, options);
};
util.inherits(GeoPoint, mongoose.Schema.Types.Mixed);
exports.GeoPoint = GeoPoint;
mongoose.Types.GeoPoint = Object;
mongoose.Schema.Types.GeoPoint = GeoPoint;
var Text = function Text (path, options) {
Text.super_.call(this, path, options);
};
util.inherits(Text, mongoose.Schema.Types.String);
exports.Text = Text;
mongoose.Types.Text = String;
mongoose.Schema.Types.Text = Text;
var Html = function Html (path, options) {
Html.super_.call(this, path, options);
};
util.inherits(Html, Text);
exports.Html = Html;
mongoose.Types.Html = String;
mongoose.Schema.Types.Html = Html;
});
var CDN_PREFIX = '';
exports.setCdnPrefix = function (prefix) {
CDN_PREFIX = prefix;
};