Skip to content

Commit

Permalink
lil change in test api | npm run pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevyashsaini committed Aug 12, 2024
1 parent 46e97ce commit a6008d7
Show file tree
Hide file tree
Showing 78 changed files with 3,342 additions and 2,548 deletions.
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"utils": "@/lib/utils",
"components": "@/components"
}
}
}
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {};

export default nextConfig;
50 changes: 50 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"pretty": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json}\""
},
"dependencies": {
"@emotion/react": "^11.12.0",
Expand All @@ -26,6 +27,7 @@
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"jodit-react": "^4.1.2",
"ldrs": "^1.0.2",
"lucide-react": "^0.408.0",
"next": "14.2.5",
Expand All @@ -48,6 +50,7 @@
"@types/react-dom": "^18",
"autoprefixer": "^10.4.19",
"postcss": "^8",
"prettier": "^3.3.3",
"supabase": "^1.187.3",
"tailwindcss": "^3.4.1",
"typescript": "^5"
Expand Down
12 changes: 6 additions & 6 deletions src/app/api/logout/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {NextRequest, NextResponse} from "next/server";
import {createClient} from "@/utils/supabase/server";
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/utils/supabase/server";

export async function GET(req: NextRequest) {
const supabase = createClient()
const supabase = createClient();

const { error } = await supabase.auth.signOut()
const { error } = await supabase.auth.signOut();

if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}

return NextResponse.json({ data: 'Logout successful' }, { status: 200 });
}
return NextResponse.json({ data: "Logout successful" }, { status: 200 });
}
16 changes: 9 additions & 7 deletions src/app/api/rest/v1/isUsername/route.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import {NextRequest, NextResponse} from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/utils/supabase/server";

export async function POST(req: NextRequest): Promise<NextResponse> {
try {
const supabase = createClient();
const body = await req.json();
if (!body.username) {
return NextResponse.json({ error: 'username is required' }, { status: 400 });
return NextResponse.json(
{ error: "username is required" },
{ status: 400 },
);
}

const { data, error } = await supabase
.rpc('is_username_exist',
{ username: body.username }
);
const { data, error } = await supabase.rpc("is_username_exist", {
username: body.username,
});

if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
Expand All @@ -22,4 +24,4 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}
}
24 changes: 12 additions & 12 deletions src/app/api/rest/v1/users/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NextRequest, NextResponse} from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/utils/supabase/server";
import { User } from "@supabase/supabase-js";

Expand All @@ -7,33 +7,33 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
request: {
headers: req.headers,
},
})
});

const body = await req.json()
const body = await req.json();
const supabase = createClient();
const searchParams = req.nextUrl.searchParams;
const option = searchParams.get('option');
const option = searchParams.get("option");

let data: User | User[] | null = null;

if ( option === 'insert' ) {
if (option === "insert") {
const { data: user, error: error } = await supabase
.from('users')
.insert([{id: body.id, username: body.username, admin: body.admin}])
.from("users")
.insert([{ id: body.id, username: body.username, admin: body.admin }]);
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
data = user;
} else if ( option === 'update' ) {
} else if (option === "update") {
const { data: user, error: error } = await supabase
.from('users')
.update({username: body.username})
.match({id: body.id})
.from("users")
.update({ username: body.username })
.match({ id: body.id });
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
data = user;
}

return NextResponse.json({ data: data });
}
}
31 changes: 19 additions & 12 deletions src/app/api/update-password/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import {NextRequest, NextResponse} from "next/server";
import { cookies } from 'next/headers';
import {createClient} from "@/utils/supabase/server";
import { NextRequest, NextResponse } from "next/server";
import { cookies } from "next/headers";
import { createClient } from "@/utils/supabase/server";

export async function GET(req: NextRequest) {
const requestUrl = new URL(req.nextUrl.href)
const code = requestUrl.searchParams.get('code')
const requestUrl = new URL(req.nextUrl.href);
const code = requestUrl.searchParams.get("code");

if( code ) {
const supabase = createClient()
const { error } = await supabase.auth.exchangeCodeForSession(code)
if (code) {
const supabase = createClient();
const { error } = await supabase.auth.exchangeCodeForSession(code);

return NextResponse.redirect(new URL(`${req.nextUrl.origin}/auth/update_password`, req.nextUrl.href))
return NextResponse.redirect(
new URL(`${req.nextUrl.origin}/auth/update_password`, req.nextUrl.href),
);
}

console.log({error : 'ERROR: Invalid auth code or no auth code found'}, { status: 500 })
console.log(
{ error: "ERROR: Invalid auth code or no auth code found" },
{ status: 500 },
);

return NextResponse.redirect(new URL(`${req.nextUrl.origin}/auth`, req.nextUrl.href))
}
return NextResponse.redirect(
new URL(`${req.nextUrl.origin}/auth`, req.nextUrl.href),
);
}
25 changes: 13 additions & 12 deletions src/app/api/v1/create/event/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ async function convertToAvif(inputFile: File): Promise<File> {
const arrayBuffer = await inputFile.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

const avifBuffer = await sharp(buffer)
.avif()
.toBuffer();
const avifBuffer = await sharp(buffer).avif().toBuffer();

const blob = new Blob([avifBuffer], { type: 'image/avif' });
const avifFile = new File([blob], inputFile.name, { type: 'image/avif' });
const blob = new Blob([avifBuffer], { type: "image/avif" });
const avifFile = new File([blob], inputFile.name, { type: "image/avif" });

return avifFile;
}
Expand Down Expand Up @@ -43,18 +41,23 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
if (userError || !user) {
return NextResponse.json(
{ success: false, message: "Unauthorized" },
{ status: 401 }
{ status: 401 },
);
}

const isAdmin = await supabase
.from("users")
.select("admin")
.eq("id", user.id);
if (isAdmin.error || !isAdmin.data || isAdmin.data.length === 0 || !isAdmin.data[0].admin) {
if (
isAdmin.error ||
!isAdmin.data ||
isAdmin.data.length === 0 ||
!isAdmin.data[0].admin
) {
return NextResponse.json(
{ success: false, message: "Unauthorized" },
{ status: 401 }
{ status: 401 },
);
}

Expand All @@ -75,14 +78,13 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
poster = await convertToAvif(poster_file);
}


delete event.poster;

const validation = validateEvent(event);
if (!validation.valid) {
return NextResponse.json(
{ success: false, message: validation.message },
{ status: 400 }
{ status: 400 },
);
}

Expand All @@ -100,7 +102,6 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
}

if (poster_file && poster) {

const { error: posterUploadError } = await supabase.storage
.from(process.env.BUCKET || "")
.upload(`/events/${eventId}/poster`, poster, {
Expand All @@ -120,7 +121,7 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
} catch (error: any) {
return NextResponse.json(
{ success: false, message: error.message },
{ status: 500 }
{ status: 500 },
);
}
}
Loading

0 comments on commit a6008d7

Please sign in to comment.