Compare commits
5 Commits
3bc440cbf8
...
356b6869ad
Author | SHA1 | Date | |
---|---|---|---|
356b6869ad | |||
030b5c814c | |||
16ed8d3420 | |||
0874ffb835 | |||
3d67b8ad18 |
@ -21,23 +21,32 @@ export class AuthorsController {
|
||||
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
||||
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
||||
@Query("search", new DefaultValuePipe("")) search: string,
|
||||
) {}
|
||||
) {
|
||||
return await this.authorService.find(limit, offset, search);
|
||||
}
|
||||
|
||||
//TODO DTO
|
||||
@Post("new")
|
||||
async newAuthor() {}
|
||||
|
||||
@UseGuards(AdminGuard)
|
||||
@Delete(":autor")
|
||||
async deleteAuthor(@Param("author") author: string) {}
|
||||
async deleteAuthor(@Param("author") author: string) {
|
||||
return await this.authorService.delete(author);
|
||||
}
|
||||
|
||||
//TODO Patch
|
||||
|
||||
@Get("files/:author")
|
||||
async getFilesForAuthor(
|
||||
async filterFilesForAuthor(
|
||||
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
||||
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
||||
@Query("search", new DefaultValuePipe("")) search: string,
|
||||
@Param("machineId") author: string,
|
||||
) {}
|
||||
) {
|
||||
return await this.authorService.findFileForAuthor(
|
||||
limit,
|
||||
offset,
|
||||
search,
|
||||
author,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,76 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { DbService } from "apps/backend/src/app/db/db.service";
|
||||
import { FilesTable } from "apps/backend/src/app/db/schema";
|
||||
import { and, eq, ilike } from "drizzle-orm";
|
||||
|
||||
@Injectable()
|
||||
export class AuthorsService {}
|
||||
export class AuthorsService {
|
||||
constructor(private readonly database: DbService) {}
|
||||
|
||||
/**
|
||||
* Searches for records in the FilesTable based on the uploadedBy field.
|
||||
*
|
||||
* @param {number} limit - The maximum number of records to return.
|
||||
* @param {number} offset - The number of records to skip before starting to collect the result set.
|
||||
* @param {string} searchField - The search term to filter the uploadedBy field.
|
||||
* @return {Promise<Array>} A promise that resolves to an array of matching records.
|
||||
*/
|
||||
async find(limit: number, offset: number, searchField: string) {
|
||||
return this.database
|
||||
.use()
|
||||
.select()
|
||||
.from(FilesTable)
|
||||
.where(ilike(FilesTable.uploadedBy, String(`%${searchField}%`)))
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.prepare("searchAuthor")
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds files uploaded by a specific author based on search criteria.
|
||||
*
|
||||
* @param {number} limit - The maximum number of files to return.
|
||||
* @param {number} offset - The offset for pagination purposes.
|
||||
* @param {string} searchField - The search term to filter files by their name.
|
||||
* @param {string} author - The author of the files.
|
||||
* @return {Promise<Array>} A promise that resolves to an array of files matching the criteria.
|
||||
*/
|
||||
async findFileForAuthor(
|
||||
limit: number,
|
||||
offset: number,
|
||||
searchField: string,
|
||||
author: string,
|
||||
) {
|
||||
return this.database
|
||||
.use()
|
||||
.select()
|
||||
.from(FilesTable)
|
||||
.where(
|
||||
and(
|
||||
eq(FilesTable.uploadedBy, author),
|
||||
ilike(FilesTable.fileName, String(`%${searchField}%`)),
|
||||
),
|
||||
)
|
||||
.prepare("searchAuthor")
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the reference of an author from the FilesTable by replacing the uploadedBy field with "none".
|
||||
*
|
||||
* @param {string} authorName - The name of the author whose reference is to be deleted.
|
||||
* @return {Promise<void>} A promise that resolves when the operation is complete.
|
||||
*/
|
||||
async delete(authorName: string) {
|
||||
await this.database
|
||||
.use()
|
||||
.update(FilesTable)
|
||||
.set({
|
||||
uploadedBy: "none",
|
||||
})
|
||||
.where(eq(FilesTable.uploadedBy, authorName))
|
||||
.prepare("replaceAuthorFieldForMatch")
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,6 @@ export const FilesTable = pgTable("files", {
|
||||
});
|
||||
|
||||
export const FilesGroupTable = pgTable("f_groups", {
|
||||
// Unique identifier on a technical aspect.
|
||||
uuid: p.uuid("uuid").unique().primaryKey().defaultRandom().notNull(),
|
||||
|
||||
groupName: p
|
||||
|
@ -14,36 +14,64 @@ import {
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { AdminGuard } from "apps/backend/src/app/auth/auth.guard";
|
||||
import { CreateMachineDto } from "apps/backend/src/app/machines/machines.dto";
|
||||
import {
|
||||
CreateMachineDto,
|
||||
TypeDto,
|
||||
} from "apps/backend/src/app/machines/machines.dto";
|
||||
import { MachinesService } from "apps/backend/src/app/machines/machines.service";
|
||||
|
||||
@Controller("machines")
|
||||
export class MachinesController {
|
||||
constructor(private readonly machineService: MachinesService) {}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@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,
|
||||
) {}
|
||||
) {
|
||||
return await this.machineService.findMany(limit, offset, search);
|
||||
}
|
||||
|
||||
//TODO DTO
|
||||
@UseGuards(AdminGuard)
|
||||
@Post("new")
|
||||
async newMachine(@Body() body: CreateMachineDto) {
|
||||
return await this.machineService.create(body.machineName, body.machineType);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.ACCEPTED)
|
||||
@UseGuards(AdminGuard)
|
||||
@Delete(":machineId")
|
||||
async deleteMachine(@Param("machineId") machineId: string) {}
|
||||
|
||||
//TODO Patch
|
||||
@HttpCode(HttpStatus.ACCEPTED)
|
||||
@UseGuards(AdminGuard)
|
||||
@Post("types/:machineId")
|
||||
async addTypeToMachine(
|
||||
@Param("machineId") machineId: string,
|
||||
@Body() body: TypeDto,
|
||||
) {
|
||||
return await this.machineService.addFileType(machineId, body.fileTypeId);
|
||||
}
|
||||
|
||||
//TODO CRUD fileType associated to machine
|
||||
@HttpCode(HttpStatus.ACCEPTED)
|
||||
@UseGuards(AdminGuard)
|
||||
@Delete("types/:machineId")
|
||||
async remTypeToMachine(
|
||||
@Param("machineId") machineId: string,
|
||||
@Body() body: TypeDto,
|
||||
) {
|
||||
return await this.machineService.removeFileType(machineId, body.fileTypeId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@HttpCode(HttpStatus.FOUND)
|
||||
@Get("types/:machineId")
|
||||
async getTypesOfMachine(@Param("machineId") machineId: string) {
|
||||
return await this.machineService.getFilesTypes(machineId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.FOUND)
|
||||
@Get("files/:machineId")
|
||||
async getFilesForMachine(
|
||||
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { MaxLength, MinLength } from "class-validator";
|
||||
import { IsUUID, MaxLength, MinLength } from "class-validator";
|
||||
|
||||
export class CreateMachineDto {
|
||||
@MaxLength(128)
|
||||
@ -9,3 +9,8 @@ export class CreateMachineDto {
|
||||
@MinLength(2)
|
||||
machineType: string;
|
||||
}
|
||||
|
||||
export class TypeDto {
|
||||
@IsUUID()
|
||||
fileTypeId: string;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user