Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f44b752
Release 1.0.0 (#12)
georgeben Jan 13, 2020
6e052cf
fix: return 400 on login failure
georgeben Jan 13, 2020
8c8bfb0
fix: update email sender in confirmation email
georgeben Jan 14, 2020
b2b8111
reduce web server instances to 1 to fix memory problem
georgeben Jan 14, 2020
abf198f
fix:memory leaks (#13)
georgeben Jan 14, 2020
3fce407
report error to sentry in error handler
georgeben Jan 14, 2020
aa9a740
Error reporting (#14)
georgeben Jan 14, 2020
2c6899a
fix: correct reset password email header
georgeben Jan 18, 2020
931be4e
fix: handle malformed token errors in oauth sign in
georgeben Jan 18, 2020
b369e9a
fix: merge conflict
georgeben Jan 19, 2020
5b08ca4
fix: oauth errors from malformed jwts (#15)
georgeben Jan 19, 2020
c0e95f2
chore:add tests (#16)
georgeben Jan 20, 2020
d9902fe
fix: send emails in development (#17)
georgeben Jan 20, 2020
2389845
chore: add tests (#18)
georgeben Jan 20, 2020
e5af71c
send emails in development
georgeben Jan 20, 2020
e6fc2cd
Merge branch 'production' of github.com:georgeben/Report-Missing-Peop…
georgeben Jan 20, 2020
a0eabb0
chore: improve comments
georgeben Jan 20, 2020
3b527f9
Merge branch 'staging' of github.com:georgeben/Report-Missing-People-…
georgeben Jan 20, 2020
447a95c
Create README.md
georgeben Jan 21, 2020
2150c30
add .env.sample file
georgeben Jan 21, 2020
153f12e
Create CONTRIBUTING.md
georgeben Jan 21, 2020
36acd84
Update README.md
georgeben Jan 21, 2020
a96d9dc
chore: fix docs (#20)
georgeben Jan 21, 2020
17ff14c
fix merge conflict with master
georgeben Jan 21, 2020
c08c8a0
fix conflict with production
georgeben Mar 15, 2020
c14046e
add different twitter bot keys for different environments
georgeben Mar 16, 2020
96fe470
update case schema to no longer require age, language, residential ad…
georgeben Mar 16, 2020
e086a0d
Merge branch 'staging' of github.com:georgeben/Report-Missing-People-…
georgeben Mar 16, 2020
a965d78
Merge branch 'master' of github.com:georgeben/Report-Missing-People-A…
georgeben Mar 16, 2020
e59a081
add exit mocha file
georgeben Mar 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = function () {
twitterBotUrl: process.env.TWITTER_BOT_STAGING,
caseFolderName: 'case_photos_staging',
userFolderName: 'user_photos_staging',
twitterBotConsumerKey: process.env.BOT_CONSUMER_KEY_STAGING,
twitterBotConsumerKeySecret: process.env.BOT_CONSUMER_SECRET_STAGING,
twitterBotAccessToken: process.env.BOT_ACCESS_TOKEN_STAGING,
twitterBotAccessTokenSecret: process.env.BOT_ACCESS_TOKEN_SECRET_STAGING,
};
case 'production':
return {
Expand All @@ -33,6 +37,10 @@ module.exports = function () {
twitterBotUrl: process.env.TWITTER_BOT,
caseFolderName: 'case_photos_prod',
userFolderName: 'user_photos_prod',
twitterBotConsumerKey: process.env.BOT_CONSUMER_KEY,
twitterBotConsumerKeySecret: process.env.BOT_CONSUMER_SECRET,
twitterBotAccessToken: process.env.BOT_ACCESS_TOKEN,
twitterBotAccessTokenSecret: process.env.BOT_ACCESS_TOKEN_SECRET,
};
default:
return {
Expand All @@ -46,6 +54,10 @@ module.exports = function () {
twitterBotUrl: process.env.TWITTER_BOT_DEV,
caseFolderName: 'case_photos',
userFolderName: 'user_photos',
twitterBotConsumerKey: process.env.BOT_CONSUMER_KEY_STAGING,
twitterBotConsumerKeySecret: process.env.BOT_CONSUMER_SECRET_STAGING,
twitterBotAccessToken: process.env.BOT_ACCESS_TOKEN_STAGING,
twitterBotAccessTokenSecret: process.env.BOT_ACCESS_TOKEN_SECRET_STAGING,
};
}
};
2 changes: 1 addition & 1 deletion db/models/Case.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ caseSchema.pre('save', function (next) {

// Generate a description of the case
let description = `${this.fullname} ${this.nicknames.length > 0 ? `aka ${this.nicknames.join(',')}` : ''}`;
description += ` who is a ${this.age} year old ${this.gender.toLowerCase()} got missing on ${this.dateLastSeen.toDateString()} at ${this.addressLastSeen.formatted_address}, in ${this.addressLastSeen.state}, ${this.addressLastSeen.country}.`;
description += ` who is a ${this.age ? `${this.age} year old ` : ''} ${this.gender.toLowerCase()} got missing on ${this.dateLastSeen.toDateString()} at ${this.addressLastSeen.formatted_address}, in ${this.addressLastSeen.state}, ${this.addressLastSeen.country}.`;

this.description = description;
next();
Expand Down
2 changes: 0 additions & 2 deletions db/schemas/Case.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const caseSchema = new Schema(
nicknames: [String],
age: {
type: Number,
required: true,
},
gender: {
type: String,
Expand All @@ -37,7 +36,6 @@ const caseSchema = new Schema(
},
language: {
type: String,
required: true,
},
residentialAddress: {
location: locationSchema,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"main": "server.js",
"scripts": {
"start": "pm2-runtime start ecosystem.config.js --env production",
"test": "mocha \"./test/**/*.spec.js\" --timeout=20000 --require test/prepare --exit",
"test": "mocha test/exit-mocha.js \"./test/**/*.spec.js\" --timeout=20000 --require test/prepare --exit",
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"author": "George Benjamin",
Expand Down
44 changes: 15 additions & 29 deletions schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,40 +93,32 @@ module.exports = {
fullname: Joi.string()
.trim()
.min(2)
.required()
.pattern(fullnamePattern, 'Firstname Lastname'),
.required(),
nicknames: Joi.array().items(Joi.string()),
age: Joi.number()
.integer()
.min(1)
.required(),
.min(1),
residentialAddress: Joi.object({
location: Joi.object({
type: Joi.string()
.trim()
.required(),
.trim(),
coordinates: Joi.array()
.items(Joi.number())
.max(2)
.required(),
.max(2),
}),
formatted_address: Joi.string()
.trim()
.required(),
.trim().optional(),
country: Joi.string()
.trim()
.required(),
.trim(),
state: Joi.string()
.trim()
.required(),
}).required(),
.trim(),
}).optional(),
gender: Joi.string()
.trim()
.required()
.valid('MALE', 'FEMALE'),
language: Joi.string()
.trim()
.required()
.pattern(namePattern, 'name'),
addressLastSeen: Joi.object({
location: Joi.object({
Expand Down Expand Up @@ -166,8 +158,7 @@ module.exports = {
updateCase: Joi.object({
fullname: Joi.string()
.trim()
.min(3)
.pattern(fullnamePattern, 'Firstname Lastname'),
.min(3),
nicknames: Joi.array().items(Joi.string()),
age: Joi.number()
.integer()
Expand All @@ -181,23 +172,18 @@ module.exports = {
residentialAddress: Joi.object({
location: Joi.object({
type: Joi.string()
.trim()
.required(),
.trim(),
coordinates: Joi.array()
.items(Joi.number())
.max(2)
.required(),
.max(2),
}),
formatted_address: Joi.string()
.trim()
.required(),
.trim().optional(),
country: Joi.string()
.trim()
.required(),
.trim(),
state: Joi.string()
.trim()
.required(),
}),
.trim(),
}).optional(),
addressLastSeen: Joi.object({
location: Joi.object({
type: Joi.string()
Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function gracefulShutdown() {
.catch((err) => process.exit(err ? 1 : 0));
});
}

process.on('SIGINT', () => {
gracefulShutdown();
});
Expand Down
2 changes: 2 additions & 0 deletions services/case.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ async function updateCase(
age,
gender,
language,
residentialAddress,
addressLastSeen,
state,
country,
Expand All @@ -153,6 +154,7 @@ async function updateCase(
if (age) reportedCase.age = age;
if (gender) reportedCase.gender = gender;
if (language) reportedCase.language = language;
if (residentialAddress) reportedCase.residentialAddress = residentialAddress;
if (addressLastSeen) reportedCase.addressLastSeen = addressLastSeen;
if (state) reportedCase.state = state;
if (country) reportedCase.country = country;
Expand Down
25 changes: 15 additions & 10 deletions services/twitterbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
const Twit = require('twit');
const axios = require('axios');
const { handleError, logger } = require('../utils');
const { frontEndUrl } = require('../config')();
const {
frontEndUrl,
twitterBotConsumerKey,
twitterBotConsumerKeySecret,
twitterBotAccessToken,
twitterBotAccessTokenSecret,
} = require('../config')();

const bot = new Twit({
consumer_key: process.env.BOT_CONSUMER_KEY,
consumer_secret: process.env.BOT_CONSUMER_SECRET,
access_token: process.env.BOT_ACCESS_TOKEN,
access_token_secret: process.env.BOT_ACCESS_TOKEN_SECRET,
consumer_key: twitterBotConsumerKey,
consumer_secret: twitterBotConsumerKeySecret,
access_token: twitterBotAccessToken,
access_token_secret: twitterBotAccessTokenSecret,
});

/**
Expand All @@ -20,18 +26,17 @@ const bot = new Twit({
*/
async function tweetNewCase(data) {
try {
let image = await axios.get(
data.photoURL,
{ responseType: 'arraybuffer' },
);
let image = await axios.get(data.photoURL, { responseType: 'arraybuffer' });
let returnedB64 = Buffer.from(image.data).toString('base64');
let result = await bot.post('media/upload', { media_data: returnedB64 });
const mediaIdStr = result.data.media_id_string;
const altText = 'Missing person photo';
const meta_params = { media_id: mediaIdStr, alt_text: { text: altText } };
await bot.post('media/metadata/create', meta_params);
const params = {
status: `${data.description}. For more info, visit ${frontEndUrl}/cases/${data.slug} #HelpLookFor${data.fullname.split(' ').join('')} #HelpLookForMe`,
status: `${data.description}. For more info, visit ${frontEndUrl}/cases/${
data.slug
} #HelpLookFor${data.fullname.split(' ').join('')} #HelpLookForMe`,
media_ids: [mediaIdStr],
};
await bot.post('statuses/update', params);
Expand Down
7 changes: 7 additions & 0 deletions test/exit-mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable prefer-arrow-callback */
/* eslint-disable no-undef */

after('Exit mocha gracefully after finishing all tests execution', function () {
console.log('Ran tests, exiting!');
process.exit();
});