Skip to content

Commit

Permalink
fix:starred files endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tunjii10 committed Sep 24, 2021
1 parent cab7e47 commit 2029afb
Show file tree
Hide file tree
Showing 3 changed files with 11,064 additions and 14,428 deletions.
26 changes: 14 additions & 12 deletions backend/controllers/file.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ exports.fileDetails = async (req, res) => {
exports.fileUpdate = async (req, res) => {
const { id: fileId } = req.params;
const { data: [file] } = await File.fetchOne({ _id: fileId });

if (!file) throw new NotFoundError();

await File.update(fileId, body);
Expand Down Expand Up @@ -256,21 +256,23 @@ exports.searchFileByIsDeleted = async (req, res) => {

// handle file searching by is starred is true
exports.searchStarredFiles = async (req, res) => {
try {
const { data } = await File.fetchAll();
const allFiles = await File.fetchAll();

if (!allFiles) throw new InternalServerError()

// loop through response object and check if isStarred is true
const starredFiles = [];
data.map((data) => {
return data.isStarred ? starredFiles.push(data) : null;
});
const data = allFiles.data.filter(file => {

response = await RealTime.publish('starred_files', starredFiles)
return file.isStarred === true;

return res.status(200).json({ status: 200, statusText: 'success', ...response });
})


} catch (error) {
return res.send({ error })
if ((data.length)<1) {
await RealTime.publish('starred_files', {})
return res.status(200).send(appResponse('No Starred File(s)!', {}, true));
} else {
await RealTime.publish('starred_files',data)
res.status(200).send(appResponse("Starred files", data, true));
}
}

Expand Down
Loading

0 comments on commit 2029afb

Please sign in to comment.