Skip to content

Commit

Permalink
fix(controllers): Update for rucken
Browse files Browse the repository at this point in the history
  • Loading branch information
EndyKaufman committed Jan 16, 2018
1 parent a4424f5 commit 5076527
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/libs/core/controllers/content-types.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Permissions } from '../decorators/permissions.decorator';

@ApiUseTags('content-types')
@ApiBearerAuth()
@Controller('/api/content-types')
@Controller('/api/content_types')
@UseGuards(AccessGuard)
export class ContentTypesController {
constructor(
Expand Down
8 changes: 6 additions & 2 deletions src/libs/core/controllers/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export class GroupsController {
@Param('id', new ParseIntPipe()) id
) {
try {
let object = await this.groupsRepository.findOneOrFail(id);
let object = await this.groupsRepository.findOneOrFail(
id,
{ relations: ['permissions', 'permissions.contentType'] }
);
return plainToClass(OutGroupDto, object);
} catch (error) {
throw error;
Expand Down Expand Up @@ -145,7 +148,8 @@ export class GroupsController {
try {
const objects = await this.groupsRepository.findAndCount({
skip: (curPage - 1) * perPage,
take: perPage
take: perPage,
relations: ['permissions', 'permissions.contentType']
});
return plainToClass(OutGroupsDto, {
groups: objects[0],
Expand Down
12 changes: 8 additions & 4 deletions src/libs/core/controllers/permissions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export class PermissionsController {
@Param('id', new ParseIntPipe()) id
) {
try {
let object = await this.permissionsRepository.findOneOrFail(id);
let object = await this.permissionsRepository.findOneOrFail(
id,
{ relations: ['contentType'] }
);
return plainToClass(OutPermissionDto, object);
} catch (error) {
throw error;
Expand Down Expand Up @@ -155,13 +158,14 @@ export class PermissionsController {
try {
let objects: [Permission[], number];
let qb = this.permissionsRepository.createQueryBuilder('permission');
qb = qb.leftJoinAndSelect('permission.contentType', 'contentType');
if (group) {
qb = qb.leftJoin('permission.groups', 'group')
qb = qb
.leftJoin('permission.groups', 'group')
.where('group.id = :group', { group: group });
}
if (contentType) {
qb = qb.leftJoin('permission.content_type', 'content_type')
.where('content_type.id = :contentType', { contentType: contentType });
qb = qb.where('contentType.id = :contentType', { contentType: contentType });
}
qb = qb.skip((curPage - 1) * perPage)
.take(perPage);
Expand Down
8 changes: 4 additions & 4 deletions src/libs/core/controllers/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class UsersController {
) {
try {
let object = plainToClass(User, dto);
object.setPassword(object.password);
object.setPassword(dto.password);
object = await this.usersRepository.save(object)
return plainToClass(OutUserDto, object);
} catch (error) {
Expand All @@ -75,7 +75,7 @@ export class UsersController {
try {
let object = plainToClass(User, dto);
object.id = id;
object.setPassword(object.password);
object.setPassword(dto.password);
object = await this.usersRepository.save(object);
return plainToClass(OutUserDto, object);
} catch (error) {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class UsersController {
try {
let object = await this.usersRepository.findOneOrFail(
id,
{ relations: ['groups'] }
{ relations: ['groups', 'groups.permissions', 'permissions.contentType'] }
);
return plainToClass(OutUserDto, object);
} catch (error) {
Expand Down Expand Up @@ -158,7 +158,7 @@ export class UsersController {
objects = await this.usersRepository.findAndCount({
skip: (curPage - 1) * perPage,
take: perPage,
relations: ['groups']
relations: ['groups', 'groups.permissions', 'permissions.contentType']
});
} else {
let qb = this.usersRepository.createQueryBuilder('user');
Expand Down

0 comments on commit 5076527

Please sign in to comment.