Skip to content

Commit

Permalink
WIP: Merge with master and fix comment reporting token parsing - #70
Browse files Browse the repository at this point in the history
  • Loading branch information
tiblu committed Jan 8, 2019
1 parent 3fbeb32 commit 78d4def
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 92 deletions.
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
## 2019-01-04

* Add endpoints to read attachment json or download uploaded attachment file with proper filename by adding query parameter `?download=true`
`GET /api/users/:userId/topics/:topicId/attachments/:attachmentId`
`GET /api/topics/:topicId/attachments/:attachmentId`

## 2018-12-18

* Fix issue where missing e-mail addresses would fail adding Topics to a Group. Regression from 2018-12-10.
* Add possibility to set topics as favourites, new table is added. New API enpoints:
`POST /api/users/:userId/topics/:topicId/favourites` - to add topic as favourite
`DELETE /api/users/:userId/topics/:topicId/favourites` - to remove topic from favourites
All authorized endpoints, returning topics data, will also have favourite boolean value
* Update GET /api/users/:userId/topics endpoint to filter results by favourites https://github.com/citizenos/citizenos-fe/issues/122
* Update GET /api/v2/search endpoint to support topic filtering by status and favourites
* Add possibility to set topics as pinned, new table is added. New API enpoints:
`POST /api/users/:userId/topics/:topicId/pin` - to pin a topic
`DELETE /api/users/:userId/topics/:topicId/pin` - to remove pin from topic
All authorized endpoints, returning topics data, will also have pinned boolean value
* Update GET /api/users/:userId/topics endpoint to filter results by pinned https://github.com/citizenos/citizenos-fe/issues/122
* Update GET /api/v2/search endpoint to support topic filtering by status and pinned

## 2018-12-17

