Add missing semicolons and format code for consistency

Updated the controllers and services by adding missing semicolons to ensure code consistency and prevent potential runtime errors. Reformatted the import statements to enhance readability and maintain a uniform style across the codebase.
This commit is contained in:
Mathis H (Avnyr) 2024-10-14 15:16:13 +02:00
parent 04cc2daf43
commit 1c78912f99
Signed by: Mathis
GPG Key ID: DD9E0666A747D126
2 changed files with 35 additions and 22 deletions

View File

@ -25,18 +25,18 @@ export class GroupsController {
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number, @Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
@Query("search", new DefaultValuePipe("")) search: string, @Query("search", new DefaultValuePipe("")) search: string,
) { ) {
return await this.groupsService.getGroupsByName(limit, offset, search) return await this.groupsService.getGroupsByName(limit, offset, search);
} }
@Post("new") @Post("new")
async newGroup(@Body() body: CreateGroupDto) { async newGroup(@Body() body: CreateGroupDto) {
return await this.groupsService.newGroup(body.groupName) return await this.groupsService.newGroup(body.groupName);
} }
@UseGuards(AdminGuard) @UseGuards(AdminGuard)
@Delete(":groupId") @Delete(":groupId")
async deleteGroup(@Param("groupId") groupId: string) { async deleteGroup(@Param("groupId") groupId: string) {
return await this.groupsService.deleteGroup(groupId) return await this.groupsService.deleteGroup(groupId);
} }
//TODO Patch //TODO Patch
@ -48,6 +48,11 @@ export class GroupsController {
@Query("search", new DefaultValuePipe("")) search: string, @Query("search", new DefaultValuePipe("")) search: string,
@Param("groupId") groupId: string, @Param("groupId") groupId: string,
) { ) {
return await this.groupsService.findFilesForGroup(limit, offset, search, groupId) return await this.groupsService.findFilesForGroup(
limit,
offset,
search,
groupId,
);
} }
} }

View File

@ -1,7 +1,11 @@
import { Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common'; import {
Injectable,
InternalServerErrorException,
NotFoundException,
} from "@nestjs/common";
import { DbService } from "apps/backend/src/app/db/db.service"; import { DbService } from "apps/backend/src/app/db/db.service";
import { FilesGroupTable, FilesTable } from 'apps/backend/src/app/db/schema'; import { FilesGroupTable, FilesTable } from "apps/backend/src/app/db/schema";
import { and, eq, ilike } from 'drizzle-orm'; import { and, eq, ilike } from "drizzle-orm";
@Injectable() @Injectable()
export class GroupsService { export class GroupsService {
@ -19,7 +23,6 @@ export class GroupsService {
.execute(); .execute();
} }
//TODO The method to create a group
async newGroup(groupName: string) { async newGroup(groupName: string) {
return await this.database return await this.database
.use() .use()
@ -32,9 +35,9 @@ export class GroupsService {
.execute(); .execute();
} }
//TODO a method to delete a group and place the associated file at a null group reference
async deleteGroup(groupId: string) { async deleteGroup(groupId: string) {
const groupInDb = await this.database.use() const groupInDb = await this.database
.use()
.select() .select()
.from(FilesGroupTable) .from(FilesGroupTable)
.where(eq(FilesGroupTable.uuid, groupId)) .where(eq(FilesGroupTable.uuid, groupId))
@ -43,24 +46,24 @@ export class GroupsService {
if (groupInDb.length === 0) throw new NotFoundException("Group not found"); if (groupInDb.length === 0) throw new NotFoundException("Group not found");
// Replace entry by null // Replace entry by null
await this.database await this.database
.use() .use()
.update(FilesTable) .update(FilesTable)
// @ts-ignore // @ts-ignore
.set({ groupId: null }) .set({ groupId: null })
.where(eq(FilesTable.groupId, groupId)) .where(eq(FilesTable.groupId, groupId))
.prepare("updateFilesGroupReference") .prepare("updateFilesGroupReference")
.execute(); .execute();
try { try {
await this.database await this.database
.use() .use()
.delete(FilesGroupTable) .delete(FilesGroupTable)
.where(eq(FilesGroupTable.uuid, groupId)) .where(eq(FilesGroupTable.uuid, groupId));
return true return true;
} catch (e) { } catch (e) {
throw new InternalServerErrorException("Error while deleting group"); throw new InternalServerErrorException("Error while deleting group");
} }
} }
async findFilesForGroup( async findFilesForGroup(
limit: number, limit: number,
offset: number, offset: number,
@ -71,10 +74,15 @@ export class GroupsService {
.use() .use()
.select() .select()
.from(FilesTable) .from(FilesTable)
.where(and(eq(FilesTable.groupId, groupId), ilike(FilesTable.fileName, String(`%${searchField}%`)) ) ) .where(
and(
eq(FilesTable.groupId, groupId),
ilike(FilesTable.fileName, String(`%${searchField}%`)),
),
)
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.prepare('findFilesInGroup') .prepare("findFilesInGroup")
.execute(); .execute();
} }
} }