Skip to content

Commit 7abffee

Browse files
Merge pull request Human-Connection#56 in HC/hc-api-feathers from feature/NEXT-270 to develop
* commit '62e8fbad20396ac63db89c2a742a462b87856c11': use --quiet for mongo try to de-dupe some stuff inside package.json by using variables disable one test and add coverage create comment notifications NEXT-270 - fixed travis build testing ends remove console logs add tests for contributions / make notifications translatable added mention notification test added mention notification test added general search endpoint
2 parents fd274c4 + 62e8fba commit 7abffee

27 files changed

+572
-51
lines changed

.istanbul.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
verbose: false
2+
instrumentation:
3+
root: ./
4+
reporting:
5+
print: summary
6+
reports:
7+
- html
8+
- text
9+
- lcov
10+
watermarks:
11+
statements: [70, 90]
12+
lines: [70, 90]
13+
functions: [70, 90]
14+
branches: [70, 90]

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@
3838
"eslint": "eslint server/. test/. --config .eslintrc.json",
3939
"start": "concurrently 'mongod' 'wait-on tcp:27017 && NODE_ENV=production node server/'",
4040
"start-win": "concurrently \"mongod\" \"wait-on tcp:27017 &&SET NODE_ENV=production&& node server/\"",
41-
"dev": "npm run clear && concurrently 'mongod --dbpath data --quiet' 'wait-on tcp:27017 && NODE_ENV=development nodemon --inspect server/'",
41+
"dev": "npm run clear && concurrently '$npm_package_config_mongoDev' 'wait-on tcp:27017 && NODE_ENV=development nodemon --inspect server/'",
4242
"dev-win": "npm run clear && concurrently \"mongod --dbpath data\" \"wait-on tcp:27017&&SET NODE_ENV=development&& nodemon --inspect server/\"",
4343
"dev-noseed": "concurrently 'mongod --dbpath data' 'wait-on tcp:27017 && NODE_ENV=development nodemon --inspect server/'",
4444
"dev-win-noseed": "concurrently \"mongod --dbpath data\" \"wait-on tcp:27017 && nodemon --inspect server/\"",
45-
"mocha": "npm run clear && concurrently --success first --kill-others 'mongod --dbpath data &>/dev/null' 'wait-on tcp:27017 && NODE_ENV=test mocha test/ --recursive --timeout 10000 --exit'"
45+
"mocha": "npm run clear && $npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && NODE_ENV=test $npm_package_config_mocha'",
46+
"coverage": "npm run clear && $npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && NODE_ENV=test istanbul cover $npm_package_config_mochaCoverage'"
47+
},
48+
"config": {
49+
"mongoDev": "mongod --dbpath data --quiet",
50+
"mocha": "node_modules/mocha/bin/_mocha test/ --recursive --timeout 10000 --exit",
51+
"mochaCoverage": "node_modules/mocha/bin/_mocha -- test/ --recursive --timeout 10000 --exit",
52+
"concurrently": "concurrently --kill-others --success first"
4653
},
4754
"dependencies": {
4855
"body-parser": "~1.18.2",
@@ -94,7 +101,8 @@
94101
"babel-eslint": "~8.2.1",
95102
"concurrently": "~3.5.1",
96103
"eslint": "~4.16.0",
97-
"mocha": "~4.0.1",
104+
"istanbul": "^0.4.5",
105+
"mocha": "^5.0.0",
98106
"nodemon": "~1.14.11",
99107
"shx": "^0.2.2",
100108
"wait-on": "~2.1.0"

server/app.hooks.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
// Application hooks that run for every service
2-
const logger = require('./hooks/logger');
2+
// const logger = require('./hooks/logger');
3+
const { discard } = require('feathers-hooks-common');
34

45
module.exports = {
56
before: {
67
all: [],
78
find: [],
89
get: [],
9-
create: [],
10-
update: [],
11-
patch: [],
10+
create: [
11+
discard('_id')
12+
],
13+
update: [
14+
discard('_id')
15+
],
16+
patch: [
17+
discard('_id')
18+
],
1219
remove: []
1320
},
1421

1522
after: {
16-
all: [ logger() ],
23+
all: [
24+
// logger()
25+
],
1726
find: [],
1827
get: [],
1928
create: [],
@@ -23,7 +32,9 @@ module.exports = {
2332
},
2433

2534
error: {
26-
all: [ logger() ],
35+
all: [
36+
// logger()
37+
],
2738
find: [],
2839
get: [],
2940
create: [],

server/helper/get-mentions.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const mentionRegex = /data-hc-mention="([\s\S]+?)"/g;
2+
3+
const getMentions = async (app, content) => {
4+
let match = mentionRegex.exec(content);
5+
let mention = {};
6+
let mentionsTable = {};
7+
while (match !== null) {
8+
mention = JSON.parse(match[1].replace(/"/g, '"'));
9+
if (!mentionsTable[mention._id]) {
10+
let mentionData = await app.service('users').get(mention._id);
11+
mentionsTable[mention._id] = mentionData;
12+
}
13+
match = mentionRegex.exec(content);
14+
}
15+
return mentionsTable;
16+
};
17+
18+
module.exports = getMentions;

server/models/notifications.model.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ module.exports = function (app) {
77
const notifications = new mongooseClient.Schema({
88
// User this notification is sent to
99
userId: { type: String, required: true },
10-
message: { type: String, required: true },
10+
type: {
11+
type: String,
12+
required: true,
13+
enum: ['comment','comment-mention','contribution-mention']
14+
},
15+
relatedUserId: { type: String },
1116
relatedContributionId: { type: String },
1217
relatedCommentId: { type: String },
1318
unseen: { type: Boolean, default: true },

server/models/users.model.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ module.exports = function (app) {
4646
language: { type: String, default: 'en' }
4747
});
4848

49+
users.index({
50+
name: 'text'
51+
});
52+
4953
return mongooseClient.model('users', users);
5054
};

server/mongoose.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function () {
1212
connectTimeoutMS: 10000,
1313
socketTimeoutMS: 10000
1414
}, function () {
15-
if (app.get('seeder').dropDatabase === true) {
15+
if (process.NODE_ENV !== 'production' && app.get('seeder').dropDatabase === true) {
1616
mongoose.connection.dropDatabase().then(() => {
1717
app.debug('>>>>>> DROPED DATABASE <<<<<<');
1818
let uploadDir = path.resolve('public/uploads');

server/seeder/base/users-admin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = (seederstore) => {
1010
1111
password: '1234',
1212
name: 'Peter',
13+
slug: 'peter',
1314
isnothere: true,
1415
timezone: 'Europe/Berlin',
1516
avatar: '{{internet.avatar}}',
@@ -24,6 +25,7 @@ module.exports = (seederstore) => {
2425
2526
password: '1234',
2627
name: 'Hans',
28+
slug: 'hans',
2729
isnothere: true,
2830
timezone: 'Europe/Berlin',
2931
avatar: '{{internet.avatar}}',

server/services/comments/comments.hooks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
const { isVerified } = require('feathers-authentication-management').hooks;
1010
const createExcerpt = require('../../hooks/create-excerpt');
1111
const createNotifications = require('./hooks/create-notifications');
12+
const createMentionNotifications = require('./hooks/create-mention-notifications');
1213
const _ = require('lodash');
1314

1415
const userSchema = {
@@ -70,6 +71,7 @@ module.exports = {
7071
],
7172
get: [],
7273
create: [
74+
createMentionNotifications(),
7375
createNotifications()
7476
],
7577
update: [],

0 commit comments

Comments
 (0)