deck handling fixed, new launch config for nest.js
This commit is contained in:
parent
a718c87c63
commit
3228f0033b
|
|
@ -2,13 +2,6 @@
|
|||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ng serve",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "npm: start",
|
||||
"url": "http://localhost:4200/"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
|
|
@ -28,9 +21,8 @@
|
|||
"name": "Debug NestJS API",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "npx",
|
||||
"runtimeExecutable": "/home/aknuth/.nvm/versions/node/v22.14.0/bin/npx",
|
||||
"runtimeArgs": ["nest", "start", "--debug", "--watch"],
|
||||
"port": 9229,
|
||||
"cwd": "${workspaceFolder}/api",
|
||||
"envFile": "${workspaceFolder}/api/.env",
|
||||
"console": "integratedTerminal",
|
||||
|
|
|
|||
|
|
@ -57,8 +57,11 @@ export class DrizzleService {
|
|||
.where(and(eq(deck.user, user.email), sql`bildid IS NULL`))
|
||||
.limit(maxDecks);
|
||||
|
||||
// Ergebnis-Array, das später zurückgegeben wird
|
||||
let result: Array<any> = [];
|
||||
|
||||
// Für jedes Deck werden nun die zugehörigen Bilder (Einträge mit bildid) abgerufen.
|
||||
const imagesForDecks = await Promise.all(
|
||||
await Promise.all(
|
||||
deckHeaders.map(async (header: any) => {
|
||||
const images: Array<any> = await this.db
|
||||
.select()
|
||||
|
|
@ -70,7 +73,12 @@ export class DrizzleService {
|
|||
sql`bildid IS NOT NULL`,
|
||||
),
|
||||
);
|
||||
const minimizedImagesArray = (() => {
|
||||
|
||||
if (images.length === 0) {
|
||||
// Wenn keine Bilder vorhanden sind, füge den Header selbst hinzu
|
||||
result.push(header);
|
||||
} else {
|
||||
// Wenn Bilder vorhanden sind, verarbeite sie wie zuvor
|
||||
const selectedBildnamen: Array<any> = [];
|
||||
// Sammle die ersten maxImages verschiedenen Bildnamen
|
||||
for (const item of images) {
|
||||
|
|
@ -82,16 +90,26 @@ export class DrizzleService {
|
|||
}
|
||||
}
|
||||
// Filtere das Array, um nur Einträge mit diesen Bildnamen zu behalten
|
||||
return images.filter((item) =>
|
||||
const filteredImages = images.filter((item) =>
|
||||
selectedBildnamen.includes(item.bildname),
|
||||
);
|
||||
})();
|
||||
return { minimizedImagesArray };
|
||||
//return { images };
|
||||
// Füge die gefilterten Bilder zum Ergebnis hinzu
|
||||
result = result.concat(filteredImages);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return imagesForDecks.flatMap((item) => item.minimizedImagesArray);
|
||||
// Sortiere das Ergebnis nach dem Einfügedatum (absteigend, neueste zuerst)
|
||||
result.sort((a, b) => {
|
||||
// Wenn inserted null oder undefined ist, setze es ans Ende
|
||||
if (!a.inserted) return 1;
|
||||
if (!b.inserted) return -1;
|
||||
|
||||
// Vergleiche die Daten (neuere Einträge zuerst)
|
||||
return new Date(a.inserted).getTime() - new Date(b.inserted).getTime();
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,8 +126,7 @@ export class DrizzleService {
|
|||
const deckCountResult = await this.db
|
||||
.select({ count: sql`count(*) as count` })
|
||||
.from(deck)
|
||||
.where(and(eq(deck.user, user.email), sql`bildid IS NULL`))
|
||||
.all();
|
||||
.where(and(eq(deck.user, user.email), sql`bildid IS NULL`));
|
||||
const deckCount = Number(deckCountResult[0].count);
|
||||
if (deckCount >= maxDecks) {
|
||||
throw new HttpException(
|
||||
|
|
@ -235,8 +252,7 @@ export class DrizzleService {
|
|||
eq(deck.deckname, data.deckname),
|
||||
sql`bildid IS NOT NULL`,
|
||||
),
|
||||
)
|
||||
.all();
|
||||
);
|
||||
const distinctImageCount = Number(distinctImagesResult[0].count);
|
||||
if (distinctImageCount >= maxImages) {
|
||||
throw new HttpException(
|
||||
|
|
@ -389,8 +405,7 @@ export class DrizzleService {
|
|||
const existingImages = await this.db
|
||||
.select()
|
||||
.from(deck)
|
||||
.where(and(eq(deck.bildid, bildId), eq(deck.user, user.email)))
|
||||
.all();
|
||||
.where(and(eq(deck.bildid, bildId), eq(deck.user, user.email)));
|
||||
if (existingImages.length === 0) {
|
||||
throw new HttpException('Deck not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
|
@ -445,10 +460,7 @@ export class DrizzleService {
|
|||
*/
|
||||
async getDistinctBildIds(user: User): Promise<string[]> {
|
||||
try {
|
||||
const result = await this.db
|
||||
.selectDistinct([deck.bildid])
|
||||
.from(deck)
|
||||
.all();
|
||||
const result = await this.db.selectDistinct([deck.bildid]).from(deck);
|
||||
const usedIds = result
|
||||
.map((row: any) => row['0'])
|
||||
.filter((id: string | null) => id !== null) as string[];
|
||||
|
|
|
|||
Loading…
Reference in New Issue