feat: username login support - recherche par username OU email
This commit is contained in:
45
server/db.ts
45
server/db.ts
@@ -9,6 +9,8 @@ import {
|
||||
appSettings,
|
||||
importLogs,
|
||||
InsertLocalUser,
|
||||
ideas,
|
||||
InsertIdea,
|
||||
} from "../drizzle/schema";
|
||||
import { ENV } from "./_core/env";
|
||||
|
||||
@@ -70,6 +72,7 @@ export async function getLocalUsers() {
|
||||
.select({
|
||||
id: localUsers.id,
|
||||
name: localUsers.name,
|
||||
username: localUsers.username,
|
||||
email: localUsers.email,
|
||||
role: localUsers.role,
|
||||
isActive: localUsers.isActive,
|
||||
@@ -315,3 +318,45 @@ export async function getImportStats() {
|
||||
totalNewRows,
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Boîte à idées ────────────────────────────────────────────────────────────
|
||||
|
||||
export async function createIdea(data: InsertIdea) {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
await db.insert(ideas).values(data);
|
||||
}
|
||||
|
||||
export async function getAllIdeas() {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
return db.select().from(ideas).orderBy(desc(ideas.createdAt));
|
||||
}
|
||||
|
||||
export async function getIdeasByUser(userId: number) {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
return db.select().from(ideas).where(eq(ideas.userId, userId)).orderBy(desc(ideas.createdAt));
|
||||
}
|
||||
|
||||
export async function repondreIdea(
|
||||
id: number,
|
||||
reponseAdmin: string,
|
||||
reponduPar: string,
|
||||
statut: "ouvert" | "en_cours" | "resolu" | "ferme"
|
||||
) {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
await db.update(ideas).set({
|
||||
reponseAdmin,
|
||||
reponduPar,
|
||||
reponduAt: new Date(),
|
||||
statut,
|
||||
}).where(eq(ideas.id, id));
|
||||
}
|
||||
|
||||
export async function updateIdeaStatut(id: number, statut: "ouvert" | "en_cours" | "resolu" | "ferme") {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
await db.update(ideas).set({ statut }).where(eq(ideas.id, id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user