@dhyasama/totem-models 10.8.0 → 10.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Organization.js +46 -1
- package/lib/Round.js +1 -1
- package/migrations/social_handles.js +119 -0
- package/package.json +1 -1
- package/test/Organization.js +24 -1
package/lib/Organization.js
CHANGED
|
@@ -33,6 +33,12 @@ module.exports = function(mongoose, config) {
|
|
|
33
33
|
linkedin: { type: String, trim: true, unique: true, partialFilterExpression : { type :"string" } }
|
|
34
34
|
},
|
|
35
35
|
|
|
36
|
+
social_handle: {
|
|
37
|
+
twitter: { type: String, trim: true },
|
|
38
|
+
facebook: { type: String, trim: true },
|
|
39
|
+
linkedin: { type: String, trim: true }
|
|
40
|
+
},
|
|
41
|
+
|
|
36
42
|
contact: {
|
|
37
43
|
|
|
38
44
|
phone: [{
|
|
@@ -1963,7 +1969,7 @@ module.exports = function(mongoose, config) {
|
|
|
1963
1969
|
|
|
1964
1970
|
Organization.pre('save', function(next) {
|
|
1965
1971
|
|
|
1966
|
-
|
|
1972
|
+
const prepForSave = function prepForSave(doc) {
|
|
1967
1973
|
|
|
1968
1974
|
var cleanContactInfo = function cleanContactInfo(obj) {
|
|
1969
1975
|
|
|
@@ -2088,7 +2094,46 @@ module.exports = function(mongoose, config) {
|
|
|
2088
2094
|
|
|
2089
2095
|
};
|
|
2090
2096
|
|
|
2097
|
+
const setSocialHandles = function setSocialHandles(doc) {
|
|
2098
|
+
|
|
2099
|
+
const getHandle = function getHandle(url) {
|
|
2100
|
+
|
|
2101
|
+
let handle = "";
|
|
2102
|
+
|
|
2103
|
+
if (!url) return handle;
|
|
2104
|
+
|
|
2105
|
+
try {
|
|
2106
|
+
|
|
2107
|
+
const segments = url.split("/");
|
|
2108
|
+
|
|
2109
|
+
// normal case, e.g., http://facebook.com/hello
|
|
2110
|
+
if (segments[segments.length - 1]) handle = segments[segments.length - 1];
|
|
2111
|
+
|
|
2112
|
+
// trailing slash, e.g., http://facebook.com/hello/
|
|
2113
|
+
else if (segments[segments.length - 2]) handle = segments[segments.length - 2];
|
|
2114
|
+
|
|
2115
|
+
else handle = "";
|
|
2116
|
+
|
|
2117
|
+
}
|
|
2118
|
+
catch (err) {
|
|
2119
|
+
console.log('Error for url', url);
|
|
2120
|
+
console.error(err);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
return handle;
|
|
2124
|
+
|
|
2125
|
+
};
|
|
2126
|
+
|
|
2127
|
+
if (!doc) return;
|
|
2128
|
+
if (!doc.social) return;
|
|
2129
|
+
doc.social_handle.facebook = getHandle(doc.social.facebook);
|
|
2130
|
+
doc.social_handle.twitter = getHandle(doc.social.twitter);
|
|
2131
|
+
doc.social_handle.linkedin = getHandle(doc.social.linkedin);
|
|
2132
|
+
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2091
2135
|
prepForSave(this);
|
|
2136
|
+
setSocialHandles(this);
|
|
2092
2137
|
|
|
2093
2138
|
return next();
|
|
2094
2139
|
|
package/lib/Round.js
CHANGED
|
@@ -399,7 +399,7 @@ module.exports = function(mongoose, config) {
|
|
|
399
399
|
|
|
400
400
|
let query = self.find({ 'vehicles.fund': fundId });
|
|
401
401
|
query.select('organization roundName vehicles');
|
|
402
|
-
query.populate('organization', 'name description logoUrl website websiteAliases filters status');
|
|
402
|
+
query.populate('organization', 'name description logoUrl website websiteAliases filters status ipo closed acquired operating');
|
|
403
403
|
|
|
404
404
|
if (options.isWorkerProcess) {
|
|
405
405
|
query.populate('vehicles.investments');
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const mongoose = require('mongoose');
|
|
4
|
+
const models = require('../index')(mongoose, { suppressDebugLog: true });
|
|
5
|
+
const Organization = mongoose.model('Organization');
|
|
6
|
+
const db_uri = "mongodb://jason:T576G150HPXLA5q4BJ2o2zj747B5030x@production-shard-00-00-gv0f3.mongodb.net:27017,production-shard-00-01-gv0f3.mongodb.net:27017,production-shard-00-02-gv0f3.mongodb.net:27017/production?replicaSet=Production-shard-0&ssl=true&authSource=admin";
|
|
7
|
+
const _ = require('underscore');
|
|
8
|
+
const async = require('async');
|
|
9
|
+
|
|
10
|
+
let dirtyOrgs = [];
|
|
11
|
+
let savedOrgCount = 0;
|
|
12
|
+
|
|
13
|
+
const getHandle = function getHandle(url) {
|
|
14
|
+
|
|
15
|
+
let handle = "";
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
|
|
19
|
+
const segments = url.split("/");
|
|
20
|
+
|
|
21
|
+
// normal case, e.g., http://facebook.com/hello
|
|
22
|
+
if (segments[segments.length - 1]) handle = segments[segments.length - 1];
|
|
23
|
+
|
|
24
|
+
// trailing slash, e.g., http://facebook.com/hello/
|
|
25
|
+
else if (segments[segments.length - 2]) handle = segments[segments.length - 2];
|
|
26
|
+
|
|
27
|
+
else handle = "";
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.log('Error for url', url);
|
|
32
|
+
console.error(err);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//console.log(handle, url);
|
|
36
|
+
|
|
37
|
+
return handle;
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const saveOrg = function(org, cb) {
|
|
42
|
+
|
|
43
|
+
Organization.upsert(org, 'social-handle-transformation', function(err) {
|
|
44
|
+
if (err) console.error(err);
|
|
45
|
+
else {
|
|
46
|
+
savedOrgCount += 1;
|
|
47
|
+
//console.log(org.name);
|
|
48
|
+
}
|
|
49
|
+
return cb();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
mongoose.connect(db_uri, function(err) {
|
|
55
|
+
|
|
56
|
+
if (err) {
|
|
57
|
+
console.error(err);
|
|
58
|
+
process.exit();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const page = 9;
|
|
62
|
+
const limit = 10000;
|
|
63
|
+
const skip = (page - 1) * limit;
|
|
64
|
+
|
|
65
|
+
console.log('Getting page', page);
|
|
66
|
+
|
|
67
|
+
Organization
|
|
68
|
+
.find({
|
|
69
|
+
$and: [
|
|
70
|
+
{ social: { $exists: true } },
|
|
71
|
+
{
|
|
72
|
+
$or: [
|
|
73
|
+
{ "social.facebook": { $exists: true } },
|
|
74
|
+
{ "social.twitter": { $exists: true } },
|
|
75
|
+
{ "social.linkedin": { $exists: true } }
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
})
|
|
80
|
+
.skip(skip)
|
|
81
|
+
.limit(limit)
|
|
82
|
+
.sort({"name": "asc"})
|
|
83
|
+
.exec(function(err, orgs) {
|
|
84
|
+
|
|
85
|
+
if (err) {
|
|
86
|
+
console.error(err);
|
|
87
|
+
process.exit();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log('Found', orgs.length, 'orgs');
|
|
91
|
+
|
|
92
|
+
orgs.forEach(function(org) {
|
|
93
|
+
|
|
94
|
+
let dirty = false;
|
|
95
|
+
|
|
96
|
+
if (org.social.facebook || org.social.twitter || org.social.linkedin) {
|
|
97
|
+
dirty = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (dirty) dirtyOrgs.push(org);
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
console.log(dirtyOrgs.length, 'orgs need to be saved');
|
|
105
|
+
|
|
106
|
+
async.each(dirtyOrgs, saveOrg, function(err) {
|
|
107
|
+
|
|
108
|
+
if (err) console.error(err);
|
|
109
|
+
|
|
110
|
+
console.log('Saved', savedOrgCount, 'orgs');
|
|
111
|
+
console.log('Done page', page);
|
|
112
|
+
|
|
113
|
+
process.exit();
|
|
114
|
+
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
});
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -19,7 +19,7 @@ var someOtherLp;
|
|
|
19
19
|
var account;
|
|
20
20
|
var customer1, customer2;
|
|
21
21
|
|
|
22
|
-
describe('Organization', function() {
|
|
22
|
+
describe.only('Organization', function() {
|
|
23
23
|
|
|
24
24
|
var org1, org2, org3, org4, org5;
|
|
25
25
|
var mergeId = new mongoose.Types.ObjectId();
|
|
@@ -448,6 +448,7 @@ describe('Organization', function() {
|
|
|
448
448
|
org1 = org;
|
|
449
449
|
done();
|
|
450
450
|
});
|
|
451
|
+
|
|
451
452
|
}); // end adds an org
|
|
452
453
|
|
|
453
454
|
it('finds a fuzzy match by name', function (done) {
|
|
@@ -1148,6 +1149,28 @@ describe('Organization', function() {
|
|
|
1148
1149
|
|
|
1149
1150
|
});
|
|
1150
1151
|
|
|
1152
|
+
it('sets social handles', function (done) {
|
|
1153
|
+
|
|
1154
|
+
const o = new Organization();
|
|
1155
|
+
o.name = 'Social Butterfly';
|
|
1156
|
+
o.slug = 'sb';
|
|
1157
|
+
o.social = {
|
|
1158
|
+
facebook: 'https://facebook.com/socialbutterfly',
|
|
1159
|
+
twitter: 'https://twitter.com/socialbutterfly',
|
|
1160
|
+
linkedin: 'http://linkedin.com/in/socialbutterfly',
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
Organization.upsert(o, 'test-user', function (err, org) {
|
|
1164
|
+
should.not.exist(err);
|
|
1165
|
+
should.exist(org);
|
|
1166
|
+
org.social_handle.facebook.should.equal('socialbutterfly');
|
|
1167
|
+
org.social_handle.twitter.should.equal('socialbutterfly');
|
|
1168
|
+
org.social_handle.linkedin.should.equal('socialbutterfly');
|
|
1169
|
+
done();
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1151
1174
|
});
|
|
1152
1175
|
|
|
1153
1176
|
describe('Deals', function() {
|