-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
186 additions
and
69 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Client } from "@notionhq/client"; | ||
import prisma from "lib/prisma"; | ||
import { NextApiResponse } from "next"; | ||
import { createRouter } from "next-connect"; | ||
|
||
import { | ||
auth, | ||
onError, | ||
onNoMatch, | ||
NextApiRequestWithUser, | ||
} from "utils/apiUtils"; | ||
|
||
const router = createRouter<NextApiRequestWithUser, NextApiResponse>(); | ||
|
||
router.use(auth); | ||
|
||
router.get(async (req, res) => { | ||
const pageId = req.query.pageId; | ||
|
||
if (typeof pageId !== "string") { | ||
return res.status(200).json({ | ||
isTweeted: false, | ||
}); | ||
} | ||
|
||
const { notion: notionResponse } = (await prisma.user.findUnique({ | ||
where: { | ||
id: req.user.id, | ||
}, | ||
include: { | ||
notion: true, | ||
}, | ||
}))!; | ||
|
||
if (!notionResponse) { | ||
return res.status(400).json({ error: "Notion is not configured" }); | ||
} | ||
|
||
const notion = new Client({ | ||
auth: notionResponse?.accessToken, | ||
}); | ||
|
||
const { id } = ( | ||
await notion.search({ | ||
page_size: 1, | ||
query: pageId, | ||
}) | ||
).results[0]; | ||
|
||
const notionPageId = ( | ||
await prisma.twitterThreads.findUnique({ | ||
where: { | ||
notionPageId: id, | ||
}, | ||
}) | ||
)?.notionPageId; | ||
|
||
if (notionPageId) { | ||
return res.status(200).json({ | ||
isTweeted: true, | ||
}); | ||
} | ||
|
||
return res.status(200).json({ | ||
isTweeted: false, | ||
}); | ||
}); | ||
|
||
export default router.handler({ | ||
onError, | ||
onNoMatch, | ||
}); |
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