parent
578f9301db
commit
1f061c7ea6
|
@ -25,9 +25,9 @@ export class UserGroupController {
|
|||
@Get()
|
||||
@Authorized("USERGROUP:GET")
|
||||
@ResponseSchema(UserGroup, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all usergroups.' })
|
||||
@OpenAPI({ description: 'Lists all groups. <br> The information provided might change while the project continues to evolve.' })
|
||||
getAll() {
|
||||
return this.userGroupsRepository.find();
|
||||
return this.userGroupsRepository.find({ relations: ["permissions"] });
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
|
@ -35,16 +35,16 @@ export class UserGroupController {
|
|||
@ResponseSchema(UserGroup)
|
||||
@ResponseSchema(UserGroupNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(UserGroupNotFoundError)
|
||||
@OpenAPI({ description: 'Returns a usergroup of a specified id (if it exists)' })
|
||||
@OpenAPI({ description: 'Lists all information about the group whose id got provided. <br> The information provided might change while the project continues to evolve.' })
|
||||
getOne(@Param('id') id: number) {
|
||||
return this.userGroupsRepository.findOne({ id: id });
|
||||
return this.userGroupsRepository.findOne({ id: id }, { relations: ["permissions"] });
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Authorized("USERGROUP:CREATE")
|
||||
@ResponseSchema(UserGroup)
|
||||
@ResponseSchema(UserGroupNotFoundError)
|
||||
@OpenAPI({ description: 'Create a new usergroup object (id will be generated automagicly).' })
|
||||
@OpenAPI({ description: 'Create a new group. <br> If you want to grant permissions to the group you have to create them seperately by posting to /api/permissions after creating the group.' })
|
||||
async post(@Body({ validate: true }) createUserGroup: CreateUserGroup) {
|
||||
let userGroup;
|
||||
try {
|
||||
|
@ -61,9 +61,9 @@ export class UserGroupController {
|
|||
@ResponseSchema(UserGroup)
|
||||
@ResponseSchema(UserGroupNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(UserGroupIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a usergroup object (id can't be changed)." })
|
||||
@OpenAPI({ description: "Update the group whose id you provided. <br> To change the permissions granted to the group please use /api/permissions instead. <br> Please remember that id's can't be changed." })
|
||||
async put(@Param('id') id: number, @EntityFromBody() userGroup: UserGroup) {
|
||||
let oldUserGroup = await this.userGroupsRepository.findOne({ id: id });
|
||||
let oldUserGroup = await this.userGroupsRepository.findOne({ id: id }, { relations: ["permissions"] });
|
||||
|
||||
if (!oldUserGroup) {
|
||||
throw new UserGroupNotFoundError()
|
||||
|
@ -82,11 +82,11 @@ export class UserGroupController {
|
|||
@ResponseSchema(ResponseUserGroup)
|
||||
@ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
||||
@OnUndefined(204)
|
||||
@OpenAPI({ description: 'Delete a specified usergroup (if it exists).' })
|
||||
@OpenAPI({ description: 'Delete the group whose id you provided. <br> If there are any permissions directly granted to the group they will get deleted as well. <br> Users associated with this group won\'t get deletet - just deassociated. <br> If no group with this id exists it will just return 204(no content).' })
|
||||
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||
let group = await this.userGroupsRepository.findOne({ id: id });
|
||||
let group = await this.userGroupsRepository.findOne({ id: id }, { relations: ["permissions"] });
|
||||
if (!group) { return null; }
|
||||
const responseGroup = await this.userGroupsRepository.findOne({ id: id }, { relations: ['permissions'] });;
|
||||
const responseGroup = await this.userGroupsRepository.findOne({ id: id }, { relations: ['permissions'] });
|
||||
|
||||
const permissionControler = new PermissionController();
|
||||
for (let permission of responseGroup.permissions) {
|
||||
|
|
Loading…
Reference in New Issue