Skip to content

Commit

Permalink
feat: use spaces and lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
frattezi committed Jun 20, 2024
1 parent f34d809 commit f3801de
Show file tree
Hide file tree
Showing 22 changed files with 602 additions and 602 deletions.
37 changes: 18 additions & 19 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "biomejs.biome",
"editor.tabSize": 2,
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"cSpell.words": ["biomejs", "lefthook", "shadcn", "tailwindcss", "Vercel"],
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "biomejs.biome",
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"cSpell.words": ["biomejs", "lefthook", "shadcn", "tailwindcss", "Vercel"],
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
60 changes: 29 additions & 31 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
{
"formatter": {
"enabled": true,
"formatWithErrors": false,
"ignore": [],
"attributePosition": "auto",
"indentStyle": "tab",
"indentWidth": 1,
"lineWidth": 80,
"lineEnding": "lf"
},
"javascript": {
"formatter": {
"arrowParentheses": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"semicolons": "always"
}
},
"json": {
"formatter": {
"trailingCommas": "none",
"indentWidth": 1,
"indentStyle": "tab",
"lineWidth": 80
}
},
"files": {
"ignore": ["dist/**", "node_modules/**", ".next/**", ".vercel/**"]
}
"formatter": {
"enabled": true,
"formatWithErrors": false,
"ignore": [],
"attributePosition": "auto",
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"lineEnding": "lf"
},
"javascript": {
"formatter": {
"arrowParentheses": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"semicolons": "always"
}
},
"json": {
"formatter": {
"lineWidth": 80,
"trailingCommas": "none"
}
},
"files": {
"ignore": ["node_modules/**", ".next/**", ".vercel/**"]
}
}
30 changes: 15 additions & 15 deletions components.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"utils": "@packages/utils/shadcn-utils",
"components": "src/packages/shadcn-ui"
}
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"utils": "@packages/utils/shadcn-utils",
"components": "src/packages/shadcn-ui"
}
}
76 changes: 38 additions & 38 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@ import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;

switch (pathname) {
case "/api/elections":
return _checkElectionParameter(request);
case "/api/elections/page":
return _checkElectionPageParameter(request);
default:
NextResponse.next();
}
const { pathname } = request.nextUrl;

switch (pathname) {
case "/api/elections":
return _checkElectionParameter(request);
case "/api/elections/page":
return _checkElectionPageParameter(request);
default:
NextResponse.next();
}
}

function _checkElectionParameter(
request: NextRequest,
request: NextRequest,
): NextResponse | undefined {
if (request.method !== "GET") {
return methodNotAllowed();
}
const { searchParams } = request.nextUrl;
const databaseId: string | null = searchParams.get("databaseId");

if (!databaseId || databaseId?.length !== 32) {
return _invalidParameterResponse("Invalid databaseId parameter.");
}
if (request.method !== "GET") {
return methodNotAllowed();
}
const { searchParams } = request.nextUrl;
const databaseId: string | null = searchParams.get("databaseId");

if (!databaseId || databaseId?.length !== 32) {
return _invalidParameterResponse("Invalid databaseId parameter.");
}
}

function _checkElectionPageParameter(
request: NextRequest,
request: NextRequest,
): NextResponse | undefined {
if (request.method !== "GET") {
return methodNotAllowed();
}
const { searchParams } = request.nextUrl;
const pageId: string | null = searchParams.get("pageId");

if (!pageId || pageId?.length !== 36) {
return _invalidParameterResponse("Invalid pageId parameter.");
}
if (request.method !== "GET") {
return methodNotAllowed();
}
const { searchParams } = request.nextUrl;
const pageId: string | null = searchParams.get("pageId");

if (!pageId || pageId?.length !== 36) {
return _invalidParameterResponse("Invalid pageId parameter.");
}
}

function _invalidParameterResponse(message: string): NextResponse {
return new NextResponse(null, {
status: 400,
statusText: message,
});
return new NextResponse(null, {
status: 400,
statusText: message,
});
}

function methodNotAllowed(): NextResponse | undefined {
return new NextResponse(null, {
status: 405,
statusText: "Method Not Allowed.",
});
return new NextResponse(null, {
status: 405,
statusText: "Method Not Allowed.",
});
}
8 changes: 4 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
images: {
domains: ["s3.us-west-2.amazonaws.com"],
},
reactStrictMode: true,
images: {
domains: ["s3.us-west-2.amazonaws.com"],
},
};

module.exports = nextConfig;
82 changes: 41 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "voting-system",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "biome check",
"migrate": "prisma migrate dev",
"generate": "prisma generate",
"format": "biome format --write .",
"postinstall": "prisma generate"
},
"dependencies": {
"@prisma/client": "^5.11.0",
"@radix-ui/react-menubar": "^1.0.4",
"@radix-ui/react-slot": "^1.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.395.0",
"next": "^14.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@biomejs/biome": "1.8.1",
"@types/node": "^20.11.27",
"@types/react": "^18.2.65",
"@types/react-dom": "^18.2.22",
"@types/uuid": "^8.3.4",
"autoprefixer": "^10.4.18",
"lefthook": "^1.6.16",
"postcss": "^8.4.35",
"prisma": "^5.11.0",
"tailwindcss": "^3.4.1",
"typescript": "^5.4.2",
"uuid": "^9.0.0"
}
"name": "voting-system",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "biome check",
"migrate": "prisma migrate dev",
"generate": "prisma generate",
"format": "biome format --write .",
"postinstall": "prisma generate"
},
"dependencies": {
"@prisma/client": "^5.11.0",
"@radix-ui/react-menubar": "^1.0.4",
"@radix-ui/react-slot": "^1.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.395.0",
"next": "^14.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@biomejs/biome": "1.8.1",
"@types/node": "^20.11.27",
"@types/react": "^18.2.65",
"@types/react-dom": "^18.2.22",
"@types/uuid": "^8.3.4",
"autoprefixer": "^10.4.18",
"lefthook": "^1.6.16",
"postcss": "^8.4.35",
"prisma": "^5.11.0",
"tailwindcss": "^3.4.1",
"typescript": "^5.4.2",
"uuid": "^9.0.0"
}
}
8 changes: 4 additions & 4 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
26 changes: 13 additions & 13 deletions src/app/elections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { createElectionValidator } from "src/packages/dto/elections.dto";
const prisma = new PrismaClient();

export async function GET() {
const elections = await prisma.election.findMany();
return NextResponse.json({ data: elections }, { status: 200 });
const elections = await prisma.election.findMany();
return NextResponse.json({ data: elections }, { status: 200 });
}

export async function POST(req: NextRequest) {
const reqBody = await req.json();
const parsedBody = createElectionValidator.safeParse(reqBody);
const reqBody = await req.json();
const parsedBody = createElectionValidator.safeParse(reqBody);

if (!parsedBody.success) {
return NextResponse.json({ message: parsedBody.error }, { status: 400 });
}
const electionData = parsedBody.data;
if (!parsedBody.success) {
return NextResponse.json({ message: parsedBody.error }, { status: 400 });
}
const electionData = parsedBody.data;

const result = await prisma.election.create({ data: electionData });
NextResponse.json(
{ result, message: "Election successfully created " },
{ status: 200 },
);
const result = await prisma.election.create({ data: electionData });
NextResponse.json(
{ result, message: "Election successfully created " },
{ status: 200 },
);
}
Loading

0 comments on commit f3801de

Please sign in to comment.