Skip to content

Commit

Permalink
Merge pull request #23 from LokeshXs/staging
Browse files Browse the repository at this point in the history
added a transaction view
  • Loading branch information
LokeshXs authored May 28, 2024
2 parents 862c54b + b0adf35 commit ea539a0
Show file tree
Hide file tree
Showing 77 changed files with 17,917 additions and 164 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ jobs:
sudo docker stop paytm-clone-webhook || true
sudo docker rm paytm-clone-user || true
sudo docker rm paytm-clone-webhook || true
sudo docker network disconnect my_network paytm-clone-user || true
sudo docker network disconnect my_network paytm-clone-webhook || true
sudo docker network create my_network
sudo docker run -d --name paytm-clone-user --network my_network -e AUTH_SECRET=${{ secrets.AUTH_SECRET }} -e AUTH_GOOGLE_ID=${{ secrets.AUTH_GOOGLE_ID }} -e AUTH_GOOGLE_SECRET=${{ secrets.AUTH_GOOGLE_SECRET }} -e DATABASE_URL=${{ secrets.DATABASE_URL }} -p 3000:3000 lokesh1129/paytm-clone-user:latest
sudo docker run -d --name paytm-clone-webhook --network my_network -e DATABASE_URL=${{ secrets.DATABASE_URL }} lokesh1129/paytm-clone-webhook:latest
sudo docker network disconnect paytm-network paytm-clone-user || true
sudo docker network disconnect paytm-network paytm-clone-webhook || true
sudo docker network create paytm-network
sudo docker run -d --name paytm-clone-user --network paytm-network -e AUTH_SECRET=${{ secrets.AUTH_SECRET }} -e AUTH_GOOGLE_ID=${{ secrets.AUTH_GOOGLE_ID }} -e AUTH_GOOGLE_SECRET=${{ secrets.AUTH_GOOGLE_SECRET }} -e DATABASE_URL=${{ secrets.DATABASE_URL }} -p 3000:3000 lokesh1129/paytm-clone-user:latest
sudo docker run -d --name paytm-clone-webhook --network paytm-network -e DATABASE_URL=${{ secrets.DATABASE_URL }} lokesh1129/paytm-clone-webhook:latest
9 changes: 8 additions & 1 deletion apps/web/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare module "next-auth" {
interface Session {
/** The user's postal address. */
userId: string;

}
}

