Copied put roles into admin namespace
This commit is contained in:
parent
6c2de42621
commit
47885ddbe1
@ -1,11 +1,12 @@
|
|||||||
import { Response, Request } from "express";
|
import { Response, Request } from "express";
|
||||||
import { Controller, Get } from "@ControllerPattern/index";
|
import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import RolesService from "@Services/admin/RolesService/RolesService";
|
import RolesService from "@Services/admin/RolesService/RolesService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Role } from "le-coffre-resources/dist/Admin";
|
import { Role } from "le-coffre-resources/dist/Admin";
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -74,4 +75,45 @@ export default class RolesController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Modify a specific role by uid
|
||||||
|
*/
|
||||||
|
@Put("/api/v1/super-admin/roles/:uid", [authHandler, ruleHandler])
|
||||||
|
protected async put(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleFound = await this.rolesService.getByUid(uid);
|
||||||
|
|
||||||
|
if (!roleFound) {
|
||||||
|
this.httpNotFoundRequest(response, "role not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//init IRole resource with request body values
|
||||||
|
const roleEntity = Role.hydrate<Role>(req.body);
|
||||||
|
|
||||||
|
//validate role
|
||||||
|
await validateOrReject(roleEntity, { groups: ["updateRole"] });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const roleEntityUpdated = await this.rolesService.update(roleEntity);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const role = Role.hydrate<Role>(roleEntityUpdated, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, role);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user