Skip to content

Commit

Permalink
added prettier, fixed code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
WTanardi committed Jun 15, 2023
1 parent 6d8bd41 commit 2534f0c
Show file tree
Hide file tree
Showing 51 changed files with 2,887 additions and 1,640 deletions.
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'all',
}
16 changes: 8 additions & 8 deletions app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Footer from "@/components/Footer";
import Header from "@/components/Header";
import Image from "next/image";
import billy from "@/public/billy-portrait.webp";
import cakra from "@/public/cakra-portrait.webp";
import Footer from '@/components/Footer'
import Header from '@/components/Header'
import Image from 'next/image'
import billy from '@/public/billy-portrait.webp'
import cakra from '@/public/cakra-portrait.webp'

const AboutPage = () => {
return (
Expand Down Expand Up @@ -41,7 +41,7 @@ const AboutPage = () => {
</div>
<Footer />
</div>
);
};
)
}

export default AboutPage;
export default AboutPage
8 changes: 4 additions & 4 deletions app/api/adminOrder/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import prisma from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function GET() {
const recipes = await prisma.order.findMany({
Expand All @@ -20,7 +20,7 @@ export async function GET() {
userId: true,
isPaid: true,
},
});
})

return NextResponse.json(recipes);
return NextResponse.json(recipes)
}
43 changes: 23 additions & 20 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import NextAuth, { type NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import prisma from "@/lib/prisma";
import { compare } from "bcrypt";
import NextAuth, { type NextAuthOptions } from 'next-auth'
import CredentialsProvider from 'next-auth/providers/credentials'
import prisma from '@/lib/prisma'
import { compare } from 'bcrypt'

export const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
credentials: {
name: {label: "Name", type: "name"},
email: { label: "Email", type: "email" },
password: { label: "Password", type: "password" }
name: { label: 'Name', type: 'name' },
email: { label: 'Email', type: 'email' },
password: { label: 'Password', type: 'password' },
},
//@ts-expect-error
async authorize(credentials) {
const { email, password } = credentials as {email: string, password: string}
const { email, password } = credentials as {
email: string
password: string
}

if (!email || !password) {
throw new Error("Missing username or password");
throw new Error('Missing username or password')
}
const user = await prisma.user.findUnique({
where: {
email,
},
});
})
// if user doesn't exist or password doesn't match
if (!user || !(await compare(password, user.password))) {
throw new Error("Invalid username or password");
throw new Error('Invalid username or password')
}
return user;
return user
},
}),
],
Expand All @@ -38,24 +41,24 @@ export const authOptions: NextAuthOptions = {
user: {
...session.user,
id: token.id,
isAdmin: token.isAdmin
isAdmin: token.isAdmin,
},
};
}
},
jwt: ({ token, user }) => {
if (user) {
const u = user as unknown as any;
const u = user as unknown as any
return {
...token,
id: u.id,
isAdmin: u.isAdmin,
};
}
}
return token;
return token
},
},
};
}

const handler = NextAuth(authOptions);
const handler = NextAuth(authOptions)

export { handler as GET, handler as POST };
export { handler as GET, handler as POST }
16 changes: 8 additions & 8 deletions app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import prisma from "@/lib/prisma";
import { hash } from "bcrypt";
import { NextResponse } from "next/server";
import prisma from '@/lib/prisma'
import { hash } from 'bcrypt'
import { NextResponse } from 'next/server'

export async function POST(req: Request) {
const { name, email, password } = await req.json();
const { name, email, password } = await req.json()
const exists = await prisma.user.findUnique({
where: {
email,
},
});
})
if (exists) {
return NextResponse.json({ error: "User already exists" }, { status: 400 });
return NextResponse.json({ error: 'User already exists' }, { status: 400 })
} else {
const user = await prisma.user.create({
data: {
name,
email,
password: await hash(password, 10),
},
});
return NextResponse.json(user);
})
return NextResponse.json(user)
}
}
8 changes: 4 additions & 4 deletions app/api/category/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import prisma from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function GET() {
const categories = await prisma.category.findMany({
Expand All @@ -9,7 +9,7 @@ export async function GET() {
img: true,
ingredients: true,
},
});
})

