Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .cursor/worktrees.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"setup-worktree": [
"npm install"
]
}
18 changes: 7 additions & 11 deletions src/app/api/air-quality/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { prisma } from "@/lib/prisma";
import { airQualitySchema } from "@/lib/validations";
import { validateRequest } from "@/lib/validation-helpers";
import { loggerHelpers } from "@/lib/logger";
import { parsePagination, createPaginatedResponse } from "@/lib/pagination";

export async function POST(request: NextRequest) {
try {
Expand Down Expand Up @@ -91,25 +92,20 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { searchParams } = new URL(request.url);
const limit = parseInt(searchParams.get("limit") || "100");
const offset = parseInt(searchParams.get("offset") || "0");
const { page, limit, skip, take } = parsePagination(request);

const [airQuality, total] = await Promise.all([
prisma.airQuality.findMany({
take: limit,
skip: offset,
take,
skip,
orderBy: { date: "desc" },
}),
prisma.airQuality.count(),
]);

return NextResponse.json({
data: airQuality,
total,
limit,
offset,
});
return NextResponse.json(
createPaginatedResponse(airQuality, total, page, limit)
);
} catch (error) {
console.error("Error fetching air quality data:", error);
return NextResponse.json(
Expand Down
26 changes: 12 additions & 14 deletions src/app/api/climate-data/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { prisma } from "@/lib/prisma";
import { climateDataSchema } from "@/lib/validations";
import { validateRequest } from "@/lib/validation-helpers";
import { loggerHelpers } from "@/lib/logger";
import { parsePagination, createPaginatedResponse } from "@/lib/pagination";

export async function POST(request: NextRequest) {
try {
Expand Down Expand Up @@ -97,8 +98,7 @@ export async function GET(request: NextRequest) {

const { searchParams } = new URL(request.url);
const stationId = searchParams.get("stationId");
const limit = parseInt(searchParams.get("limit") || "100");
const offset = parseInt(searchParams.get("offset") || "0");
const { page, limit, skip, take } = parsePagination(request);

const where: any = {};
if (stationId) {
Expand All @@ -108,24 +108,22 @@ export async function GET(request: NextRequest) {
const [climateData, total] = await Promise.all([
prisma.climateData.findMany({
where,
take: limit,
skip: offset,
take,
skip,
orderBy: { date: "desc" },
}),
prisma.climateData.count({ where }),
]);

// Cache for 5 minutes
return NextResponse.json({
data: climateData,
total,
limit,
offset,
}, {
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
});
return NextResponse.json(
createPaginatedResponse(climateData, total, page, limit),
{
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
}
);
} catch (error) {
console.error("Error fetching climate data:", error);
return NextResponse.json(
Expand Down
43 changes: 27 additions & 16 deletions src/app/api/employees/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { prisma } from "@/lib/prisma";
import { employeeSchema } from "@/lib/validations";
import { validateRequest } from "@/lib/validation-helpers";
import { loggerHelpers } from "@/lib/logger";
import { parsePagination, createPaginatedResponse } from "@/lib/pagination";

export async function POST(request: NextRequest) {
try {
Expand Down Expand Up @@ -85,26 +86,36 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const employees = await prisma.employee.findMany({
include: {
user: {
select: {
firstName: true,
lastName: true,
email: true,
role: true,
const { page, limit, skip, take } = parsePagination(request);

const [employees, total] = await Promise.all([
prisma.employee.findMany({
include: {
user: {
select: {
firstName: true,
lastName: true,
email: true,
role: true,
},
},
},
},
orderBy: { createdAt: "desc" },
});
orderBy: { createdAt: "desc" },
take,
skip,
}),
prisma.employee.count(),
]);

// Cache for 5 minutes
return NextResponse.json(employees, {
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
});
return NextResponse.json(
createPaginatedResponse(employees, total, page, limit),
{
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
}
);
} catch (error) {
loggerHelpers.apiError(error as Error, {
route: "/api/employees",
Expand Down
26 changes: 12 additions & 14 deletions src/app/api/water-quality/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { prisma } from "@/lib/prisma";
import { waterQualitySchema } from "@/lib/validations";
import { validateRequest } from "@/lib/validation-helpers";
import { loggerHelpers } from "@/lib/logger";
import { parsePagination, createPaginatedResponse } from "@/lib/pagination";

export async function POST(request: NextRequest) {
try {
Expand Down Expand Up @@ -95,8 +96,7 @@ export async function GET(request: NextRequest) {

const { searchParams } = new URL(request.url);
const type = searchParams.get("type");
const limit = parseInt(searchParams.get("limit") || "100");
const offset = parseInt(searchParams.get("offset") || "0");
const { page, limit, skip, take } = parsePagination(request);

const where: any = {};
if (type) {
Expand All @@ -106,24 +106,22 @@ export async function GET(request: NextRequest) {
const [waterQuality, total] = await Promise.all([
prisma.waterQuality.findMany({
where,
take: limit,
skip: offset,
take,
skip,
orderBy: { date: "desc" },
}),
prisma.waterQuality.count({ where }),
]);

// Cache for 5 minutes
return NextResponse.json({
data: waterQuality,
total,
limit,
offset,
}, {
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
});
return NextResponse.json(
createPaginatedResponse(waterQuality, total, page, limit),
{
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
}
);
} catch (error) {
console.error("Error fetching water quality data:", error);
return NextResponse.json(
Expand Down
Loading