From 221410dfb0f1942089d64a8b9ec82b1526c52333 Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 3 Oct 2024 13:52:45 +0200 Subject: [PATCH] Refactor getGroupsByName to streamline database call Replaced the variable assignment and logging with a streamlined return statement for better code readability and performance. This change improves the method's efficiency by reducing unnecessary steps and directly returning the result. --- apps/backend/src/app/groups/groups.service.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/backend/src/app/groups/groups.service.ts b/apps/backend/src/app/groups/groups.service.ts index a120625..b8565a6 100644 --- a/apps/backend/src/app/groups/groups.service.ts +++ b/apps/backend/src/app/groups/groups.service.ts @@ -1,24 +1,23 @@ -import { Injectable } from "@nestjs/common"; +import { Injectable } from '@nestjs/common'; import { DbService } from 'apps/backend/src/app/db/db.service'; import { FilesGroupTable } from 'apps/backend/src/app/db/schema'; import { ilike } from 'drizzle-orm'; + @Injectable() export class GroupsService { constructor(private readonly database: DbService) {} //TODO a method to fetch groups in the database by a specific search with limit, offset and a search field (can be blank) async getGroupsByName(limit: number, offset: number, search: string) { - const result = await this.database.use() + return await this.database.use() .select() .from(FilesGroupTable) .where(ilike(FilesGroupTable.groupName, search)) .limit(limit) .offset(offset) .prepare("getGroupsByName") - .execute() - console.log(`Found ${result.length} groups for search :\n > "${search}"`) - return result; + .execute(); } //TODO The method to create a group