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.
This commit is contained in:
Mathis H (Avnyr) 2024-10-03 13:52:45 +02:00
parent b2d084af4a
commit 221410dfb0
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -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