Skip to content

Commit

Permalink
Merge cd21cce into f26ee48
Browse files Browse the repository at this point in the history
  • Loading branch information
olusoladavid committed Aug 18, 2018
2 parents f26ee48 + cd21cce commit 518ccb7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/controllers/entryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class entryController {
if (!deleted.rowCount) {
res.status(404).json({ error: { message: 'Entry not found' } });
}
res.sendStatus(204);
res.status(204).json();
} catch (error) {
next(error);
}
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class userController {
fav_count: favEntries.rows.length,
created_on: user.rows[0].created_on,
push_sub: JSON.parse(user.rows[0].push_sub),
email_reminder: user.rows[0].reminderisset,
reminder_set: user.rows[0].reminderisset,
});
} catch (error) {
next(error);
Expand All @@ -112,11 +112,11 @@ class userController {

static async updateProfile(req, res, next) {
try {
const { push_sub: pushSub, email_reminder: reminderIsSet } = req.body;
const { push_sub: pushSub, reminder_set: reminderIsSet } = req.body;
const pushSubString = JSON.stringify(pushSub);
await query(queries.updateProfile, [req.authorizedUser.email,
pushSubString, reminderIsSet]);
res.sendStatus(204);
res.status(204).json();
} catch (error) {
next(error);
}
Expand Down
2 changes: 1 addition & 1 deletion server/db/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ queries.insertOneUser = 'INSERT INTO users(email, password) VALUES($1, $2) RETUR

queries.getAllEntries = `SELECT entries.id, entries.title, entries.content, entries.created_on,
entries.updated_on, entries.is_favorite FROM entries INNER JOIN users ON entries.user_id=users.id
WHERE (users.email=$1) AND ($2='all' OR entries.is_favorite='t')`;
WHERE (users.email=$1) AND ($2='all' OR entries.is_favorite='t') ORDER BY entries.created_on DESC`;

queries.getOneEntry = `SELECT entries.id, entries.title, entries.content,
entries.created_on, entries.is_favorite FROM entries INNER JOIN users ON entries.user_id = users.id
Expand Down
2 changes: 1 addition & 1 deletion server/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ validate.updateProfile = [
.isJSON()
.withMessage('Push Subscription should be JSON')
.optional(),
body('email_reminder')
body('reminder_set')
.isBoolean()
.withMessage('Email reminder preference should be boolean')
.optional(),
Expand Down
2 changes: 1 addition & 1 deletion test/sampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const sampleData = {
push_sub: JSON.stringify({ channel: 'foo' }),
},
invalidProfile: {
email_reminder: '',
reminder_set: '',
},
timestampNow: 1534258252771,
justOverADay: 24 * 3600 * 1000 + 1,
Expand Down
4 changes: 3 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let entryCreationDate; // for storing pg date of cached entry
const makeAuthHeader = authToken => `Bearer ${authToken}`;

before(async () => {
// try to create tables if they dont exist
await createTables();
// remove all entries
const task1 = await query('TRUNCATE TABLE entries CASCADE');
// remove all users
Expand Down Expand Up @@ -616,7 +618,7 @@ describe('/GET profile', () => {
expect(res).to.have.status(200);
expect(res.body).to.be.an('object');
expect(res.body).to.be.have.keys(['entries_count', 'fav_count', 'push_sub',
'email_reminder', 'email', 'created_on']);
'reminder_set', 'email', 'created_on']);
done();
});
});
Expand Down

0 comments on commit 518ccb7

Please sign in to comment.