Add addFileType method to machines service
Implemented the `addFileType` method to link a file type to a machine. This includes database checks for valid machine and file type IDs, and the actual insertion logic. Updated imports and removed obsolete TODO comments.
This commit is contained in:
parent
fa65b62716
commit
a8a190198b
@ -8,6 +8,7 @@ import {
|
||||
FilesForMachinesTable,
|
||||
FilesTable,
|
||||
FilesTypeForMachine,
|
||||
FilesTypesTable,
|
||||
MachinesTable,
|
||||
} from "apps/backend/src/app/db/schema";
|
||||
import { and, eq, ilike } from "drizzle-orm";
|
||||
@ -80,7 +81,6 @@ export class MachinesService {
|
||||
* @throws {NotFoundException} If the machine ID or file type ID is not found.
|
||||
*/
|
||||
async removeFileType(machineId: string, fileTypeId: string) {
|
||||
//TODO Find machineId
|
||||
const machine = await this.database
|
||||
.use()
|
||||
.select()
|
||||
@ -90,7 +90,7 @@ export class MachinesService {
|
||||
.execute();
|
||||
if (machine.length !== 1)
|
||||
throw new NotFoundException("Machine id not found.");
|
||||
//TODO Find fileTypeId
|
||||
|
||||
const fileType = await this.database
|
||||
.use()
|
||||
.select()
|
||||
@ -120,9 +120,45 @@ export class MachinesService {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file type to a machine by their respective IDs.
|
||||
*
|
||||
* @param {string} machineId - The ID of the machine to which the file type will be added.
|
||||
* @param {string} fileTypeId - The ID of the file type to be added to the machine.
|
||||
* @return {Promise<object>} The result of the database insert operation.
|
||||
* @throws {NotFoundException} If the machine ID or file type ID are not found in the database.
|
||||
*/
|
||||
async addFileType(machineId: string, fileTypeId: string) {
|
||||
//TODO Find machineId
|
||||
//TODO Find fileTypeId
|
||||
const machine = await this.database
|
||||
.use()
|
||||
.select()
|
||||
.from(MachinesTable)
|
||||
.where(eq(MachinesTable.id, machineId))
|
||||
.prepare("findMachineById")
|
||||
.execute();
|
||||
if (machine.length !== 1)
|
||||
throw new NotFoundException("Machine id not found.");
|
||||
|
||||
const fileType = await this.database
|
||||
.use()
|
||||
.select()
|
||||
.from(FilesTypesTable)
|
||||
.where(eq(FilesTypesTable.id, fileTypeId))
|
||||
.prepare("findFileTypeById")
|
||||
.execute();
|
||||
if (fileType.length !== 1)
|
||||
throw new NotFoundException("File type not found.");
|
||||
|
||||
const insertFileType = await this.database
|
||||
.use()
|
||||
.insert(FilesTypeForMachine)
|
||||
.values({
|
||||
machineId,
|
||||
fileTypeId,
|
||||
})
|
||||
.prepare("insertFileTypeForMachine")
|
||||
.execute();
|
||||
return insertFileType;
|
||||
}
|
||||
|
||||
async getFilesTypes(machineId: string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user