-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:nimit9/cms-new into feat/bookmarks
- Loading branch information
Showing
21 changed files
with
405 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
name: Bug | ||
about: Create a report to help us improve | ||
title: "bug: " | ||
labels: bug | ||
assignees: '' | ||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Do something | ||
2. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots or GIFs** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Info (please complete the following information):** | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
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,19 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: 'feature: ' | ||
labels: enhancement | ||
assignees: '' | ||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
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,9 @@ | ||
### PR Fixes: | ||
- 1 | ||
- 2 | ||
|
||
Resolves #[Issue Number if there] | ||
|
||
### Checklist before requesting a review | ||
- [ ] I have performed a self-review of my code | ||
- [ ] I assure there is no similar/duplicate pull request regarding same issue |
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,80 @@ | ||
'use server'; | ||
import db from '@/db'; | ||
import { Cache } from '@/db/Cache'; | ||
import { getAllCourses } from '@/db/course'; | ||
import { authOptions } from '@/lib/auth'; | ||
import { checkUserEmailForPurchase } from '@/utiles/appx-check-mail'; | ||
import { Course } from '@prisma/client'; | ||
import { getServerSession } from 'next-auth'; | ||
|
||
type RefreshDbFn = (args: { userId: string; email: string }) => Promise<{ | ||
error: boolean; | ||
message: string; | ||
}>; | ||
|
||
export const refreshDb: RefreshDbFn = async () => { | ||
const session = await getServerSession(authOptions); | ||
const email = session?.user.email || ''; | ||
const userId = session?.user.id; | ||
|
||
if (!email) { | ||
return { | ||
error: true, | ||
message: 'You are not logged in', | ||
}; | ||
} | ||
|
||
// Only allow user to refetch every minute | ||
if (Cache.getInstance().get('rate-limit', [email])) { | ||
return { | ||
error: true, | ||
message: 'Wait sometime before refetching', | ||
}; | ||
} | ||
|
||
const allCourses = (await getAllCourses()) as Course[]; | ||
|
||
// Check which course the user has purchased | ||
const userCourses = await db.userPurchases.findMany({ | ||
where: { | ||
userId, | ||
}, | ||
}); | ||
|
||
const coursesWithoutUser = allCourses.filter((course) => { | ||
return !userCourses.some((userCourse) => userCourse.courseId === course.id); | ||
}); | ||
|
||
const responses: Course[] = []; | ||
|
||
const promises = coursesWithoutUser | ||
.filter((x) => !x.openToEveryone) | ||
.map(async (course) => { | ||
const courseId = course.appxCourseId.toString(); | ||
const data = await checkUserEmailForPurchase(email, courseId); | ||
|
||
if (data.data === '1') { | ||
responses.push(course); | ||
} | ||
}); | ||
|
||
await Promise.all(promises); | ||
|
||
responses.forEach(async (res) => { | ||
try { | ||
await db.userPurchases.create({ | ||
data: { | ||
userId, | ||
courseId: res.id, | ||
}, | ||
}); | ||
} catch { | ||
return { error: true, message: 'Unable to insert courses' }; | ||
} | ||
}); | ||
|
||
Cache.getInstance().evict('courses', [email]); | ||
Cache.getInstance().set('rate-limit', [email], true, 60); | ||
|
||
return { error: false, message: 'Refetched Courses' }; | ||
}; |
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,21 @@ | ||
import { NotionAPI } from 'notion-client'; | ||
import db from '@/db'; | ||
const notion = new NotionAPI(); | ||
import PrintNotes from '@/components/print/PrintNotes'; | ||
|
||
export default async function PrintNotion({ | ||
params: { contentId }, | ||
}: { | ||
params: { contentId: string }; | ||
}) { | ||
const notionMetadata = await db.notionMetadata.findFirst({ | ||
where: { | ||
contentId: parseInt(contentId, 10), | ||
}, | ||
}); | ||
|
||
if (notionMetadata?.notionId) { | ||
const recordMap = await notion.getPage(notionMetadata?.notionId); | ||
return <PrintNotes recordMap={recordMap} />; | ||
} | ||
} |
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,31 @@ | ||
'use client'; | ||
import { refreshDb } from '@/actions/refresh-db'; | ||
import { Button } from './ui/button'; | ||
import { toast } from 'sonner'; | ||
import { useSession } from 'next-auth/react'; | ||
|
||
export function RefreshDb() { | ||
const session = useSession(); | ||
console.log(session); | ||
|
||
const handleClick = async () => { | ||
// @ts-ignore | ||
const res = await refreshDb({ userId: session.data.user.id }); | ||
if (res.error) { | ||
toast.error(res.message); | ||
} else { | ||
toast.info(res.message); | ||
} | ||
}; | ||
|
||
if (session.status === 'loading') return <>Loading...</>; | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<h1>Don't see all your courses?</h1> | ||
<Button className="dark:text-white" onClick={handleClick}> | ||
Refresh Database | ||
</Button> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.