Skip to content

Commit

Permalink
58. Comments in API routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Soumyadas15 committed Mar 8, 2024
1 parent 7f8cb1d commit 79e5b91
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 65 deletions.
8 changes: 8 additions & 0 deletions app/api/audits/[auditId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { db } from "@/lib/db";
import { initialProfile } from "@/lib/initial-profile";


/**
* Deletes an audit record from the database.
* Only auditors can delete audit records.
*
* @param auditId - The ID of the audit record to delete.
* @returns A response indicating whether the deletion was successful.
*/

interface IParams {
auditId?: string;
}
Expand Down
27 changes: 27 additions & 0 deletions app/api/audits/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { db } from "@/lib/db";
import { initialProfile } from "@/lib/initial-profile";



/**
* Handles POST requests to the /api/audit endpoint.
*
* @param request - the incoming HTTP request
* @returns a response containing the created audit, or an error response
*/


export async function POST(request: Request) {
try {
const currentUser = await initialProfile();
Expand Down Expand Up @@ -46,6 +55,15 @@ export async function POST(request: Request) {
}
}

/**
* Handles GET requests to the /api/audit endpoint.
*
* @param request - the incoming HTTP request
* @returns a response containing a list of audits, or an error response
*/



export async function GET(request: Request) {
try {
const queryParams = new URL(request.url).searchParams;
Expand All @@ -71,6 +89,15 @@ export async function GET(request: Request) {
}
}


/**
* Handles PUT requests to the /api/audit endpoint.
*
* @param request - the incoming HTTP request
* @returns a response containing the updated audit, or an error response
*/


export async function PUT(request: Request) {
try {
const body = await request.json();
Expand Down
9 changes: 9 additions & 0 deletions app/api/feedbacks/[feedbackId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { db } from "@/lib/db";
import { initialProfile } from "@/lib/initial-profile";



/**
* Deletes a feedback entry in the database.
* Only users with the "ADMIN" or "MANAGER" role can create feedback.
*
* @param request - the incoming request
* @returns a response containing the created feedback, or an error message
*/

interface IParams {
feedbackId?: string;
}
Expand Down
44 changes: 19 additions & 25 deletions app/api/feedbacks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { db } from "@/lib/db";
import { initialProfile } from "@/lib/initial-profile";


/**
* Creates a new feedback entry in the database.
* Only users with the "ADMIN" or "MANAGER" role can create feedback.
*
* @param request - the incoming request
* @returns a response containing the created feedback, or an error message
*/


export async function POST(request: Request) {
try {
const currentUser = await initialProfile();
Expand Down Expand Up @@ -53,30 +62,15 @@ export async function POST(request: Request) {
}
}

// export async function GET(request: Request) {
// try {
// const queryParams = new URL(request.url).searchParams;
// const projectId = queryParams.get('projectId');

// if (!projectId) {
// return new Response('Missing projectId query parameter', { status: 400 });
// }

// const audits = await db.audit.findMany({
// where: {
// projectId: projectId,
// },
// });

// return new Response(JSON.stringify(audits), { status: 200, headers: { 'Content-Type': 'application/json' } });
// } catch (error) {
// if (error instanceof Error) {
// return new Response(error.message, { status: 500 });
// } else {
// return new Response('An unknown error occurred', { status: 500 });
// }
// }
// }

/**
* Updates feedback entry in the database.
* Only users with the "ADMIN" or "MANAGER" role can update feedback.
*
* @param request - the incoming request
* @returns a response containing the created feedback, or an error message
*/


export async function PUT(request: Request) {
try {
Expand All @@ -90,7 +84,7 @@ export async function PUT(request: Request) {
if (!(currentUser.role === "ADMIN" || currentUser.role === "MANAGER")) {
return new Response('You dont have the necessary permissions', { status: 404 });
}

const content = await request.json();
const { feedbackId, type, body, action, date, closureDate } = content;

Expand Down
45 changes: 18 additions & 27 deletions app/api/moms/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { db } from "@/lib/db";
import { initialProfile } from "@/lib/initial-profile";


/**
* Creates an MoM.
* Only users with the "ADMIN" or "MANAGER" role can update MoMs.
*
* @param request - the incoming request
* @returns a response indicating the status and content of the updated MoM
*/


export async function POST(request: Request) {
try {
const currentUser = await initialProfile();
Expand Down Expand Up @@ -34,8 +43,6 @@ export async function POST(request: Request) {
return new Response('Project not found', { status: 400 });
}

console.log(intDuration)

const mom = await db.mom.create({
data: {
date: date,
Expand All @@ -57,30 +64,15 @@ export async function POST(request: Request) {
}
}

// export async function GET(request: Request) {
// try {
// const queryParams = new URL(request.url).searchParams;
// const projectId = queryParams.get('projectId');

// if (!projectId) {
// return new Response('Missing projectId query parameter', { status: 400 });
// }

// const audits = await db.audit.findMany({
// where: {
// projectId: projectId,
// },
// });

// return new Response(JSON.stringify(audits), { status: 200, headers: { 'Content-Type': 'application/json' } });
// } catch (error) {
// if (error instanceof Error) {
// return new Response(error.message, { status: 500 });
// } else {
// return new Response('An unknown error occurred', { status: 500 });
// }
// }
// }

/**
* Updates an existing MoM.
* Only users with the "ADMIN" or "MANAGER" role can update MoMs.
*
* @param request - the incoming request
* @returns a response indicating the status and content of the updated MoM
*/


export async function PUT(request: Request) {
try {
Expand Down Expand Up @@ -114,7 +106,6 @@ export async function PUT(request: Request) {
return new Response('MoM not found', { status: 404 });
}

console.log(mom)

const updatedMom = await db.mom.update({
where: {
Expand Down
38 changes: 25 additions & 13 deletions components/pages/projects/ProjectNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { usePathname, useRouter } from "next/navigation";
import { ProjectNavbarItem } from "./ProjectNavbarItem";
import useAuditModal from "@/hooks/createModalHooks/useAuditModal";
import { Button } from "@/components/reusable/Button";
import { Plus } from "lucide-react";
import { ArrowRightIcon, Plus } from "lucide-react";
import useResourceModal from "@/hooks/createModalHooks/useResourceModal";
import useFeedbackModal from "@/hooks/createModalHooks/useFeedbackModal";
import useUpdateModal from "@/hooks/createModalHooks/useUpdateModal";
import useEditUpdateModal from "@/hooks/editModalHooks/useEditUpdateModa";
import useMomModal from "@/hooks/createModalHooks/useMomModal";
import axios from "axios";
import toast from "react-hot-toast";
import { useState } from "react";

interface ProjectNavbarProps {
project: any;
Expand All @@ -23,9 +24,16 @@ export const ProjectNavbar = ({
user,
}: ProjectNavbarProps) => {

const [navbarPosition, setNavbarPosition] = useState('justify-start');

const toggleNavbar = () => {
setNavbarPosition(navbarPosition === 'justify-start' ? 'justify-end' : 'justify-start');
}

const pathname = usePathname();
const router = useRouter();


const auditModal = useAuditModal();
const resourceModal = useResourceModal();
const feedbackModal = useFeedbackModal();
Expand Down Expand Up @@ -71,19 +79,23 @@ export const ProjectNavbar = ({
];

return (
<div className="w-full h-[2rem] flex items-center justify-between gap-5 mt-3 ">
<div className="w-[80%] h-full flex items-center justify-between gap-5 overflow-hidden overflow-x-scroll scrollbar-hide">
<div className="flex items-center gap-10">
{routes.map((route, index) => (
<ProjectNavbarItem
key={index}
label={route.slice(1).charAt(0).toUpperCase() + route.slice(2)}
to={`/main/projects/${project.id}${route}`}
isActive={pathname?.startsWith(`/main/projects/${project.id}${route}`)}
/>
))}
<div className="w-full h-[2rem] flex items-center justify-between gap-5 mt-3 ">
<div className="w-[80%] h-full flex items-center justify-between">
<div className={`w-[95%] h-full flex items-center ${navbarPosition} transition gap-5 overflow-hidden overflow-x-scroll scrollbar-hide`}>
<div className="flex items-center gap-10">
{routes.map((route, index) => (
<ProjectNavbarItem
key={index}
label={route.slice(1).charAt(0).toUpperCase() + route.slice(2)}
to={`/main/projects/${project.id}${route}`}
isActive={pathname?.startsWith(`/main/projects/${project.id}${route}`)}
/>
))}
</div>
</div>
<div>
<ArrowRightIcon size={20} className="font-bold hover:cursor-pointer hover:opacity-75" onClick={toggleNavbar}/>
</div>

</div>
{(user.role === "MANAGER" || user.role === "ADMIN") ? (
<div>
Expand Down

0 comments on commit 79e5b91

Please sign in to comment.