Expand Down
8 changes: 4 additions & 4 deletions db/migrations/20181213213857-create-topic-favourite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('TopicFavourites', {
return queryInterface.createTable('TopicPins', {
topicId: {
type: Sequelize.UUID,
allowNull: false,
comment: 'To what Topic this Favourite belongs to.',
comment: 'To what Topic this Pin belongs to.',
references: {
model: 'Topics',
key: 'id'
Expand All @@ -16,7 +16,7 @@ module.exports = {
userId: {
type: Sequelize.UUID,
allowNull: false,
comment: 'Which User this Favourite belongs to.',
comment: 'Which User this Pin belongs to.',
references: {
model: 'Users',
key: 'id'
Expand All @@ -28,6 +28,6 @@ module.exports = {
});
},
down: (queryInterface) => {
return queryInterface.dropTable('TopicFavourites');
return queryInterface.dropTable('TopicPins');
}
};
2 changes: 2 additions & 0 deletions db/models/Attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ module.exports = function (sequelize, DataTypes) {
});
};

Attachment.SOURCES = SOURCES;

return Attachment;
};
10 changes: 5 additions & 5 deletions db/models/TopicFavourite.js → db/models/TopicPin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
module.exports = function (sequelize, DataTypes) {

var TopicFavourite = sequelize.define(
'TopicFavourite',
var TopicPin = sequelize.define(
'TopicPin',
{
topicId: {
type: DataTypes.UUID,
allowNull: false,
comment: 'To what Topic this Favourite belongs to.',
comment: 'To what Topic this Pin belongs to.',
references: {
model: 'Topics',
key: 'id'
Expand All @@ -28,7 +28,7 @@ module.exports = function (sequelize, DataTypes) {
userId: {
type: DataTypes.UUID,
allowNull: false,
comment: 'Which User this Favourite belongs to.',
comment: 'Which User this Pin belongs to.',
references: {
model: 'Users',
key: 'id'
Expand All @@ -41,5 +41,5 @@ module.exports = function (sequelize, DataTypes) {
}
);

return TopicFavourite;
return TopicPin;
};
16 changes: 8 additions & 8 deletions routes/api/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,9 @@ module.exports = function (app) {
t.categories, \
t."endsAt", \
CASE \
WHEN tf."topicId" = t.id THEN true \
WHEN tp."topicId" = t.id THEN true \
ELSE false \
END as "favourite", \
END as "pinned", \
t.hashtag, \
t."updatedAt", \
t."createdAt", \
Expand Down Expand Up @@ -978,11 +978,11 @@ module.exports = function (app) {
WHERE "deletedAt" IS NULL \
GROUP BY "topicId" \
) AS mgc ON (mgc."topicId" = t.id) \
LEFT JOIN "TopicFavourites" tf ON tf."topicId" = t.id AND tf."userId" = :userId \
LEFT JOIN "TopicPins" tp ON tp."topicId" = t.id AND tp."userId" = :userId \
WHERE gt."groupId" = :groupId \
AND gt."deletedAt" IS NULL \
AND t."deletedAt" IS NULL \
ORDER BY "favourite" DESC \
ORDER BY "pinned" DESC \
;'
,
{
Expand Down Expand Up @@ -1019,9 +1019,9 @@ module.exports = function (app) {
t.categories, \
t."endsAt", \
CASE \
WHEN tf."topicId" = t.id THEN true \
WHEN tp."topicId" = t.id THEN true \
ELSE false \
END as "favourite", \
END as "pinned", \
t.hashtag, \
t."updatedAt", \
t."createdAt", \
Expand Down Expand Up @@ -1078,12 +1078,12 @@ module.exports = function (app) {
WHERE "deletedAt" IS NULL \
GROUP BY "topicId" \
) AS mgc ON (mgc."topicId" = t.id) \
LEFT JOIN "TopicFavourites" tf ON tf."topicId" = t.id AND tf."userId" = :userId \
LEFT JOIN "TopicPins" tp ON tp."topicId" = t.id AND tp."userId" = :userId \
WHERE gt."groupId" = :groupId \
AND gt."deletedAt" IS NULL \
AND t."deletedAt" IS NULL \
AND COALESCE(tmup.level, tmgp.level, \'none\')::"enum_TopicMemberUsers_level" > \'none\' \
ORDER BY "favourite" DESC \
ORDER BY "pinned" DESC \
; \
',
{
Expand Down
14 changes: 7 additions & 7 deletions routes/api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = function (app) {
var params = Object.keys(req.query);
var statuses;
var queryStatuses = req.query.statuses;
var favourite = req.query.favourite;
var pinned = req.query.pinned;

if (queryStatuses) {
if (!Array.isArray(queryStatuses)) {
Expand Down Expand Up @@ -162,8 +162,8 @@ module.exports = function (app) {
myTopicWhere += ' AND t.status IN (:statuses)';
}

if (favourite) {
myTopicWhere += 'AND tf."topicId" = t.id AND tf."userId" = :userId';
if (pinned) {
myTopicWhere += 'AND tp."topicId" = t.id AND tp."userId" = :userId';
}

// TODO: NOT THE MOST EFFICIENT QUERY IN THE WORLD, tune it when time.
Expand All @@ -181,9 +181,9 @@ module.exports = function (app) {
ELSE NULL \
END as "tokenJoin", \
CASE \
WHEN tf."topicId" = t.id THEN true \
WHEN tp."topicId" = t.id THEN true \
ELSE false \
END as "favourite", \
END as "pinned", \
t.categories, \
t."endsAt", \
t."createdAt", \
Expand Down Expand Up @@ -236,9 +236,9 @@ module.exports = function (app) {
) AS mgc ON (mgc."topicId" = t.id) \
LEFT JOIN "TopicVotes" tv \
ON (tv."topicId" = t.id) \
LEFT JOIN "TopicFavourites" tf ON tf."topicId" = t.id AND tf."userId" = :userId \
LEFT JOIN "TopicPins" tp ON tp."topicId" = t.id AND tp."userId" = :userId \
WHERE ' + myTopicWhere + ' \
GROUP BY t.id, tmup.level, tmgp.level, muc.count, mgc.count, tv."voteId", tf."topicId" \
GROUP BY t.id, tmup.level, tmgp.level, muc.count, mgc.count, tv."voteId", tp."topicId" \
ORDER BY t.title ASC \
LIMIT :limit \
OFFSET :offset \
Expand Down
Loading

0 comments on commit 78d4def

Please sign in to comment.