Skip to content

Commit

Permalink
fixing npm test api error
Browse files Browse the repository at this point in the history
  • Loading branch information
tu2463 committed Oct 10, 2024
1 parent 773cb64 commit 15eceae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,16 @@ topicsAPI.unfollow = async function (caller, data) {

topicsAPI.favorite = async function (caller, data) {
await topics.favorite(data.tid, caller.uid);

const response = { status: "success", message: "Topic favorited successfully" };
return response;
};

topicsAPI.unfavorite = async function (caller, data) {
await topics.unfavorite(data.tid, caller.uid);

const response = { status: "success", message: "Topic favorited successfully" };
return response;
};

topicsAPI.updateTags = async (caller, { tid, tags }) => {
Expand Down
24 changes: 16 additions & 8 deletions src/controllers/write/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ Topics.favorite = async (req, res) => {
await db.setAdd(`uid:${uid}:favorites`, tid);
await db.sortedSetAdd(`tid:${tid}:favoritedBy`, Date.now(), uid);

helpers.formatApiResponse(200, res, { message: 'Topic added to favorites successfully' });
} catch (err) {
helpers.formatApiResponse(500, res, { error: err.message });
}
helpers.formatApiResponse(200, res, {
status: 'success',
message: 'Topic added to favorites successfully',
response: {},
});
} catch (err) {
helpers.formatApiResponse(500, res, { status: 'error', message: err.message });
}
};

Topics.unfavorite = async (req, res) => {
Expand All @@ -124,10 +128,14 @@ Topics.unfavorite = async (req, res) => {
await db.setRemove(`uid:${uid}:favorites`, tid);
await db.sortedSetRemove(`tid:${tid}:favoritedBy`, uid);

helpers.formatApiResponse(200, res, { message: 'Topic removed from favorites successfully' });
} catch (err) {
helpers.formatApiResponse(500, res, { error: err.message });
}
helpers.formatApiResponse(200, res, {
status: 'success',
message: 'Topic removed from favorites successfully',
response: {},
});
} catch (err) {
helpers.formatApiResponse(500, res, { status: 'error', message: err.message });
}
};


Expand Down

0 comments on commit 15eceae

Please sign in to comment.