Compare commits

..

5 Commits

Author SHA1 Message Date
e931822010
Refactor GroupsController with route updates and guards
Renamed route for fetching groups and added an admin guard to the delete endpoint. Also updated the endpoint for getting files associated with a group and removed unnecessary method bodies and comments.
2024-10-08 13:29:34 +02:00
d3feeb6d6a
Add TODO placeholder for future patch implementation
In the machines.controller.ts file, a TODO comment was added to indicate where a future patch method will be implemented. This serves as a reminder for developers to address this area later.
2024-10-08 13:29:22 +02:00
fd1742e9dc
Refactor response return statements in files controller
Reformat the return statements for better readability and consistency. The changes ensure that the status codes and response body are returned in a clearer and more maintainable format.
2024-10-08 13:26:32 +02:00
392446fa06
Add CredentialsModule to MachinesModule imports
This change includes the CredentialsModule in the imports array of the MachinesModule. This integration ensures that machine-related operations have access to necessary credential services.
2024-10-08 13:26:10 +02:00
f72b7ad9cb
Secure machine operations with AdminGuard
Added AdminGuard to POST and DELETE routes in MachinesController to ensure only admins can create or delete machines. Renamed endpoints for clarity and removed redundant code. This enhances security and improves API design.
2024-10-08 13:25:44 +02:00
4 changed files with 46 additions and 40 deletions

View File

@ -77,24 +77,30 @@ export class FilesController {
}
console.log("Executing save procedure...");
return res
return (
res
// @ts-ignore
.status(HttpStatus.CREATED)
.send(await this.filesService.save(fileBuffer, Params));
.send(await this.filesService.save(fileBuffer, Params))
);
} catch (err) {
console.error(err);
return res
return (
res
// @ts-ignore
.status(err.status || HttpStatus.INTERNAL_SERVER_ERROR)
.send(err);
.send(err)
);
}
});
req.on("error", (err) => {
return res
return (
res
// @ts-ignore
.status(err.status || HttpStatus.INTERNAL_SERVER_ERROR)
.send(err);
.send(err)
);
});
return;
@ -107,7 +113,7 @@ export class FilesController {
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
@Query("search", new DefaultValuePipe("")) search: string,
) {
return this.filesService.search(limit, offset, search)
return this.filesService.search(limit, offset, search);
}
@HttpCode(HttpStatus.FOUND)

View File

@ -7,42 +7,38 @@ import {
Param,
ParseIntPipe,
Post,
Query,
} from "@nestjs/common";
Query, UseGuards
} from '@nestjs/common';
import { CreateGroupDto } from "apps/backend/src/app/groups/groups.dto";
import { ISearchQuery } from "apps/backend/src/app/groups/groups.types";
import { GroupsService } from "./groups.service";
import { AdminGuard } from 'apps/backend/src/app/auth/auth.guard';
@Controller("groups")
export class GroupsController {
constructor(private readonly groupsService: GroupsService) {}
//GET all groups with limit and offset + optional search
@Get()
@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,
) {
//TODO add service method
}
) {}
//POST a new group
@Post("new")
async newGroup(@Body() dto: CreateGroupDto) {}
async newGroup() {}
//DELETE a group
@UseGuards(AdminGuard)
@Delete(":groupId")
async deleteGroup(@Param("groupId") groupId: string) {}
//GET files associated to group with limit and offset
@Get(":groupId")
async getForGroup(
//TODO Patch
@Get(":groupId/files")
async getFilesForGroup(
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
@Query("search", new DefaultValuePipe("")) search: string,
@Param("groupId") groupId: string,
) {
const query = { limit, offset, search };
}
) {}
}

View File

@ -4,38 +4,41 @@ import {
Delete,
Get,
Param,
ParseBoolPipe,
ParseIntPipe,
Post,
Query,
UseGuards,
} from "@nestjs/common";
import { AdminGuard } from "apps/backend/src/app/auth/auth.guard";
import { MachinesService } from "apps/backend/src/app/machines/machines.service";
@Controller("machines")
export class MachinesController {
constructor(private readonly machineService: MachinesService) {}
@Get()
@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,
) {
const query = { limit, offset, search };
}
) {}
@UseGuards(AdminGuard)
@Post("new")
async newMachine() {}
@UseGuards(AdminGuard)
@Delete(":machineId")
async deleteGroup(@Param("machineId") machineId: string) {}
async deleteMachine(@Param("machineId") machineId: string) {}
@Get(":groupId")
async getForGroup(
//TODO Patch
@Get(":machineId/files")
async getFilesForMachine(
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
@Query("search", new DefaultValuePipe("")) search: string,
@Param("machineId") machineId: string,
) {
const query = { limit, offset, search };
}
) {}
}

View File

@ -2,9 +2,10 @@ import { Module } from "@nestjs/common";
import { DbModule } from "apps/backend/src/app/db/db.module";
import { MachinesController } from "apps/backend/src/app/machines/machines.controller";
import { MachinesService } from "apps/backend/src/app/machines/machines.service";
import { CredentialsModule } from 'apps/backend/src/app/credentials/credentials.module';
@Module({
imports: [DbModule],
imports: [DbModule, CredentialsModule],
controllers: [MachinesController],
providers: [MachinesService],
})