Add CreateGroupDto and integrate DbModule with GroupsService

Introduced CreateGroupDto to enforce validation rules for group creation. Integrated DbModule into GroupsService and added a getGroupsByName method for database queries. Placeholder methods for group creation, deletion and file retrieval are also defined.
This commit is contained in:
Mathis H (Avnyr) 2024-10-03 12:08:17 +02:00
parent 6b8ea9cd00
commit 3eca2472c6
Signed by: Mathis
GPG Key ID: DD9E0666A747D126
4 changed files with 45 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import { import {
Body,
Controller, Controller,
DefaultValuePipe, DefaultValuePipe,
Delete, Delete,
@ -6,10 +7,11 @@ import {
Param, Param,
ParseIntPipe, ParseIntPipe,
Post, Post,
Query, Query
} from "@nestjs/common"; } from '@nestjs/common';
import { ISearchQuery } from "apps/backend/src/app/groups/groups.types"; import { ISearchQuery } from "apps/backend/src/app/groups/groups.types";
import { GroupsService } from "./groups.service"; import { GroupsService } from "./groups.service";
import { CreateGroupDto } from 'apps/backend/src/app/groups/groups.dto';
@Controller("groups") @Controller("groups")
export class GroupsController { export class GroupsController {
@ -22,12 +24,14 @@ 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,
) { ) {
const query = { limit, offset, search }; //TODO add service method
} }
//POST a new group //POST a new group
@Post("new") @Post("new")
async newGroup() {} async newGroup(@Body() dto : CreateGroupDto) {
}
//DELETE a group //DELETE a group
@Delete(":groupId") @Delete(":groupId")

View File

@ -0,0 +1,8 @@
import { IsString, MinLength, MaxLength } from 'class-validator';
export class CreateGroupDto {
@IsString()
@MinLength(4)
@MaxLength(64)
groupName: string;
}

View File

@ -1,8 +1,10 @@
import { Module } from "@nestjs/common"; import { Module } from "@nestjs/common";
import { GroupsController } from "./groups.controller"; import { GroupsController } from "./groups.controller";
import { GroupsService } from "./groups.service"; import { GroupsService } from "./groups.service";
import { DbModule } from '../db/db.module';
@Module({ @Module({
imports: [DbModule],
controllers: [GroupsController], controllers: [GroupsController],
providers: [GroupsService], providers: [GroupsService],
}) })

View File

@ -1,4 +1,30 @@
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() @Injectable()
export class GroupsService {} 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()
.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;
}
//TODO The method to create a group
//TODO a method to delete a group and place the associated file at a null group reference
//TODO a method to get the files of a group in the database by a specific search with limit, offset and a search field (can be blank)
}