Skip to content

Commit

Permalink
Merge pull request #470 from Sid-80/feat/468
Browse files Browse the repository at this point in the history
Feat/468
  • Loading branch information
subhadeeproy3902 authored Jul 14, 2024
2 parents 00e8be4 + db8e6d3 commit 362203a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
32 changes: 32 additions & 0 deletions src/app/api/files/delete/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mongoDB } from "@/lib/MongoDB";
import { AuthMiddleware } from "@/Middleware/AuthMiddleware";
import FileModel from "@/models/file";
import { NextResponse } from "next/server";

export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {

const result = await AuthMiddleware(request);

if (result instanceof NextResponse) {

try {

const { id } = params;

if (!id) return new Response("Parameters missing!!", { status: 401 });

await mongoDB();

await FileModel.deleteOne({_id:id})

return NextResponse.json('Deleted SuccessFully!!',{ status: 200 });
} catch (err) {
return NextResponse.json(`Err : ${err}`, {status:500});
}
} else {
return result;
}
}
32 changes: 32 additions & 0 deletions src/app/api/teams/delete/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mongoDB } from "@/lib/MongoDB";
import { AuthMiddleware } from "@/Middleware/AuthMiddleware";
import TeamModel from "@/models/team";
import { NextResponse } from "next/server";

export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {

const result = await AuthMiddleware(request);

if (result instanceof NextResponse) {

try {

const { id } = params;

if (!id) return new Response("Parameters missing!!", { status: 401 });

await mongoDB();

await TeamModel.deleteOne({_id:id})

return NextResponse.json('Deleted SuccessFully!!',{ status: 200 });
} catch (err) {
return NextResponse.json(`Err : ${err}`, {status:500});
}
} else {
return result;
}
}
12 changes: 7 additions & 5 deletions src/app/dashboard/_components/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Badge } from "@/components/ui/badge";
import FileStatusModal from "@/components/shared/FileStatusModal";
import { RootState } from "@/config/store";
import createAxiosInstance from "@/config/AxiosProtectedRoute";
import { updateFileUrl } from "@/lib/API-URLs";
import { deleteFileUrl, updateFileUrl } from "@/lib/API-URLs";

export interface FILE {
archive: boolean;
Expand Down Expand Up @@ -245,7 +245,6 @@ function FileList({
const [isSubmitted, setIsSubmitted] = useState(false);
const safeFileList = Array.isArray(fileList) ? fileList : [];
const pathname = usePathname();

const axiosInstance = createAxiosInstance(user.accessToken)

const sortedFiles = [...safeFileList];
Expand All @@ -261,11 +260,14 @@ function FileList({
});
}

const deleteFile = useMutation(api.files.deleteFile);
const deleteFunc = async (e: any, id: string) => {
e.stopPropagation();
await deleteFile({ _id: id as Id<"files"> });
setIsSubmitted(true);
try {
await axiosInstance.delete(`${deleteFileUrl}/${id}`)
setIsSubmitted(true);
} catch (err) {
console.log(err);
}
};


Expand Down
12 changes: 6 additions & 6 deletions src/app/dashboard/_components/SideNavBottomSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
import { RootState } from "@/config/store";
import { useSelector } from "react-redux";
import createAxiosInstance from "@/config/AxiosProtectedRoute";
import { createFileUrl } from "@/lib/API-URLs";
import { createFileUrl, deleteTeamUrl } from "@/lib/API-URLs";
import { Switch } from "@/components/ui/switch";

interface TEAM {
Expand Down Expand Up @@ -97,12 +97,12 @@ function SideNavBottomSection({getFiles, totalFiles, activeTeam }: any) {

const deleteFunc = async (e: any, id: String) => {
e.stopPropagation();
if (activeTeam.teamName === "My Org") {
toast.error("My Org can not be deleted");
return;
try {
await axiosInstance.delete(`${deleteTeamUrl}/${id}`)
setIsSubmitted(true);
} catch (err) {
console.log(err);
}
await deleteTeam({ _id: id as Id<"teams"> });
setIsSubmitted(true);
};

const handleFileInput = (val: string) => {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/API-URLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export const getTeamUrl = "/api/teams/get";
export const createFileUrl = "/api/files/create";
export const getFileUrl = "/api/files/get";
export const getFileByIdUrl = "/api/files/getFileById";
export const updateFileUrl = "/api/files/update";
export const updateFileUrl = "/api/files/update";
export const deleteFileUrl = "/api/files/delete";
export const deleteTeamUrl = "/api/teams/delete";

0 comments on commit 362203a

Please sign in to comment.