-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🔥 [EXL-67] support policies page of a group
support policies page of a group
- Loading branch information
tal-rofe
committed
Sep 22, 2022
1 parent
be14516
commit 0693db4
Showing
68 changed files
with
1,357 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apps/backend/src/modules/user/modules/groups/classes/edit-description.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString, MinLength } from 'class-validator'; | ||
|
||
import { IsNullable } from '@/decorators/is-nullable.decorator'; | ||
|
||
export class EditDescriptionDto { | ||
@ApiProperty({ | ||
type: String, | ||
nullable: true, | ||
description: 'The new description for a group', | ||
example: 'Yazif Group Description', | ||
}) | ||
@IsString() | ||
@IsNullable() | ||
@MinLength(1) | ||
readonly description!: string | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/backend/src/modules/user/modules/groups/commands/contracts/edit-description.contact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class EditDescriptionContract { | ||
constructor(public readonly groupId: string, public readonly description: string | null) {} | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/backend/src/modules/user/modules/groups/commands/handlers/edit-description.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CommandHandler, type ICommandHandler } from '@nestjs/cqrs'; | ||
|
||
import { DBGroupService } from '@/modules/database/group.service'; | ||
|
||
import { EditDescriptionContract } from '../contracts/edit-description.contact'; | ||
|
||
@CommandHandler(EditDescriptionContract) | ||
export class EditDescriptionHandler implements ICommandHandler<EditDescriptionContract> { | ||
constructor(private readonly dbGroupService: DBGroupService) {} | ||
|
||
async execute(contract: EditDescriptionContract) { | ||
await this.dbGroupService.editGroupDescription(contract.groupId, contract.description || null); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
apps/backend/src/modules/user/modules/groups/commands/handlers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { DeleteHandler } from './delete.handler'; | ||
import { EditDescriptionHandler } from './edit-description.handler'; | ||
import { EditLabelHandler } from './edit-label.handler'; | ||
|
||
export const CommandHandlers = [EditLabelHandler, DeleteHandler]; | ||
export const CommandHandlers = [EditLabelHandler, DeleteHandler, EditDescriptionHandler]; |
9 changes: 9 additions & 0 deletions
9
apps/backend/src/modules/user/modules/groups/data/libraries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PolicyLibrary } from '@prisma/client'; | ||
|
||
export const libariesLanguages: Record<PolicyLibrary, string> = { | ||
ESLint: 'JavaScript', | ||
Stylelint: 'CSS', | ||
Depcheck: 'JavaScript', | ||
Inflint: 'Agnostic', | ||
Prettier: 'Agnostic', | ||
}; |
51 changes: 51 additions & 0 deletions
51
apps/backend/src/modules/user/modules/groups/edit-description.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Body, Controller, HttpCode, HttpStatus, Logger, Param, Patch, UseGuards } from '@nestjs/common'; | ||
import { CommandBus } from '@nestjs/cqrs'; | ||
import { | ||
ApiBearerAuth, | ||
ApiInternalServerErrorResponse, | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiTags, | ||
ApiUnauthorizedResponse, | ||
} from '@nestjs/swagger'; | ||
|
||
import { CurrentUserId } from '@/decorators/current-user-id.decorator'; | ||
import { BelongingGroupGuard } from '@/guards/belonging-group.guard'; | ||
|
||
import Routes from './groups.routes'; | ||
import { EditDescriptionDto } from './classes/edit-description.dto'; | ||
import { EditDescriptionContract } from './commands/contracts/edit-description.contact'; | ||
|
||
@ApiTags('Groups') | ||
@Controller(Routes.CONTROLLER) | ||
export class EditDescriptionController { | ||
private readonly logger = new Logger(EditDescriptionController.name); | ||
|
||
constructor(private readonly commandBus: CommandBus) {} | ||
|
||
@ApiOperation({ description: "Edit a group's description with a new description and its identifier" }) | ||
@ApiBearerAuth('access-token') | ||
@ApiOkResponse({ description: 'If successfully edited the description of the group' }) | ||
@ApiUnauthorizedResponse({ | ||
description: 'If access token is either missing or invalid, or group does not belong to user', | ||
}) | ||
@ApiInternalServerErrorResponse({ description: 'If failed to edit the description of the group' }) | ||
@UseGuards(BelongingGroupGuard) | ||
@Patch(Routes.EDIT_DESCRIPTION) | ||
@HttpCode(HttpStatus.OK) | ||
public async editDescription( | ||
@CurrentUserId() userId: string, | ||
@Body() editDescriptionDto: EditDescriptionDto, | ||
@Param('group_id') groupId: string, | ||
): Promise<void> { | ||
this.logger.log(`Will try to edit a group with an Id ${groupId} for a user with an Id: ${userId}`); | ||
|
||
await this.commandBus.execute<EditDescriptionContract, void>( | ||
new EditDescriptionContract(groupId, editDescriptionDto.description), | ||
); | ||
|
||
this.logger.log( | ||
`Successfully edited a group with an Id: ${groupId} for a user with an Id: ${userId}`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
apps/backend/src/modules/user/modules/groups/get-inline-policies.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Controller, Get, HttpCode, HttpStatus, Logger, Param, Query, UseGuards } from '@nestjs/common'; | ||
import { QueryBus } from '@nestjs/cqrs'; | ||
import { | ||
ApiBearerAuth, | ||
ApiInternalServerErrorResponse, | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiTags, | ||
ApiUnauthorizedResponse, | ||
} from '@nestjs/swagger'; | ||
|
||
import { CurrentUserId } from '@/decorators/current-user-id.decorator'; | ||
import { BelongingGroupGuard } from '@/guards/belonging-group.guard'; | ||
|
||
import Routes from './groups.routes'; | ||
import { GetInlinePoliciesResponse } from './classes/responses'; | ||
import { GetInlinePoliciesContract } from './queries/contracts/get-inline-policies.contract'; | ||
import type { IGroupInlinePolicies } from './interfaces/group-policies'; | ||
|
||
@ApiTags('Groups') | ||
@Controller(Routes.CONTROLLER) | ||
export class GetInlinePoliciesController { | ||
private readonly logger = new Logger(GetInlinePoliciesController.name); | ||
|
||
constructor(private readonly queryBus: QueryBus) {} | ||
|
||
@ApiBearerAuth('access-token') | ||
@ApiOperation({ description: 'Get all inline policies of a group' }) | ||
@ApiOkResponse({ | ||
description: 'If successfully got all inline policies of a group', | ||
type: GetInlinePoliciesResponse, | ||
}) | ||
@ApiUnauthorizedResponse({ | ||
description: 'If access token is either missing or invalid', | ||
}) | ||
@ApiInternalServerErrorResponse({ description: 'If failed to fetch all inline policies of a group' }) | ||
@UseGuards(BelongingGroupGuard) | ||
@Get(Routes.GET_INLINE_POLICIES) | ||
@HttpCode(HttpStatus.OK) | ||
public async getInlinePolicies( | ||
@CurrentUserId() userId: string, | ||
@Param('group_id') groupId: string, | ||
@Query('p') page?: string, | ||
): Promise<GetInlinePoliciesResponse> { | ||
this.logger.log( | ||
`Will try to fetch all inline policies of a group with an ID: "${groupId}" belong to user with an Id: "${userId}"`, | ||
); | ||
|
||
const inlinePolicies = await this.queryBus.execute<GetInlinePoliciesContract, IGroupInlinePolicies>( | ||
new GetInlinePoliciesContract(groupId, page), | ||
); | ||
|
||
this.logger.log( | ||
`Successfully got all inline policies of a group with an ID: "${groupId}" belong to user with an Id: "${userId}"`, | ||
); | ||
|
||
return inlinePolicies; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
const Routes = { | ||
CONTROLLER: 'groups', | ||
CREATE: '', | ||
EDIT_LABEL: ':group_id', | ||
EDIT_LABEL: 'label/:group_id', | ||
EDIT_DESCRIPTION: 'description/:group_id', | ||
DELETE: ':group_id', | ||
GET_ALL: '', | ||
AVAILABLE_LABEL: 'available/:label', | ||
GET: ':group_id', | ||
GET_INLINE_POLICIES: 'inline-policies/:group_id', | ||
}; | ||
|
||
export default Routes; |
10 changes: 10 additions & 0 deletions
10
apps/backend/src/modules/user/modules/groups/interfaces/group-policies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Group, InlinePolicy } from '@prisma/client'; | ||
|
||
export type IGroupInlinePolicy = Pick<InlinePolicy, 'id' | 'label' | 'library'> & { | ||
readonly language: string; | ||
}; | ||
|
||
export interface IGroupInlinePolicies extends Pick<Group, 'description'> { | ||
count: number; | ||
inlinePolicies: IGroupInlinePolicy[]; | ||
} |
2 changes: 1 addition & 1 deletion
2
apps/backend/src/modules/user/modules/groups/queries/contracts/get-group.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export class GetGroupContract { | ||
constructor(public readonly userId: string, public readonly groupId: string) {} | ||
constructor(public readonly groupId: string) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
...backend/src/modules/user/modules/groups/queries/contracts/get-inline-policies.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class GetInlinePoliciesContract { | ||
constructor(public readonly groupId: string, public readonly page?: string) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.