Skip to content

Commit

Permalink
Merge pull request #733 from marchhq/testing-pr
Browse files Browse the repository at this point in the history
feat: marge type and source
  • Loading branch information
sajdakabir authored Dec 25, 2024
2 parents 20d0d70 + 06a2437 commit 54f5dae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
12 changes: 6 additions & 6 deletions apps/backend/src/controllers/lib/item.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createItem, filterItems, updateItem, getItem, getItemFilterByLabel, searchItemsByTitle, getAllItemsByBloack, createInboxItem, getThisWeekItemsByDateRange, getUserFavoriteItems, getSubItems, getItemsByType, getItemsBySource } from "../../services/lib/item.service.js";
import { createItem, filterItems, updateItem, getItem, getItemFilterByLabel, searchItemsByTitle, getAllItemsByBloack, createInboxItem, getThisWeekItemsByDateRange, getUserFavoriteItems, getSubItems, getItemsByTypeAndSource, getItemsBySource } from "../../services/lib/item.service.js";
import { linkPreviewGenerator } from "../../services/lib/linkPreview.service.js";

const extractUrl = (text) => {
Expand Down Expand Up @@ -234,14 +234,14 @@ const getSubItemsController = async (req, res, next) => {
}
};

const getItemsByTypeController = async (req, res, next) => {
const getItemsByTypeAndSourceController = async (req, res, next) => {
try {
const user = req.user._id;
const { slug } = req.params;
const items = await getItemsByType(user, slug);
const { type, source } = req.query;
const items = await getItemsByTypeAndSource(user, { type, source });
res.json({
items
})
});
} catch (error) {
next(error);
}
Expand Down Expand Up @@ -270,6 +270,6 @@ export {
getThisWeekItemsByDateRangeController,
getUserFavoriteItemsController,
getSubItemsController,
getItemsByTypeController,
getItemsByTypeAndSourceController,
getItemsBySourceController
}
4 changes: 2 additions & 2 deletions apps/backend/src/routers/lib/common.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
getThisWeekItemsByDateRangeController,
getUserFavoriteItemsController,
getSubItemsController,
getItemsByTypeController,
getItemsByTypeAndSourceController,
getItemsBySourceController
} from "../../controllers/lib/item.controller.js";

Expand Down Expand Up @@ -59,6 +59,7 @@ router.route("/today/").get(getUserTodayItemsController);
router.route("/overdue/").get(getUserOverdueItemsController);
router.route("/favorite/").get(getUserFavoriteItemsController);
router.route("/setDate/").post(moveItemtoDateController);
router.route("/items/").get(getItemsByTypeAndSourceController);
router.route("/:date/").get(getUserItemsByDateController);

/* Journal Routes
Expand All @@ -75,7 +76,6 @@ router.route("/items/search/").get(searchItemsByTitleController);
router.route("/items/filter/").get(filterItemsController);
router.route("/items/source/").get(getItemsBySourceController);
router.route("/items/all/").get(getAllitemsController);
router.route("/items/:slug").get(getItemsByTypeController);

/* Asset Management Routes
-------------------------------------------------- */
Expand Down
19 changes: 13 additions & 6 deletions apps/backend/src/services/lib/item.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,18 @@ const getSubItems = async (user, parentId) => {
return subItems;
};

const getItemsByType = async (user, slug) => {
const items = await Item.find({
type: slug,
user
})
const getItemsByTypeAndSource = async (user, { type, source }) => {
const query = { user };

if (type) {
query.type = type;
}

if (source) {
query.source = source;
}

const items = await Item.find(query);
return items;
}

Expand Down Expand Up @@ -414,6 +421,6 @@ export {
getThisWeekItemsByDateRange,
getUserFavoriteItems,
getSubItems,
getItemsByType,
getItemsByTypeAndSource,
getItemsBySource
}

0 comments on commit 54f5dae

Please sign in to comment.