Skip to content

Commit

Permalink
feat: delete team and file
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid-80 committed Jul 14, 2024
1 parent b71f97e commit db8e6d3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 13 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;
}
}
13 changes: 7 additions & 6 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 @@ -247,8 +247,6 @@ function FileList({
const pathname = usePathname();
const axiosInstance = createAxiosInstance(user.accessToken)

const axiosInstance = createAxiosInstance(user.accessToken)

const sortedFiles = [...safeFileList];
if (sortConfig !== null) {
sortedFiles.sort((a, b) => {
Expand All @@ -262,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 db8e6d3

Please sign in to comment.