Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/services/projects.service.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add these filters while getting all the projects:
region: token_payload?.region,
owner: token_payload?.user_id,

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ import { constants } from "../constants";

const getAllProjects = async (req: Request) => {
const orgId = req?.params?.orgId;
//Add logic to get All Projects from DB
return [orgId];
const decodedToken = req.body.token_payload;
const { user_id = "", region = "" } = decodedToken;

const project = await ProjectModel.find({
org_id: orgId,
region,
owner: user_id,
});

if (!project) throw new NotFoundError(constants.HTTP_TEXTS.PROJECT_NOT_FOUND);

return project;
};
const getProject = async (req: Request) => {
const orgId = req?.params?.orgId;
const projectId = req?.params?.projectId;
const decodedToken = req.body.token_payload;
const { user_id = "test-123", region = "NA" } = decodedToken;
const { user_id = "", region = "" } = decodedToken;
// Find the project based on both orgId and projectId, region, owner
const project = await ProjectModel.findOne({
org_id: orgId,
Expand All @@ -36,7 +46,7 @@ const createProject = async (req: Request) => {
const orgId = req?.params?.orgId;
const { name, description } = req.body;
const decodedToken = req.body.token_payload;
const { user_id = "test-123", region = "NA" } = decodedToken;
const { user_id = "", region = "" } = decodedToken;
const projectData = {
region,
org_id: orgId,
Expand Down Expand Up @@ -68,7 +78,7 @@ const updateProject = async (req: Request) => {
const projectId = req?.params?.projectId;
const updateData = req?.body;
const decodedToken = req.body.token_payload;
const { user_id = "test-123", region = "NA" } = decodedToken;
const { user_id = "", region = "" } = decodedToken;
// Find the project based on both orgId and projectId
const project = await ProjectModel.findOne({
org_id: orgId,
Expand Down