Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
100 changes: 50 additions & 50 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
.env
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
bun.lockb

# docker volume
/postgres-data/

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

#vs-code (debug config)
.vscode
launch.json

# typescript
*.tsbuildinfo
next-env.d.ts

*storybook.log

# ignore yarn.lock & package-lock
yarn.lock
package-lock.json
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
bun.lockb
# docker volume
/postgres-data/
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
#vs-code (debug config)
.vscode
launch.json
# typescript
*.tsbuildinfo
next-env.d.ts
*storybook.log
# ignore yarn.lock & package-lock
yarn.lock
package-lock.json
config.bat
152 changes: 79 additions & 73 deletions src/actions/bookmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,79 @@
'use server';
import { createSafeAction } from '@/lib/create-safe-action';
import { BookmarkCreateSchema, BookmarkDeleteSchema } from './schema';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import db from '@/db';
import {
InputTypeCreateBookmark,
InputTypeDeleteBookmark,
ReturnTypeCreateBookmark,
} from './types';
import { revalidatePath } from 'next/cache';

const reloadBookmarkPage = () => {
revalidatePath('/bookmark');
};

const createBookmarkHandler = async (
data: InputTypeCreateBookmark,
): Promise<ReturnTypeCreateBookmark> => {
const session = await getServerSession(authOptions);

if (!session || !session.user) {
return { error: 'Unauthorized or insufficient permissions' };
}

const { contentId } = data;
const userId = session.user.id;

try {
const addedBookmark = await db.bookmark.create({
data: {
contentId,
userId,
},
});
reloadBookmarkPage();
return { data: addedBookmark };
} catch (error: any) {
return { error: error.message || 'Failed to create comment.' };
}
};

const deleteBookmarkHandler = async (
data: InputTypeDeleteBookmark,
): Promise<any> => {
const session = await getServerSession(authOptions);

if (!session || !session.user) {
return { error: 'Unauthorized or insufficient permissions' };
}
const userId = session.user.id;
const { id } = data;

try {
const deletedBookmark = await db.bookmark.delete({
where: { id, userId },
});
reloadBookmarkPage();
return { data: deletedBookmark };
} catch (error: any) {
return { error: error.message || 'Failed to create comment.' };
}
};

export const createBookmark = createSafeAction(
BookmarkCreateSchema,
createBookmarkHandler,
);
export const deleteBookmark = createSafeAction(
BookmarkDeleteSchema,
deleteBookmarkHandler,
);
'use server';
import { createSafeAction } from '@/lib/create-safe-action';
import { BookmarkCreateSchema, BookmarkDeleteSchema } from './schema';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import db from '@/db';
import {
InputTypeCreateBookmark,
InputTypeDeleteBookmark,
ReturnTypeCreateBookmark,
} from './types';
import { revalidatePath } from 'next/cache';

const reloadBookmarkPage = () => {
revalidatePath('/bookmark');
};

const createBookmarkHandler = async (
data: InputTypeCreateBookmark,
): Promise<ReturnTypeCreateBookmark> => {
const session = await getServerSession(authOptions);

if (!session || !session.user) {
return { error: 'Unauthorized or insufficient permissions' };
}

const { contentId } = data;
const userId = session.user.id;

try {
const addedBookmark = await db.bookmark.create({
data: {
contentId,
userId,
},
});
reloadBookmarkPage();
return { data: addedBookmark };
} catch (error: unknown) {
if (error instanceof Error) {
return { error: error.message};
}
return { error: 'Failed to create comment.' };
}
};

const deleteBookmarkHandler = async (
data: InputTypeDeleteBookmark,
): Promise<any> => {
const session = await getServerSession(authOptions);

if (!session || !session.user) {
return { error: 'Unauthorized or insufficient permissions' };
}
const userId = session.user.id;
const { id } = data;

try {
const deletedBookmark = await db.bookmark.delete({
where: { id, userId },
});
reloadBookmarkPage();
return { data: deletedBookmark };
} catch (error: unknown) {
if (error instanceof Error) {
return { error: error.message};
}
return { error: 'Failed to create comment.' };
}
};

export const createBookmark = createSafeAction(
BookmarkCreateSchema,
createBookmarkHandler,
);
export const deleteBookmark = createSafeAction(
BookmarkDeleteSchema,
deleteBookmarkHandler,
);
122 changes: 61 additions & 61 deletions src/actions/bounty/userActions.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
'use server';
import prisma from '@/db';
import { bountySubmissionSchema } from './schema';
import { BountySubmissionData } from './types';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { createSafeAction } from '@/lib/create-safe-action';
import { Prisma } from '@prisma/client';

async function submitBountyHandler(data: BountySubmissionData) {
try {
const session = await getServerSession(authOptions);

if (!session || !session.user) {
return { error: 'User not authenticated' };
}

const bountySubmission = await prisma.bountySubmission.create({
data: {
prLink: data.prLink,
paymentMethod: data.paymentMethod,
userId: session.user.id,
},
});
return { data: bountySubmission };
} catch (error: any) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === 'P2002') {
return {
error: 'PR already submitted. Try a different one.',
};
}
}
return { error: 'Failed to submit bounty!' };
}
}

export async function getUserBounties() {
try {
const session = await getServerSession(authOptions);

if (!session || !session.user) {
throw new Error('User not authenticated');
}

const bounties = await prisma.bountySubmission.findMany({
where: { userId: session.user.id },
include: { user: true },
});

return bounties;
} catch (error) {
console.error('Error retrieving user bounties:', error);
throw error;
}
}

export const submitBounty = createSafeAction(
bountySubmissionSchema,
submitBountyHandler,
);
'use server';
import prisma from '@/db';
import { bountySubmissionSchema } from './schema';
import { BountySubmissionData } from './types';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { createSafeAction } from '@/lib/create-safe-action';
import { Prisma } from '@prisma/client';
async function submitBountyHandler(data: BountySubmissionData) {
try {
const session = await getServerSession(authOptions);
if (!session || !session.user) {
return { error: 'User not authenticated' };
}
const bountySubmission = await prisma.bountySubmission.create({
data: {
prLink: data.prLink,
paymentMethod: data.paymentMethod,
userId: session.user.id,
},
});
return { data: bountySubmission };
} catch (error: unknown) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === 'P2002') {
return {
error: 'PR already submitted. Try a different one.',
};
}
}
return { error: 'Failed to submit bounty!' };
}
}
export async function getUserBounties() {
try {
const session = await getServerSession(authOptions);
if (!session || !session.user) {
throw new Error('User not authenticated');
}
const bounties = await prisma.bountySubmission.findMany({
where: { userId: session.user.id },
include: { user: true },
});
return bounties;
} catch (error) {
console.error('Error retrieving user bounties:', error);
throw error;
}
}
export const submitBounty = createSafeAction(
bountySubmissionSchema,
submitBountyHandler,
);
Loading