Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notification #148

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b7b3a1c
feat: database schema for notification
Aashish-Upadhyay-101 Nov 11, 2023
e72bbb5
feat: webhook schema
Aashish-Upadhyay-101 Nov 11, 2023
2e47dc4
feat: internal notification webhook
Aashish-Upadhyay-101 Nov 11, 2023
84a808f
feat: notification service sent event
Aashish-Upadhyay-101 Nov 11, 2023
4eb7281
feat: webhook triggers
Aashish-Upadhyay-101 Nov 11, 2023
1690c33
feat: document view notification
Aashish-Upadhyay-101 Nov 17, 2023
ed68dd4
Merge remote-tracking branch 'refs/remotes/origin/main' into feat-not…
Aashish-Upadhyay-101 Nov 17, 2023
eb5579c
chore: link enableNotifcation moved to notification handler
Aashish-Upadhyay-101 Nov 17, 2023
57017bb
feat: webhook schema
Aashish-Upadhyay-101 Nov 18, 2023
f82c760
chore: internal webhook moved to notifications webhook
Aashish-Upadhyay-101 Nov 18, 2023
4f52039
Merge remote-tracking branch 'refs/remotes/origin/feat-notification' …
Aashish-Upadhyay-101 Nov 18, 2023
545b9bc
feat: api endpoint for creating and geting webhooks
Aashish-Upadhyay-101 Nov 18, 2023
d5529ef
feat: sidebar webhook item
Aashish-Upadhyay-101 Nov 18, 2023
9a41ce6
feat: webhook page
Aashish-Upadhyay-101 Nov 18, 2023
e3c82d3
feat: webhook page
Aashish-Upadhyay-101 Nov 18, 2023
c322fb9
feat: webhook delete
Aashish-Upadhyay-101 Nov 18, 2023
fb03648
fix: handler function typo
Aashish-Upadhyay-101 Nov 18, 2023
cf06142
Merge branch 'feat-notification' of https://github.com/Aashish-Upadhy…
Aashish-Upadhyay-101 Nov 18, 2023
20b87b8
Merge branch 'feat-webhook' into feat-notification
Aashish-Upadhyay-101 Nov 18, 2023
ae76477
fix: notification ordering fix
Aashish-Upadhyay-101 Nov 18, 2023
c7e1c54
Merge branch 'mfts:main' into main
Aashish-Upadhyay-101 Nov 22, 2023
975251e
fix: minor typos and few changes
Aashish-Upadhyay-101 Nov 22, 2023
a0220af
fix: webhook and notification scoped by Team
Aashish-Upadhyay-101 Nov 23, 2023
dea2d36
fix: webhook delete api errors
Aashish-Upadhyay-101 Nov 23, 2023
abc3a07
Merge branch 'main' of https://github.com/Aashish-Upadhyay-101/paperm…
Aashish-Upadhyay-101 Dec 5, 2023
8cbc7ff
chore: notification cleanup
Aashish-Upadhyay-101 Dec 6, 2023
4158e7e
feat: document uploaded event
Aashish-Upadhyay-101 Dec 6, 2023
2415beb
feat: document deleted webhook
Aashish-Upadhyay-101 Dec 7, 2023
7c3dbcc
db migration
Aashish-Upadhyay-101 Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: api endpoint for creating and geting webhooks
Aashish-Upadhyay-101 committed Nov 18, 2023
commit 545b9bc38f00d7f3a21f9a852b97c46b9d28bf63
55 changes: 55 additions & 0 deletions pages/api/webhooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth";
import { authOptions } from "../auth/[...nextauth]";
import { CustomUser } from "@/lib/types";
import prisma from "@/lib/prisma";
import { errorhandler } from "@/lib/errorHandler";

export async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") {
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}

const userId = (session.user as CustomUser).id;

const { targetUrl, events } = req.body;

try {
const webhook = await prisma.webhook.create({
data: {
userId,
targetUrl,
events,
}
})

return res.status(201).json(webhook);
}catch (error) {
errorhandler(error, res);
}
}
else if (req.method === "GET") {
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}

const userId = (session.user as CustomUser).id;

try {
const webhooks = await prisma.webhook.findMany({
where: {
userId,
}
})
return res.status(200).json(webhooks);
}catch (error) {
errorhandler(error, res);
}
} else {
res.setHeader("Allow", ["GET", "POST"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
}