fix(lint): add version to drizzle-orm imports and prefix unused NOT_FOUND
This commit is contained in:
@@ -4,7 +4,7 @@ import { enseignements } from "$root/databases/schema.ts";
|
||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
const NOT_FOUND = new Response(
|
||||
const _NOT_FOUND = new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{ status: 404, headers: { "content-type": "application/json" } },
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { db } from "$root/databases/db.ts";
|
||||
import { modules } from "$root/databases/schema.ts";
|
||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||
import { eq } from "npm:drizzle-orm";
|
||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
export const handler: Handlers<null, AuthenticatedState> = {
|
||||
// #23 GET /modules
|
||||
|
||||
@@ -2,7 +2,7 @@ import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { db } from "$root/databases/db.ts";
|
||||
import { modules } from "$root/databases/schema.ts";
|
||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||
import { eq } from "npm:drizzle-orm";
|
||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
const NOT_FOUND = new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { db } from "../../../../databases/db.ts";
|
||||
import { notes } from "../../../../databases/schema.ts";
|
||||
import { eq } from "npm:drizzle-orm";
|
||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
export const handler: Handlers = {
|
||||
// #42 GET /notes
|
||||
@@ -44,10 +44,13 @@ export const handler: Handlers = {
|
||||
const { note, numEtud, idModule } = body;
|
||||
|
||||
if (note === undefined || !numEtud || !idModule) {
|
||||
return new Response("Champs 'note', 'numEtud' et 'idModule' requis", { status: 400 });
|
||||
return new Response("Champs 'note', 'numEtud' et 'idModule' requis", {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const result = await db.insert(notes).values({ note, numEtud, idModule }).returning();
|
||||
const result = await db.insert(notes).values({ note, numEtud, idModule })
|
||||
.returning();
|
||||
|
||||
return new Response(JSON.stringify(result[0]), {
|
||||
status: 201,
|
||||
@@ -58,4 +61,4 @@ export const handler: Handlers = {
|
||||
return new Response("Failed to create note", { status: 500 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { db } from "../../../../../../databases/db.ts";
|
||||
import { notes } from "../../../../../../databases/schema.ts";
|
||||
import { and, eq } from "npm:drizzle-orm";
|
||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
export const handler: Handlers = {
|
||||
// #45 GET /notes/:numEtud/:idModule
|
||||
// #45 GET /notes/:numEtud/:idModule
|
||||
async GET(_request, context) {
|
||||
try {
|
||||
const numEtud = parseInt(context.params.numEtud);
|
||||
const { idModule } = context.params;
|
||||
|
||||
if (isNaN(numEtud)) {
|
||||
return new Response(JSON.stringify({ error: "Paramètre numEtud invalide" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const result = await db.select().from(notes).where(
|
||||
@@ -25,10 +28,13 @@ export const handler: Handlers = {
|
||||
);
|
||||
|
||||
if (result.length === 0) {
|
||||
return new Response(JSON.stringify({ error: "Ressource introuvable" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(result[0]), {
|
||||
@@ -48,10 +54,13 @@ export const handler: Handlers = {
|
||||
const { idModule } = context.params;
|
||||
|
||||
if (isNaN(numEtud)) {
|
||||
return new Response(JSON.stringify({ error: "Paramètre numEtud invalide" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
@@ -69,10 +78,13 @@ export const handler: Handlers = {
|
||||
).returning();
|
||||
|
||||
if (result.length === 0) {
|
||||
return new Response(JSON.stringify({ error: "Ressource introuvable" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(result[0]), {
|
||||
@@ -92,10 +104,13 @@ export const handler: Handlers = {
|
||||
const { idModule } = context.params;
|
||||
|
||||
if (isNaN(numEtud)) {
|
||||
return new Response(JSON.stringify({ error: "Paramètre numEtud invalide" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const result = await db.delete(notes).where(
|
||||
@@ -106,10 +121,13 @@ export const handler: Handlers = {
|
||||
).returning();
|
||||
|
||||
if (result.length === 0) {
|
||||
return new Response(JSON.stringify({ error: "Ressource introuvable" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
@@ -118,4 +136,4 @@ export const handler: Handlers = {
|
||||
return new Response("Failed to delete note", { status: 500 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { db } from "../../../../databases/db.ts";
|
||||
import { ueModules } from "../../../../databases/schema.ts";
|
||||
import { and, eq } from "npm:drizzle-orm";
|
||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
export const handler: Handlers = {
|
||||
// #37 GET /ue-modules
|
||||
// #37 GET /ue-modules
|
||||
async GET(request) {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
@@ -33,7 +33,7 @@ export const handler: Handlers = {
|
||||
return new Response("Failed to fetch data", { status: 500 });
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// #38 POST /ue-modules
|
||||
async POST(request) {
|
||||
try {
|
||||
@@ -41,10 +41,18 @@ export const handler: Handlers = {
|
||||
const { idModule, idUE, idPromo, coeff } = body;
|
||||
|
||||
if (!idModule || !idUE || !idPromo || coeff === undefined) {
|
||||
return new Response("Champs 'idModule', 'idUE', 'idPromo' et 'coeff' requis", { status: 400 });
|
||||
return new Response(
|
||||
"Champs 'idModule', 'idUE', 'idPromo' et 'coeff' requis",
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const result = await db.insert(ueModules).values({ idModule, idUE, idPromo, coeff }).returning();
|
||||
const result = await db.insert(ueModules).values({
|
||||
idModule,
|
||||
idUE,
|
||||
idPromo,
|
||||
coeff,
|
||||
}).returning();
|
||||
|
||||
return new Response(JSON.stringify(result[0]), {
|
||||
status: 201,
|
||||
@@ -55,4 +63,4 @@ export const handler: Handlers = {
|
||||
return new Response("Failed to create UE-module", { status: 500 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -91,14 +91,17 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
|
||||
if (!updated) return NOT_FOUND;
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
idModule: updated.idModule,
|
||||
idUE: updated.idUE,
|
||||
idPromo: updated.idPromo,
|
||||
coeff: updated.coeff,
|
||||
}), {
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
idModule: updated.idModule,
|
||||
idUE: updated.idUE,
|
||||
idPromo: updated.idPromo,
|
||||
coeff: updated.coeff,
|
||||
}),
|
||||
{
|
||||
headers: { "content-type": "application/json" },
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
// #41 DELETE /ue-modules/{idModule}/{idUE}/{idPromo}
|
||||
|
||||
@@ -39,4 +39,4 @@ export const handler: Handlers = {
|
||||
return new Response("Failed to create UE", { status: 500 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,28 +1,34 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { db } from "../../../../../databases/db.ts";
|
||||
import { ues } from "../../../../../databases/schema.ts";
|
||||
import { eq } from "npm:drizzle-orm";
|
||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
export const handler: Handlers = {
|
||||
// # 34 GET /ues/:idUE
|
||||
// # 34 GET /ues/:idUE
|
||||
async GET(_request, context) {
|
||||
try {
|
||||
const idUE = parseInt(context.params.idUE);
|
||||
|
||||
if (isNaN(idUE)) {
|
||||
return new Response(JSON.stringify({ error: "Paramètre idUE invalide" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const result = await db.select().from(ues).where(eq(ues.id, idUE));
|
||||
|
||||
if (result.length === 0) {
|
||||
return new Response(JSON.stringify({ error: "Ressource introuvable" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(result[0]), {
|
||||
@@ -41,10 +47,13 @@ export const handler: Handlers = {
|
||||
const idUE = parseInt(context.params.idUE);
|
||||
|
||||
if (isNaN(idUE)) {
|
||||
return new Response(JSON.stringify({ error: "Paramètre idUE invalide" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
@@ -54,13 +63,17 @@ export const handler: Handlers = {
|
||||
return new Response("Champ 'nom' manquant", { status: 400 });
|
||||
}
|
||||
|
||||
const result = await db.update(ues).set({ nom }).where(eq(ues.id, idUE)).returning();
|
||||
const result = await db.update(ues).set({ nom }).where(eq(ues.id, idUE))
|
||||
.returning();
|
||||
|
||||
if (result.length === 0) {
|
||||
return new Response(JSON.stringify({ error: "Ressource introuvable" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(result[0]), {
|
||||
@@ -79,19 +92,25 @@ export const handler: Handlers = {
|
||||
const idUE = parseInt(context.params.idUE);
|
||||
|
||||
if (isNaN(idUE)) {
|
||||
return new Response(JSON.stringify({ error: "Paramètre idUE invalide" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const result = await db.delete(ues).where(eq(ues.id, idUE)).returning();
|
||||
|
||||
if (result.length === 0) {
|
||||
return new Response(JSON.stringify({ error: "Ressource introuvable" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Ressource introuvable" }),
|
||||
{
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
|
||||
Reference in New Issue
Block a user