-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1342 from mfts/feat/archive-views
feat: add ability to archive views
- Loading branch information
Showing
11 changed files
with
401 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { authOptions } from "@/pages/api/auth/[...nextauth]"; | ||
import { getServerSession } from "next-auth/next"; | ||
|
||
import { errorhandler } from "@/lib/errorHandler"; | ||
import prisma from "@/lib/prisma"; | ||
import { CustomUser } from "@/lib/types"; | ||
|
||
export default async function handle( | ||
req: NextApiRequest, | ||
res: NextApiResponse, | ||
) { | ||
if (req.method === "PUT") { | ||
// PUT /api/teams/:teamId/views/:id/archive | ||
const session = await getServerSession(req, res, authOptions); | ||
if (!session) { | ||
return res.status(401).end("Unauthorized"); | ||
} | ||
|
||
const userId = (session.user as CustomUser).id; | ||
const { teamId, id } = req.query as { teamId: string; id: string }; | ||
const { isArchived } = req.body; | ||
|
||
try { | ||
const team = await prisma.team.findUnique({ | ||
where: { | ||
id: teamId, | ||
users: { some: { userId } }, | ||
}, | ||
}); | ||
|
||
if (!team) { | ||
return res.status(403).json({ error: "Unauthorized" }); | ||
} | ||
|
||
// Update the link in the database | ||
const updatedView = await prisma.view.update({ | ||
where: { id, teamId }, | ||
data: { | ||
isArchived: isArchived, | ||
}, | ||
}); | ||
|
||
if (!updatedView) { | ||
return res.status(404).json({ error: "View not found" }); | ||
} | ||
|
||
return res.status(200).json(updatedView); | ||
} catch (error) { | ||
errorhandler(error, res); | ||
} | ||
} | ||
|
||
// We only allow PUT requests | ||
res.setHeader("Allow", ["PUT"]); | ||
return res.status(405).end(`Method ${req.method} Not Allowed`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
prisma/migrations/20241029000000_add_archived_view/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "View" ADD COLUMN "isArchived" BOOLEAN NOT NULL DEFAULT false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters