Compare commits
2 Commits
e03d16bdb4
...
221410dfb0
Author | SHA1 | Date | |
---|---|---|---|
221410dfb0 | |||
b2d084af4a |
@ -1,14 +1,22 @@
|
|||||||
import { Controller, Get, Param, Post, StreamableFile } from '@nestjs/common';
|
import { Controller, DefaultValuePipe, Get, Param, ParseIntPipe, Post, Query, StreamableFile } from '@nestjs/common';
|
||||||
import { FilesService } from "./files.service";
|
import { FilesService } from "./files.service";
|
||||||
|
|
||||||
@Controller("files")
|
@Controller("files")
|
||||||
export class FilesController {
|
export class FilesController {
|
||||||
constructor(private readonly filesService: FilesService) {}
|
constructor(private readonly filesService: FilesService) {}
|
||||||
|
|
||||||
//TODO POST FILE
|
|
||||||
@Post('new')
|
@Post('new')
|
||||||
async saveFile() {
|
async saveFile() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('find')
|
||||||
|
async findMany(
|
||||||
|
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
||||||
|
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
||||||
|
@Query("search", new DefaultValuePipe("")) search: string,
|
||||||
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':fileId')
|
@Get(':fileId')
|
||||||
|
19
apps/backend/src/app/files/files.dto.ts
Normal file
19
apps/backend/src/app/files/files.dto.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { IsUUID, MaxLength, MinLength } from 'class-validator';
|
||||||
|
import { DefaultValuePipe } from '@nestjs/common';
|
||||||
|
|
||||||
|
|
||||||
|
export class CreateFilesDto {
|
||||||
|
@MaxLength(128)
|
||||||
|
@MinLength(4)
|
||||||
|
fileName: string;
|
||||||
|
|
||||||
|
@MaxLength(64)
|
||||||
|
@MinLength(2)
|
||||||
|
uploadedBy: string;
|
||||||
|
|
||||||
|
isDocumentation?: boolean;
|
||||||
|
isRestricted?: boolean;
|
||||||
|
|
||||||
|
@IsUUID()
|
||||||
|
groupId: string;
|
||||||
|
}
|
@ -2,7 +2,7 @@ import { Injectable, NotFoundException, StreamableFile } from '@nestjs/common';
|
|||||||
import { DbService } from 'apps/backend/src/app/db/db.service';
|
import { DbService } from 'apps/backend/src/app/db/db.service';
|
||||||
import { FilesTable } from 'apps/backend/src/app/db/schema';
|
import { FilesTable } from 'apps/backend/src/app/db/schema';
|
||||||
import { StorageService } from 'apps/backend/src/app/storage/storage.service';
|
import { StorageService } from 'apps/backend/src/app/storage/storage.service';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq, ilike } from 'drizzle-orm';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -55,10 +55,20 @@ export class FilesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO list the files
|
public async search(limit: number, offset: number, searchField: string) {
|
||||||
|
return await this.database
|
||||||
|
.use()
|
||||||
|
.select()
|
||||||
|
.from(FilesTable)
|
||||||
|
.where(ilike(FilesTable.fileName, String(searchField)))
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset)
|
||||||
|
.prepare("searchFiles")
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
//TODO save a file
|
//TODO save a file
|
||||||
public async set() {
|
public async save() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 { DbService } from 'apps/backend/src/app/db/db.service';
|
||||||
import { FilesGroupTable } from 'apps/backend/src/app/db/schema';
|
import { FilesGroupTable } from 'apps/backend/src/app/db/schema';
|
||||||
import { ilike } from 'drizzle-orm';
|
import { ilike } from 'drizzle-orm';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GroupsService {
|
export class GroupsService {
|
||||||
constructor(private readonly database: DbService) {}
|
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)
|
//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) {
|
async getGroupsByName(limit: number, offset: number, search: string) {
|
||||||
const result = await this.database.use()
|
return await this.database.use()
|
||||||
.select()
|
.select()
|
||||||
.from(FilesGroupTable)
|
.from(FilesGroupTable)
|
||||||
.where(ilike(FilesGroupTable.groupName, search))
|
.where(ilike(FilesGroupTable.groupName, search))
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.prepare("getGroupsByName")
|
.prepare("getGroupsByName")
|
||||||
.execute()
|
.execute();
|
||||||
console.log(`Found ${result.length} groups for search :\n > "${search}"`)
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO The method to create a group
|
//TODO The method to create a group
|
||||||
|
Loading…
x
Reference in New Issue
Block a user