Compare commits
No commits in common. "578b52919914f0fd2ba07075c7fc62888f1292ed" and "64f9cd497fad43f765c11d3c6179ac02bf28c5e1" have entirely different histories.
578b529199
...
64f9cd497f
@ -1,11 +1,8 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { AuthorsController } from "apps/backend/src/app/authors/authors.controller";
|
||||
import { AuthorsService } from "apps/backend/src/app/authors/authors.service";
|
||||
import { CredentialsModule } from "apps/backend/src/app/credentials/credentials.module";
|
||||
import { DbModule } from "apps/backend/src/app/db/db.module";
|
||||
|
||||
@Module({
|
||||
imports: [DbModule, CredentialsModule],
|
||||
controllers: [AuthorsController],
|
||||
providers: [AuthorsService],
|
||||
})
|
||||
|
@ -1,11 +1,10 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { CredentialsModule } from "apps/backend/src/app/credentials/credentials.module";
|
||||
import { DbModule } from "../db/db.module";
|
||||
import { GroupsController } from "./groups.controller";
|
||||
import { GroupsService } from "./groups.service";
|
||||
|
||||
@Module({
|
||||
imports: [DbModule, CredentialsModule],
|
||||
imports: [DbModule],
|
||||
controllers: [GroupsController],
|
||||
providers: [GroupsService],
|
||||
})
|
||||
|
@ -1,5 +1,4 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
DefaultValuePipe,
|
||||
Delete,
|
||||
@ -14,7 +13,6 @@ 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 { MachinesService } from "apps/backend/src/app/machines/machines.service";
|
||||
|
||||
@Controller("machines")
|
||||
@ -31,9 +29,7 @@ export class MachinesController {
|
||||
//TODO DTO
|
||||
@UseGuards(AdminGuard)
|
||||
@Post("new")
|
||||
async newMachine(@Body() body: CreateMachineDto) {
|
||||
return await this.machineService.create(body.machineName, body.machineType);
|
||||
}
|
||||
async newMachine() {}
|
||||
|
||||
@UseGuards(AdminGuard)
|
||||
@Delete(":machineId")
|
||||
|
@ -1,11 +0,0 @@
|
||||
import { MaxLength, MinLength } from "class-validator";
|
||||
|
||||
export class CreateMachineDto {
|
||||
@MaxLength(128)
|
||||
@MinLength(4)
|
||||
machineName: string;
|
||||
|
||||
@MaxLength(64)
|
||||
@MinLength(2)
|
||||
machineType: string;
|
||||
}
|
@ -1,12 +1,7 @@
|
||||
import {
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { DbService } from "apps/backend/src/app/db/db.service";
|
||||
import {
|
||||
FilesForMachinesTable,
|
||||
FilesTable,
|
||||
MachinesTable,
|
||||
} from "apps/backend/src/app/db/schema";
|
||||
import { eq, ilike } from "drizzle-orm";
|
||||
@ -40,38 +35,18 @@ export class MachinesService {
|
||||
}
|
||||
|
||||
//TODO The method to create a machine
|
||||
async create(machineName: string, machineType: string) {
|
||||
try {
|
||||
const newMachine = await this.database
|
||||
.use()
|
||||
.insert(MachinesTable)
|
||||
.values({
|
||||
machineName,
|
||||
machineType,
|
||||
})
|
||||
.prepare("createMachine")
|
||||
.execute();
|
||||
console.log("Created a new machine.", newMachine);
|
||||
return newMachine;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw new InternalServerErrorException(
|
||||
"Insertion of the new machine failed, see the server console for more information.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO a method to delete a machine and delete the associated FilesTypeForMachine row
|
||||
|
||||
/**
|
||||
* Finds files associated with a specific machine.
|
||||
* Retrieves a list of files associated with a specific machine from the database.
|
||||
*
|
||||
* @param {number} limit - The maximum number of files to return.
|
||||
* @param {number} offset - The number of files to skip before starting to return results.
|
||||
* @param {string} searchField - The field to search within for files.
|
||||
* @param {string} machineId - The ID of the machine to find files for.
|
||||
* @returns {Promise<Array<Object>>} A promise that resolves to an array of files associated with the specified machine.
|
||||
* @throws {NotFoundException} If the machine ID is not found.
|
||||
* @param {number} limit - The maximum number of files to retrieve.
|
||||
* @param {number} offset - The offset from which to start retrieving files.
|
||||
* @param {string} searchField - The specific field to search within the files.
|
||||
* @param {string} machineId - The unique identifier of the machine.
|
||||
* @return {Promise<Array>} A promise that resolves to an array of file records for the machine.
|
||||
* @throws {NotFoundException} If the machine with the given id is not found.
|
||||
*/
|
||||
async findFilesForMachine(
|
||||
limit: number,
|
||||
@ -91,15 +66,11 @@ export class MachinesService {
|
||||
|
||||
return await this.database
|
||||
.use()
|
||||
.select({
|
||||
associatedMachine: FilesForMachinesTable.machineId,
|
||||
data: FilesTable,
|
||||
})
|
||||
.select()
|
||||
.from(FilesForMachinesTable)
|
||||
.where(eq(FilesForMachinesTable.machineId, machineId))
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.leftJoin(FilesTable, eq(FilesTable.uuid, FilesForMachinesTable.fileId))
|
||||
.prepare("findFilesForMachineId")
|
||||
.execute();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user