Expand Down Expand Up @@ -55,14 +56,21 @@ export const { handlers, auth, signIn, signOut } = NextAuth({

callbacks: {
async signIn({ user, account, profile, email, credentials }) {

return true;
},

async session({ session, user, token }) {
// console.log(token);
session.userId = token.sub!;


return session;
},
async jwt({ token, user, account, profile, isNewUser }) {

return token
},
async redirect({ url, baseUrl }) {
return "/myaccount/dashboard";
},
Expand All @@ -71,7 +79,6 @@ export const { handlers, auth, signIn, signOut } = NextAuth({

events: {
async signIn({ isNewUser, user }) {
// console.log("Is new user", isNewUser);

if (isNewUser) {
await db.balance.create({
Expand Down
13 changes: 8 additions & 5 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"@repo/database": "*",
"@repo/ui": "*",
"@repo/database":"*",
"@types/bcryptjs": "^2.4.6",
"@types/uuid": "^9.0.8",
"bcryptjs": "^2.4.3",
Expand All @@ -22,15 +22,16 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwind-merge": "^2.3.0",
"twilio": "^5.0.4",
"uuid": "^9.0.1",
"zod": "^3.22.4"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.1.1",
"@repo/eslint-config": "*",
"@repo/schemas": "*",
"@repo/tailwind-config": "*",
"@repo/typescript-config": "*",
"@repo/schemas":"*",
"@types/node": "^20.11.24",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
Expand All @@ -42,8 +43,10 @@
"exports": {
"./signUp": "./src/actions/authentication.ts",
"./auth": "./auth.ts",
"./logout":"./src/actions/logout.ts",
"./db":"./src/lib/db.ts",
"./mobilenavcontext":"./src/context/MobileNavContext.tsx"
"./logout": "./src/actions/logout.ts",
"./db": "./src/lib/db.ts",
"./mobilenavcontext": "./src/context/MobileNavContext.tsx",
"./baseurl": "./src/config/site-config.ts",
"./updateProfile": "./src/actions/updateProfile.ts"
}
}
7 changes: 4 additions & 3 deletions apps/web/src/actions/addMoney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import db from "../lib/db";
import { auth } from "../../auth";
import { revalidatePath } from "next/cache";
import { v4 as uuidv4 } from "uuid";
import { BASE_URL, WEBHOOK_URL } from "../config/site-config";

export async function addMoney(values: z.infer<typeof addMoneyFormSchema>) {
try {
const session = await auth();
const userId = session?.userId;

console.log(values);


// 1.) zod validation

Expand All @@ -34,7 +35,7 @@ export async function addMoney(values: z.infer<typeof addMoneyFormSchema>) {
data: {
status: "Processing",
amount: amountInNumber,
startTime: new Date(),
timestamp: new Date(),
userId: userId!,
token: uuidv4(),
paymentCardId: bank,
Expand All @@ -44,7 +45,7 @@ export async function addMoney(values: z.infer<typeof addMoneyFormSchema>) {
revalidatePath("/dashboard");
// console.log(transactionDetails);
setTimeout(async () => {
await fetch("http://localhost:3001/webhook", {
await fetch(`${WEBHOOK_URL}/webhook`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/actions/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export async function signUp(values: z.infer<typeof SignUpSchema>) {
},
});


// Initialising the user with Zero balance
await db.balance.create({
data: {
Expand All @@ -67,6 +66,7 @@ export async function signUp(values: z.infer<typeof SignUpSchema>) {
},
});


return {
status: "success",
message: "Signed up successfully",
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function signInAction(values: z.infer<typeof SignInSchema>) {
message: "Successfully Signed in",
};
} catch (error) {
console.log(error);
// console.log(error);

if (error instanceof AuthError) {
switch (error.type) {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/actions/transferMoney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default async function TransferMoney(
data: {
toUserId: toUser.id,
fromUserId: session.userId,
Amount: Number(validatedValues.data.amount) * 100,
amount: Number(validatedValues.data.amount) * 100,
status: "Success",
},
});
Expand All @@ -133,7 +133,7 @@ export default async function TransferMoney(
data: {
toUserId: toUser.id,
fromUserId: session.userId,
Amount: Number(validatedValues.data.amount) * 100,
amount: Number(validatedValues.data.amount) * 100,
status: "Failed",
},
});
Expand Down
200 changes: 200 additions & 0 deletions apps/web/src/actions/updateProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
"use server";

import { UpdateCustomProfileSchema } from "@repo/schemas/authenticationSchema";
import { z } from "zod";
import db from "../lib/db";
import { auth } from "../../auth";
import bcrypt from "bcryptjs";
import {Prisma} from "@prisma/client"

export const updateProfile = async (
values: z.infer<typeof UpdateCustomProfileSchema>
) => {
console.log(values);
try {
const session = await auth();

const validatedValues = UpdateCustomProfileSchema.safeParse(values);

if (!validatedValues.success) {
return {
status: "error",
message: "Values are not valid",
};
}

const validatedValuesData: {
name: string;
phonenumber: string;
email: string;
password: string;
[key: string]: string; // Index signature
} = validatedValues.data;

// 1.) Fetch the updatable fields from DB

const userOriginalDetails: {
name: string | null;
phonenumber: string | null;
email: string;
password: string | null;
[key: string]: string | null; // Index signature
} | null = await db.user.findUnique({
where: {
id: session?.userId,
},
select: {
name: true,
email: true,
password: true,
phonenumber: true,
},
});

const toBeUpdatedFields: any = {};

for (let [key, value] of Object.entries(userOriginalDetails || {})) {
if (userOriginalDetails) {
if (key === "password") {
const isValid = await bcrypt.compare(
validatedValuesData["password"],
userOriginalDetails["password"] || ""
);

if (!isValid && validatedValuesData["password"] !== "") {
toBeUpdatedFields["password"] = validatedValuesData["password"];
}
} else {
if (userOriginalDetails[key] !== validatedValuesData[key]) {
toBeUpdatedFields[key] = validatedValuesData[key];
}
}
}
}



// 2.) Update fields

await db.user.update({
where: {
id: session?.userId,
},
data: toBeUpdatedFields,
});

return {
status: "success",
message: "Profile is updated successfully",
};
} catch (error) {

console.log(error);

if(error instanceof Prisma.PrismaClientKnownRequestError){
if(error.code === "P2002"){
return {
status:"error",
message:"User with the details already exist"
}
}
}

return {
status: "error",
message: "Something went wrong, try after sometime",
};
}
};




// ******************************************************************************

export const updateOAuthProfile = async (
values: {number:string}
) => {
try {
const session = await auth();

const validatedValues = UpdateCustomProfileSchema.safeParse(values);

if (!validatedValues.success) {
return {
status: "error",
message: "Values are not valid",
};
}

const validatedValuesData: {
name: string;
phonenumber: string;
email: string;
password: string;
[key: string]: string; // Index signature
} = validatedValues.data;

// 1.) Fetch the updatable fields from DB

const userOriginalDetails: {
name: string | null;
phonenumber: string | null;
email: string;
password: string | null;
[key: string]: string | null; // Index signature
} | null = await db.user.findUnique({
where: {
id: session?.userId,
},
select: {
name: true,
email: true,
password: true,
phonenumber: true,
},
});

const toBeUpdatedFields: any = {};

for (let [key, value] of Object.entries(userOriginalDetails || {})) {
if (userOriginalDetails) {
if (key === "password") {
const isValid = await bcrypt.compare(
validatedValuesData["password"],
userOriginalDetails["password"] || ""
);

if (!isValid && validatedValuesData["password"] !== "") {
toBeUpdatedFields["password"] = validatedValuesData["password"];
}
} else {
if (userOriginalDetails[key] !== validatedValuesData[key]) {
toBeUpdatedFields[key] = validatedValuesData[key];
}
}
}
}

// 2.) Update fields

await db.user.update({
where: {
id: session?.userId,
},
data: toBeUpdatedFields,
});

return {
status: "success",
message: "Profile is updated successfully",
};
} catch (error) {
return {
status: "error",
message: "Something went wrong, try after sometime",
};
}
};


Loading

0 comments on commit ea539a0

Please sign in to comment.