return NextResponse.json(categories);
return NextResponse.json(categories)
}
52 changes: 29 additions & 23 deletions app/api/ingredient/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { NextResponse } from "next/server";
import { Ingredient, PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
import { NextResponse } from 'next/server'
import { Ingredient, PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

export const PATCH = async (req: Request, {params}: {params: {id: string}}) =>{
const body: Ingredient= await req.json();
const ingredient= await prisma.ingredient.update({
where:{
id: Number(params.id)
},
data:{
name: body.name,
categoryId: body.categoryId
}
});
return NextResponse.json(ingredient, {status: 200});
export const PATCH = async (
req: Request,
{ params }: { params: { id: string } },
) => {
const body: Ingredient = await req.json()
const ingredient = await prisma.ingredient.update({
where: {
id: Number(params.id),
},
data: {
name: body.name,
categoryId: body.categoryId,
},
})
return NextResponse.json(ingredient, { status: 200 })
}

export const DELETE = async (req: Request, {params}: {params: {id: string}}) =>{
const ingredient = await prisma.ingredient.delete({
where:{
id: Number(params.id)
}
});
return NextResponse.json(ingredient, {status: 200});
}
export const DELETE = async (
req: Request,
{ params }: { params: { id: string } },
) => {
const ingredient = await prisma.ingredient.delete({
where: {
id: Number(params.id),
},
})
return NextResponse.json(ingredient, { status: 200 })
}
24 changes: 12 additions & 12 deletions app/api/ingredient/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import prisma from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function GET() {
const ingredients = await prisma.ingredient.findMany({
Expand All @@ -8,31 +8,31 @@ export async function GET() {
name: true,
category: true,
},
});
})

return NextResponse.json(ingredients);
return NextResponse.json(ingredients)
}

export async function POST(req: Request) {
const { id, name, categoryId } = await req.json();
console.log("categoryId: ", categoryId);
const { id, name, categoryId } = await req.json()
console.log('categoryId: ', categoryId)
const exists = await prisma.ingredient.findUnique({
where: {
id,
},
});
})
if (exists) {
return NextResponse.json(
{ error: "Ingredient already exists" },
{ status: 400 }
);
{ error: 'Ingredient already exists' },
{ status: 400 },
)
} else {
const ingredient = await prisma.ingredient.create({
data: {
name,
categoryId,
},
});
return NextResponse.json(ingredient);
})
return NextResponse.json(ingredient)
}
}
24 changes: 12 additions & 12 deletions app/api/order/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { NextResponse } from "next/server";
import { PrismaClient, Order } from "@prisma/client";
const prisma = new PrismaClient();
import { NextResponse } from 'next/server'
import { PrismaClient, Order } from '@prisma/client'
const prisma = new PrismaClient()

export const PATCH = async (
req: Request,
{ params }: { params: { id: string } }
{ params }: { params: { id: string } },
) => {
const body: Order = await req.json();
const body: Order = await req.json()
const order = await prisma.order.update({
where: {
id: Number(params.id),
},
data: {
isPaid: body.isPaid,
},
});
return NextResponse.json(order, { status: 200 });
};
})
return NextResponse.json(order, { status: 200 })
}

export const DELETE = async (
req: Request,
{ params }: { params: { id: string } }
{ params }: { params: { id: string } },
) => {
const recipe = await prisma.order.delete({
where: {
id: Number(params.id),
},
});
return NextResponse.json(recipe, { status: 200 });
};
})
return NextResponse.json(recipe, { status: 200 })
}
14 changes: 7 additions & 7 deletions app/api/order/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import prisma from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function GET() {
const recipes = await prisma.order.findFirst({
Expand All @@ -11,13 +11,13 @@ export async function GET() {
isPaid: true,
},
take: -1,
});
})

return NextResponse.json(recipes);
return NextResponse.json(recipes)
}

export async function POST(req: Request) {
const { totalPrice, foodId, userId, isPaid } = await req.json();
const { totalPrice, foodId, userId, isPaid } = await req.json()

const order = await prisma.order.create({
data: {
Expand All @@ -26,7 +26,7 @@ export async function POST(req: Request) {
userId,
isPaid,
},
});
})

return NextResponse.json(order);
return NextResponse.json(order)
}
Loading

1 comment on commit 2534f0c

@vercel
Copy link

@vercel vercel bot commented on 2534f0c Jun 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

pantry-pilot-2 – ./

pantry-pilot-2.vercel.app
pantry-pilot-2-git-main-wtanardi.vercel.app
pantry-pilot-2-wtanardi.vercel.app

Please sign in to comment.