mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
wip
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Get,
|
||||
Delete,
|
||||
Param,
|
||||
@@ -45,7 +46,7 @@ export class RolesController {
|
||||
};
|
||||
}
|
||||
|
||||
@Post(':id')
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'Edit an existing role' })
|
||||
@ApiParam({ name: 'id', description: 'Role ID' })
|
||||
@ApiBody({ type: EditRoleDto })
|
||||
|
||||
@@ -17,7 +17,7 @@ export class EditRoleService {
|
||||
|
||||
@Inject(Role.name)
|
||||
private readonly roleModel: TenantModelProxy<typeof Role>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Edits details of the given role on the storage.
|
||||
@@ -30,7 +30,13 @@ export class EditRoleService {
|
||||
|
||||
// Retrieve the given role or throw not found serice error.
|
||||
const oldRole = await this.roleModel().query().findById(roleId);
|
||||
const permissions = editRoleDTO.permissions;
|
||||
// Transform permissions: map permissionId to id for Objection.js upsertGraph
|
||||
const permissions = editRoleDTO.permissions.map((perm) => ({
|
||||
id: perm.permissionId,
|
||||
subject: perm.subject,
|
||||
ability: perm.ability,
|
||||
value: perm.value,
|
||||
}));
|
||||
|
||||
// Updates the role on the storage.
|
||||
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
|
||||
|
||||
@@ -38,7 +38,7 @@ export class CommandRolePermissionDto {
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
export class CreateRolePermissionDto extends CommandRolePermissionDto {}
|
||||
export class CreateRolePermissionDto extends CommandRolePermissionDto { }
|
||||
export class EditRolePermissionDto extends CommandRolePermissionDto {
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
@@ -83,9 +83,9 @@ export class EditRoleDto extends CommandRoleDto {
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => CommandRolePermissionDto)
|
||||
@Type(() => EditRolePermissionDto)
|
||||
@ApiProperty({
|
||||
type: [CommandRolePermissionDto],
|
||||
type: [EditRolePermissionDto],
|
||||
description: 'The permissions of the role',
|
||||
})
|
||||
permissions: Array<EditRolePermissionDto>;
|
||||
|
||||
Reference in New Issue
Block a user