V1 folder created For auth Data project, trash, home page based on the token and role based
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
import { Request, Response } from "express";
|
||||
import { RecentlyAdded, searchProject, searchTrashProject } from "../../../shared/services/home/homeService.ts";
|
||||
import { AuthenticatedRequest } from "../../../shared/utils/token.ts";
|
||||
import {
|
||||
RecentlyAdded,
|
||||
searchProject,
|
||||
searchTrashProject,
|
||||
} from "../../../shared/services/home/homeService.ts";
|
||||
|
||||
export const recentDataController = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization,role } = req.user||{};
|
||||
if (!userId || !organization||!role) {
|
||||
const { userId, organization } = req.params;
|
||||
if (!userId || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RecentlyAdded({ userId, organization,role });
|
||||
const result = await RecentlyAdded({ userId, organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
@@ -45,7 +48,10 @@ export const recentDataController = async (
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
export const searchProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
@@ -92,7 +98,10 @@ export const searchProjectController = async (req: Request, res: Response): Prom
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchTrashProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
export const searchTrashProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
@@ -138,4 +147,4 @@ export const searchTrashProjectController = async (req: Request, res: Response):
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,27 +6,20 @@ import {
|
||||
updateProject,
|
||||
viewProject,
|
||||
} from "../../../shared/services/project/project-Services.ts";
|
||||
import { AuthenticatedRequest } from "../../../shared/utils/token.ts";
|
||||
|
||||
export const createProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
console.log("req.user: ", req.user);
|
||||
const { projectUuid, thumbnail } = req.body;
|
||||
if (!req.user || !req.user.userId || !req.user.organization) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectUuid || !thumbnail) {
|
||||
const { projectUuid, userId, thumbnail, organization } = req.body;
|
||||
if (!projectUuid || !userId || !thumbnail || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await createProject({ ...req.body, userId, organization });
|
||||
const result = await createProject(req.body);
|
||||
|
||||
switch (result.status) {
|
||||
case "project_exists":
|
||||
@@ -61,19 +54,18 @@ export const createProjectController = async (
|
||||
}
|
||||
};
|
||||
export const GetProjects = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
// const { userId, organization } = req.params;
|
||||
if (!userId || !organization || !role) {
|
||||
const { userId, organization } = req.params;
|
||||
if (!userId || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await GetAllProjects({ userId, organization, role });
|
||||
const result = await GetAllProjects({ userId, organization });
|
||||
switch (result?.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
@@ -100,34 +92,19 @@ export const GetProjects = async (
|
||||
}
|
||||
};
|
||||
export const RemoveProject = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
// const { organization, userId } = req.body;
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectId || !organization || !userId || !role) {
|
||||
const { organization, userId } = req.body;
|
||||
if (!projectId || !organization || !userId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
const result = await DeleteProject({ projectId, organization, userId });
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
@@ -158,13 +135,13 @@ export const RemoveProject = async (
|
||||
}
|
||||
};
|
||||
export const updateProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
const { projectId, projectName, thumbnail } = req.body;
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
const { projectId, organization, projectName, thumbnail, userId } =
|
||||
req.body;
|
||||
if (!userId || !organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -176,7 +153,6 @@ export const updateProjectController = async (
|
||||
userId,
|
||||
projectName,
|
||||
thumbnail,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
@@ -208,25 +184,14 @@ export const updateProjectController = async (
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const ViewData = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
export const ViewData = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
const { projectId } = req.query as {
|
||||
const { projectId, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
userId: string;
|
||||
};
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
if (!userId || !organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -236,7 +201,6 @@ export const ViewData = async (
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
|
||||
@@ -3,21 +3,20 @@ import {
|
||||
TrashDatas,
|
||||
RestoreTrashData,
|
||||
} from "../../../shared/services/trash/trashService.ts";
|
||||
import { AuthenticatedRequest } from "../../../shared/utils/token.ts";
|
||||
|
||||
export const GetTrashList = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
if (!organization || !role || !userId) {
|
||||
const { organization } = req.query as { organization: string };
|
||||
if (!organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await TrashDatas({ organization, role, userId });
|
||||
const result = await TrashDatas({ organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "Trash is Empty":
|
||||
@@ -29,6 +28,7 @@ export const GetTrashList = async (
|
||||
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
// message: "Project created Successfully",
|
||||
TrashDatas: result.ListDatas,
|
||||
});
|
||||
break;
|
||||
@@ -47,26 +47,22 @@ export const GetTrashList = async (
|
||||
};
|
||||
|
||||
export const RestoreTrash = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
const { projectId } = req.query as {
|
||||
const { organization, projectId } = req.query as {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
};
|
||||
if (!organization || !projectId || !role || !userId) {
|
||||
console.log("organization: ", organization);
|
||||
if (!organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RestoreTrashData({
|
||||
organization,
|
||||
projectId,
|
||||
role,
|
||||
userId,
|
||||
});
|
||||
const result = await RestoreTrashData({ organization, projectId });
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
|
||||
Reference in New Issue
Block a user