@dhyasama/totem-models 2.6.1 → 2.7.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/Interaction.js +14 -0
- package/lib/Organization.js +1 -1
- package/package.json +2 -2
- package/test/Interaction.js +162 -0
- package/.npmignore +0 -14
- package/package-lock.json +0 -1163
package/lib/Interaction.js
CHANGED
|
@@ -84,6 +84,9 @@ module.exports = function(mongoose, config) {
|
|
|
84
84
|
|
|
85
85
|
Interaction.statics.getForPeople = function getForPeople(personIds, options, cb) {
|
|
86
86
|
|
|
87
|
+
// This filters by customer so is NOT usable by admin tools
|
|
88
|
+
if (config.CUSTOMER_ID == 'GLOBAL_PROCESS') return cb(new Error('Access denied. Use getForPeopleLite.'), null);
|
|
89
|
+
|
|
87
90
|
var self = this;
|
|
88
91
|
|
|
89
92
|
options.limit = options.limit || -1;
|
|
@@ -128,6 +131,17 @@ module.exports = function(mongoose, config) {
|
|
|
128
131
|
|
|
129
132
|
};
|
|
130
133
|
|
|
134
|
+
Interaction.statics.getForPeopleLite = function getForPeopleLite(personIds, cb) {
|
|
135
|
+
|
|
136
|
+
// This doesn't filter by customer so is only usable by admin tools
|
|
137
|
+
if (config.CUSTOMER_ID != 'GLOBAL_PROCESS') return cb(new Error('Access denied'), null);
|
|
138
|
+
|
|
139
|
+
var self = this;
|
|
140
|
+
var query = self.find({'attendees.external': { $in : personIds }});
|
|
141
|
+
query.exec(cb);
|
|
142
|
+
|
|
143
|
+
};
|
|
144
|
+
|
|
131
145
|
Interaction.statics.getNotes = function getNotes(personIds, options, cb) {
|
|
132
146
|
|
|
133
147
|
var self = this;
|
package/lib/Organization.js
CHANGED
|
@@ -1146,7 +1146,7 @@ module.exports = function(mongoose, config) {
|
|
|
1146
1146
|
if (data.domain) {
|
|
1147
1147
|
data.domain = data.domain.toLowerCase();
|
|
1148
1148
|
var domainRegExp = options.fuzzy ? new RegExp(data.domain, 'i') : new RegExp('^' + data.domain + '$', 'i');
|
|
1149
|
-
query['$or'].push({ 'website': domainRegExp });
|
|
1149
|
+
query['$or'].push({ 'website': domainRegExp }, {'websiteAliases': domainRegExp});
|
|
1150
1150
|
}
|
|
1151
1151
|
|
|
1152
1152
|
// remove if unused
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-models",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"author": "Jason Reynolds",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "Models for Totem platform",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@dhyasama/ffvc-crypto": "^1.0.0",
|
|
16
16
|
"@dhyasama/ffvc-geoip": "^1.0.0",
|
|
17
17
|
"@dhyasama/ffvc-s3": "^1.0.0",
|
|
18
|
-
"@dhyasama/ffvc-utilities": "^2.
|
|
18
|
+
"@dhyasama/ffvc-utilities": "^2.2.0",
|
|
19
19
|
"async": "^2.6.0",
|
|
20
20
|
"awesome-phonenumber": "^1.0.14",
|
|
21
21
|
"bcrypt": "^0.8.0",
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
_ = require('underscore'),
|
|
7
|
+
config = require('./config')['test'],
|
|
8
|
+
mongoose = require('mongoose'),
|
|
9
|
+
moment = require('moment'),
|
|
10
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
11
|
+
Interaction = mongoose.model('Interaction');
|
|
12
|
+
|
|
13
|
+
var totemCustomerId1 = new mongoose.Types.ObjectId();
|
|
14
|
+
var totemCustomerId2 = new mongoose.Types.ObjectId();
|
|
15
|
+
var externalAttendee1 = new mongoose.Types.ObjectId();
|
|
16
|
+
var externalAttendee2 = new mongoose.Types.ObjectId();
|
|
17
|
+
|
|
18
|
+
describe.only('Interaction', function() {
|
|
19
|
+
|
|
20
|
+
before(function(done) {
|
|
21
|
+
if (mongoose.connection.db) return done();
|
|
22
|
+
mongoose.connect(config.db.uri, done);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
before(function(done) {
|
|
26
|
+
clearDB(done);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// calendarEventId: { type: Schema.ObjectId, ref: 'CalendarEvent', required: true }, // the event from the original pull
|
|
30
|
+
// providerEventId: { type: String, required: true, index: true, trim: true }, // unique id from the calendar provider
|
|
31
|
+
// totemCustomerId: { type: Schema.ObjectId, ref: 'Organization', index: true, required: true },
|
|
32
|
+
// summary: { type: String, required: true, trim: true },
|
|
33
|
+
// startTime: { type: Date, index: true },
|
|
34
|
+
// recurring: { type: Boolean, default: false },
|
|
35
|
+
// attendees: {
|
|
36
|
+
// internal: [{ type: Schema.ObjectId, ref: 'Person', index: true }], // people from customer
|
|
37
|
+
// external: [{ type: Schema.ObjectId, ref: 'Person', index: true }] // everyone else
|
|
38
|
+
// },
|
|
39
|
+
// notes: [ { type: Schema.ObjectId, ref: 'Note' } ]
|
|
40
|
+
|
|
41
|
+
it('creates an interaction', function(done) {
|
|
42
|
+
|
|
43
|
+
var interaction = new Interaction({
|
|
44
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
45
|
+
providerEventId: 'abc124',
|
|
46
|
+
totemCustomerId: totemCustomerId1,
|
|
47
|
+
startTime: new Date(),
|
|
48
|
+
summary: 'test 1',
|
|
49
|
+
attendees: {
|
|
50
|
+
external: [externalAttendee1]
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
55
|
+
should.not.exist(err);
|
|
56
|
+
should.exist(result);
|
|
57
|
+
done();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('creates another interaction', function(done) {
|
|
63
|
+
|
|
64
|
+
var interaction = new Interaction({
|
|
65
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
66
|
+
providerEventId: 'abc124',
|
|
67
|
+
totemCustomerId: totemCustomerId2,
|
|
68
|
+
startTime: new Date(),
|
|
69
|
+
summary: 'test 2',
|
|
70
|
+
attendees: {
|
|
71
|
+
external: [externalAttendee2]
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
76
|
+
should.not.exist(err);
|
|
77
|
+
should.exist(result);
|
|
78
|
+
done();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('gets interactions for a person', function(done) {
|
|
84
|
+
|
|
85
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
86
|
+
|
|
87
|
+
Interaction.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
88
|
+
should.not.exist(err);
|
|
89
|
+
should.exist(result);
|
|
90
|
+
result.length.should.equal(1);
|
|
91
|
+
result[0].summary.should.equal('test 1');
|
|
92
|
+
done();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('tries to get interactions for a person as an admin process', function(done) {
|
|
98
|
+
|
|
99
|
+
config.CUSTOMER_ID = 'GLOBAL_PROCESS';
|
|
100
|
+
|
|
101
|
+
Interaction.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
102
|
+
should.exist(err);
|
|
103
|
+
should.not.exist(result);
|
|
104
|
+
done();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('gets interactions for a person as an admin process', function(done) {
|
|
110
|
+
|
|
111
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
112
|
+
|
|
113
|
+
Interaction.getForPeople([externalAttendee2], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
114
|
+
should.not.exist(err);
|
|
115
|
+
should.exist(result);
|
|
116
|
+
result.length.should.equal(1);
|
|
117
|
+
result[0].summary.should.equal('test 2');
|
|
118
|
+
done();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('gets interactions for a customer', function(done) {
|
|
124
|
+
|
|
125
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
126
|
+
|
|
127
|
+
var interaction = new Interaction({
|
|
128
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
129
|
+
providerEventId: 'abc124',
|
|
130
|
+
totemCustomerId: totemCustomerId2,
|
|
131
|
+
startTime: new Date(),
|
|
132
|
+
summary: 'test 3',
|
|
133
|
+
attendees: {
|
|
134
|
+
external: [new mongoose.Types.ObjectId()]
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
139
|
+
|
|
140
|
+
should.not.exist(err);
|
|
141
|
+
should.exist(result);
|
|
142
|
+
|
|
143
|
+
Interaction.getForCustomer(totemCustomerId2, null, function(err, result) {
|
|
144
|
+
|
|
145
|
+
should.not.exist(err);
|
|
146
|
+
should.exist(result);
|
|
147
|
+
result.length.should.equal(2);
|
|
148
|
+
|
|
149
|
+
Interaction.getForCustomer(totemCustomerId1, null, function(err, result) {
|
|
150
|
+
should.not.exist(err);
|
|
151
|
+
should.exist(result);
|
|
152
|
+
result.length.should.equal(1);
|
|
153
|
+
done();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
});
|