Skip to content

Commit

Permalink
Merge pull request #20 from ruru-m07/main
Browse files Browse the repository at this point in the history
Refactor code and fix bugs close #19
  • Loading branch information
ruru-m07 authored Feb 8, 2024
2 parents 3576ab5 + 4774d99 commit 3cd88f8
Show file tree
Hide file tree
Showing 78 changed files with 17,590 additions and 3,391 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
DATABASE_URL="postgresql://ruru-m07:qNUHdS2pTj4z@ep-crimson-rain-a18rwix8-pooler.ap-southeast-1.aws.neon.tech/cocola_DB?sslmode=require&pgbouncer=true"
DIRECT_URL="postgresql://ruru-m07:qNUHdS2pTj4z@ep-crimson-rain-a18rwix8.ap-southeast-1.aws.neon.tech/cocola_DB?sslmode=require"
MONGODB_URL='mongodb+srv://cocola:[email protected]/cocola?retryWrites=true&w=majority'

AUTH_SECRET=2e1d8c3da161567ec57e934a6f3fb35b

Expand Down
40 changes: 40 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"workbench.colorTheme": "Tokyo Night",
"workbench.startupEditor": "none",
"files.autoSave": "afterDelay",
"glassit.alpha": 245,
"glassit.force_sway": true,
"workbench.iconTheme": "material-icon-theme",
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"hediet.vscode-drawio.resizeImages": null,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"tabnine.experimentalAutoImports": true,
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.updateImportsOnFileMove.enabled": "always",
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"glassit.step": 500,
"bitoAI.codeCompletion.enableCommentToCode": true,
"bitoAI.codeCompletion.enableAutoCompletion": true,
"cmake.options.statusBarVisibility": "hidden"
}
13 changes: 13 additions & 0 deletions actions/findImageUrlByUserName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use server";

import { db } from "@/lib/db";

export const findImageUrlByUserName = async (userName: string) => {
const user = await db.user.findUnique({
where: {
username: userName,
},
});
let image = user?.image;
return image;
};
8 changes: 4 additions & 4 deletions actions/new-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const newVerification = async (token: string) => {
const existingToken = await getVerificationTokenByToken(token);

if (!existingToken) {
return { error: "Token does not exist!" };
return { success: "Email verified!" };
}

const hasExpired = new Date(existingToken.expires) < new Date();
Expand All @@ -25,14 +25,14 @@ export const newVerification = async (token: string) => {

await db.user.update({
where: { id: existingUser.id },
data: {
data: {
emailVerified: new Date(),
email: existingToken.email,
}
},
});

await db.verificationToken.delete({
where: { id: existingToken.id }
where: { id: existingToken.id },
});

return { success: "Email verified!" };
Expand Down
11 changes: 4 additions & 7 deletions actions/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const register = async (values: z.infer<typeof RegisterSchema>) => {
return { error: "Invalid fields!" };
}

const { email, password, name } = validatedFields.data;
const { email, password, username } = validatedFields.data;
const hashedPassword = await bcrypt.hash(password, 10);

const existingUser = await getUserByEmail(email);
Expand All @@ -27,17 +27,14 @@ export const register = async (values: z.infer<typeof RegisterSchema>) => {

await db.user.create({
data: {
name,
email,
username: username,
email: email,
password: hashedPassword,
},
});

const verificationToken = await generateVerificationToken(email);
await sendVerificationEmail(
verificationToken.email,
verificationToken.token,
);
await sendVerificationEmail(verificationToken.email, verificationToken.token);

return { success: "Confirmation email sent!" };
};
18 changes: 18 additions & 0 deletions actions/repo/branchCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use server";

import { db } from "@/lib/db";

export const fetchrepo = async (username: string, repository: string) => {
if (!username && !repository) {
return { error: "Invalid user!" };
}

const repo = await db.repository.findFirst({
where: {
name: repository,
author: username,
},
});
console.log(repo)
return { repo: repo };
};
19 changes: 19 additions & 0 deletions actions/repo/commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use server";

import { db } from "@/lib/db";

export const create = async () => {
const commitresult = await db.commit.create({
data: {
commitId: "3",
title: "Initial Commit",
description: " Initial Commit of the repository",
branch: "master",
repositoryId: "65c339bbf67715e59d92337d",
},
});
return {
success: "create commit Successfully! 🎉",
commitresult: commitresult,
};
};
59 changes: 59 additions & 0 deletions actions/repo/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use server";

import * as z from "zod";

import { db } from "@/lib/db";
import { RepoSchema } from "@/schemas";
import { User } from "@prisma/client";

export const create = async (
values: z.infer<typeof RepoSchema>,
user: User
) => {
const validatedFields = RepoSchema.safeParse(values);

if (!validatedFields.success) {
return { error: "Invalid fields!" };
}

const { name, description, visibility, branch } = validatedFields.data;

if (!user?.username) {
return { error: "Invalid user!" };
}
const existingRepo = await db.repository.findFirst({
where: {
name: name,
author: user?.username,
},
});

console.log(existingRepo);

if (existingRepo) {
return { error: "Repository already exist with this name!" };
}

if (user?.username && user?.id) {
const repository = await db.repository.create({
data: {
name: name,
description: description,
Visibility: visibility,
author: user?.username,
authorId: user?.id,
DefualtBranch: branch,
},
});

await db.branch.create({
data: {
name: branch,
repositoryId: repository.id,
},
});
return { success: "Repository create Successfully! 🎉" };
} else {
return { error: "Invalid user!" };
}
};
45 changes: 45 additions & 0 deletions actions/repo/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use server";

import { db } from "@/lib/db";
import { User } from "@prisma/client";

export const fetchRepo = async (
username: string,
repository: string,
user?: User | null
) => {
if (!username || !repository) {
return { error: "Invalid user or repository!" };
}

let repo;

if (user?.username === username) {
repo = await db.repository.findFirst({
where: {
name: repository,
author: username,
},
});
} else {
repo = await db.repository.findFirst({
where: {
name: repository,
author: username,
Visibility: "public",
},
});
}

if (!repo) {
return { error: "Repository not found!", statuscode: 404 };
}

const branches = await db.branch.findMany({
where: {
repositoryId: repo.id,
},
});

return { repo, branchCount: branches.length };
};
45 changes: 45 additions & 0 deletions actions/whoami.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use server";

import { db } from "@/lib/db";

export const whoami = async (currentUser: any) => {
const { ...userdata } = await db.user.findUnique({
where: { email: currentUser?.email as string | undefined },
select: {
id: true,
name: true,
email: true,
emailVerified: true,
image: true,
password: false,
role: true,
isTwoFactorEnabled: true,
username: true,
lname: true,
displayName: true,
profileImage: true,
coverImage: true,
bio: true,
dateOfBirth: true,
gender: true,
phone: true,
street: true,
city: true,
state: true,
zipcode: true,
country: true,
facebook: true,
twitter: true,
instagram: true,
linkedin: true,
website: true,
createdAt: true,
updatedAt: true,
accounts: true,
twoFactorConfirmation: true,
_count: true,
},
});

return { userdata };
};
Loading

1 comment on commit 3cd88f8

@vercel
Copy link

@vercel vercel bot commented on 3cd88f8 Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.