Compare commits

..

No commits in common. "356b6869adb40cd3f50380b22b9160405dc0ef97" and "3bc440cbf897c31f1961abcf50be44ae8ceb0419" have entirely different histories.

5 changed files with 15 additions and 128 deletions

View File

@ -21,32 +21,23 @@ 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) {
return await this.authorService.delete(author);
}
async deleteAuthor(@Param("author") author: string) {}
//TODO Patch
@Get("files/:author")
async filterFilesForAuthor(
async getFilesForAuthor(
@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,
);
}
) {}
}

View File

@ -1,76 +1,4 @@
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 {
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();
}
}
export class AuthorsService {}

View File

@ -105,6 +105,7 @@ 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

View File

@ -14,64 +14,36 @@ import {
UseGuards,
} from "@nestjs/common";
import { AdminGuard } from "apps/backend/src/app/auth/auth.guard";
import {
CreateMachineDto,
TypeDto,
} from "apps/backend/src/app/machines/machines.dto";
import { CreateMachineDto } 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) {}
@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 Patch
@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);
}
//TODO CRUD fileType associated to machine
@HttpCode(HttpStatus.FOUND)
@Get("types/:machineId")
async getTypesOfMachine(@Param("machineId") machineId: string) {
return await this.machineService.getFilesTypes(machineId);
}
@HttpCode(HttpStatus.FOUND)
@HttpCode(HttpStatus.OK)
@Get("files/:machineId")
async getFilesForMachine(
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,

View File

@ -1,4 +1,4 @@
import { IsUUID, MaxLength, MinLength } from "class-validator";
import { MaxLength, MinLength } from "class-validator";
export class CreateMachineDto {
@MaxLength(128)
@ -9,8 +9,3 @@ export class CreateMachineDto {
@MinLength(2)
machineType: string;
}
export class TypeDto {
@IsUUID()
fileTypeId: string;
}