Skip to content

Commit e82454b

Browse files
committed
Merge branches 'develop' and 'feature/NEXT-250' of https://team.human-connection.org/bitbucket/scm/hc/hc-api-feathers into feature/NEXT-250
# Conflicts: # server/hooks/create-excerpt.js
2 parents 8a71247 + 8856252 commit e82454b

29 files changed

+622
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ node_modules
3232
.project
3333
.classpath
3434
.c9/
35+
.vscode
3536
*.launch
3637
.settings/
3738
*.sublime-workspace

.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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,23 @@
3333
"yarn": ">= 0.18.0"
3434
},
3535
"scripts": {
36-
"clear": "shx rm -Rf tmp",
36+
"clear": "del tmp",
3737
"test": "npm run eslint && npm run mocha",
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",
@@ -88,13 +95,15 @@
8895
"serve-favicon": "~2.4.5",
8996
"shortid": "~2.2.8",
9097
"slug": "~0.9.1",
98+
"trunc-html": "^1.1.2",
9199
"winston": "~3.0.0-rc1"
92100
},
93101
"devDependencies": {
94102
"babel-eslint": "~8.2.1",
95103
"concurrently": "~3.5.1",
96104
"eslint": "~4.16.0",
97-
"mocha": "~4.0.1",
105+
"istanbul": "^0.4.5",
106+
"mocha": "^5.0.0",
98107
"nodemon": "~1.14.11",
99108
"shx": "^0.2.2",
100109
"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/hooks/create-excerpt.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
/* eslint-disable */
22

33
// https://github.com/yangsibai/node-html-excerpt
4-
const excerpt = require('html-excerpt');
4+
// const excerpt = require('html-excerpt');
5+
const trunc = require('trunc-html');
56

6-
module.exports = function (options = {
7-
field: 'content',
8-
length: 120
9-
}) { // eslint-disable-line no-unused-vars
7+
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
108
return function (hook) {
11-
console.log('TRY TO CREATE EXCERPT');
12-
console.log('field', options.field);
13-
if(!options.field || !hook.data[options.field]) return hook;
14-
15-
if(!hook.data || !hook.data[options.field]) {
9+
if(!hook.data || !hook.data.content) {
1610
return hook;
1711
}
1812
/* eslint no-use-before-define: 0 */ // --> OFF
19-
const text = hook.data[options.field]
20-
.replace(/\<br\>|\<\/br\>|\<\/ br\>|<br \/\>|\<\/(strong|b|h[1-6])>/ig, "\n")
21-
.replace(/(<([^>]+)>)/ig, '');
22-
hook.data[`${options.field}Excerpt`] = excerpt.text(text, options.length, '...');
13+
const content = hook.data.content
14+
.replace(/\<br\>|\<\/br\>|\<\/ br\>|\<br\>|\<br\\\>|\<p\>|\<\/p\>/ig, "\n")
15+
.replace(/\<(strong|b|i|blockquote|pre|em|u|h[1-6])>|\<\/(strong|b|i|blockquote|pre|em|u|h[1-6])>/ig, '')
16+
.replace(/\<p\>\<br\>\<\/p\>/ig, ' ')
17+
.replace(/(\ )[2,]/ig, ' ')
18+
.trim();
19+
hook.data.contentExcerpt = trunc(content, 120, {
20+
ignoreTags: ['img', 'script']
21+
}).html;
22+
23+
hook.data.content = hook.data.content
24+
.replace(/(\ )[2,]/ig, ' ')
2325
return Promise.resolve(hook);
2426
};
2527
};

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');

0 commit comments

Comments
 (0)