-
Notifications
You must be signed in to change notification settings - Fork 2
637 Feature: Daily Player Emotions #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CapoMK25
wants to merge
6
commits into
dev
Choose a base branch
from
637-feature-request-player-data-should-contain-information-about-the-daily-emotions-for-the-past-week
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b21e0fe
Implemented daily emotions
CapoMK25 a489f40
linter changes
CapoMK25 033134d
Re-added JSDocs that disappeared on the initial commit
CapoMK25 ee87674
revamped the emotions according to requirements
CapoMK25 7693288
Merge branch 'dev' into 637-feature-request-player-data-should-contai…
CapoMK25 02e48cc
addressed good suggetions
CapoMK25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 { Expose } from 'class-transformer'; | ||
|
|
||
| export class EmotionDto { | ||
| @Expose() | ||
| emotion: string; | ||
|
|
||
| @Expose() | ||
| date: Date; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| import { PlayerEmotion } from '../enum/playerEmotion.enum'; | ||
|
|
||
| export class EmotionCheckDto { | ||
| constructor(isSent: boolean, currentEmotion: PlayerEmotion) { | ||
| this.isSent = isSent; | ||
| this.currentEmotion = currentEmotion; | ||
| } | ||
|
|
||
| isSent: boolean; | ||
| currentEmotion: PlayerEmotion; | ||
| } |
This file contains hidden or 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 hidden or 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,11 @@ | ||
| import { IsEnum, IsNotEmpty } from 'class-validator'; | ||
| import { PlayerEmotion } from '../enum/playerEmotion.enum'; | ||
|
|
||
| export class UpdateEmotionDto { | ||
| @IsEnum(PlayerEmotion, { | ||
| message: | ||
| 'Emotion must be one of these: Sorrow, Anger, Joy, Playful, Love, Blank', | ||
| }) | ||
| @IsNotEmpty() | ||
| emotion: PlayerEmotion; | ||
| } |
This file contains hidden or 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,8 @@ | ||
| export enum PlayerEmotion { | ||
| SORROW = 'Sorrow', | ||
| ANGER = 'Anger', | ||
| JOY = 'Joy', | ||
| PLAYFUL = 'Playful', | ||
| LOVE = 'Love', | ||
| BLANK = 'Blank', | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,17 +7,21 @@ import { | |
| Param, | ||
| Post, | ||
| Put, | ||
| BadRequestException | ||
| } from '@nestjs/common'; | ||
| import { PlayerService } from './player.service'; | ||
| import { CreatePlayerDto } from './dto/createPlayer.dto'; | ||
| import { UpdatePlayerDto } from './dto/updatePlayer.dto'; | ||
| import { UpdateEmotionDto } from './dto/updateEmotion.dto'; | ||
| import { PlayerDto } from './dto/player.dto'; | ||
| import { _idDto } from '../common/dto/_id.dto'; | ||
| import { BasicDELETE } from '../common/base/decorator/BasicDELETE.decorator'; | ||
| import { ModelName } from '../common/enum/modelName.enum'; | ||
| import { NoAuth } from '../auth/decorator/NoAuth.decorator'; | ||
| import { Authorize } from '../authorization/decorator/Authorize'; | ||
| import { Action } from '../authorization/enum/action.enum'; | ||
| import { LoggedUser } from '../common/decorator/param/LoggedUser.decorator'; | ||
| import { User } from '../auth/user'; | ||
| import { OffsetPaginate } from '../common/interceptor/request/offsetPagination.interceptor'; | ||
| import { AddSearchQuery } from '../common/interceptor/request/addSearchQuery.interceptor'; | ||
| import { GetAllQuery } from '../common/decorator/param/GetAllQuery'; | ||
|
|
@@ -30,6 +34,8 @@ import ApiResponseDescription from '../common/swagger/response/ApiResponseDescri | |
| import EventEmitterService from '../common/service/EventEmitterService/EventEmitter.service'; | ||
| import { ServerTaskName } from '../dailyTasks/enum/serverTaskName.enum'; | ||
| import { isEqual } from 'lodash'; | ||
| import { IServiceReturn } from '../common/service/basicService/IService'; | ||
| import { EmotionCheckDto } from './dto/emotionCheck.dto'; | ||
| import { MongooseError } from 'mongoose'; | ||
|
|
||
| @Controller('player') | ||
|
|
@@ -41,19 +47,15 @@ export default class PlayerController { | |
|
|
||
| /** | ||
| * Create a player | ||
| * | ||
| * | ||
| * @remarks Create a new Player. This is not recommended way of creating a new Player and it should be used only in edge cases. | ||
| * The recommended way is to create it via /profile POST endpoint. | ||
| * | ||
| * Player is representing an object, which holds data related to game player. This object can be used inside the game for example while joining a Clan. | ||
| * Notice, that the Profile object should not be used inside the game (except for logging-in). | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { | ||
| dto: PlayerDto, | ||
| modelName: ModelName.PLAYER, | ||
| status: 201, | ||
| }, | ||
| success: { dto: PlayerDto, modelName: ModelName.PLAYER, status: 201 }, | ||
| errors: [400, 401, 403, 409], | ||
| hasAuth: false, | ||
| }) | ||
|
|
@@ -64,16 +66,52 @@ export default class PlayerController { | |
| return this.service.createOne(body); | ||
| } | ||
|
|
||
| /** | ||
| * Player emotion check | ||
| * Checks if the authenticated player has already submitted an emotion for the current day. | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { status: 200 }, | ||
| errors: [401, 403, 404], | ||
| }) | ||
| @Get('/emotioncheck') | ||
| @Authorize({ action: Action.read, subject: PlayerDto }) | ||
| public async checkDailyEmotion( | ||
| @LoggedUser() user: User, | ||
| ): Promise<IServiceReturn<boolean>> { | ||
|
|
||
| return await this.service.checkIfEmotionSentToday(user.player_id); | ||
| } | ||
|
|
||
| /** | ||
| * Registers the player's selected emotion for the current day. | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { dto: null, modelName: ModelName.PLAYER, status: 204 }, | ||
| errors: [400, 401, 403, 409], | ||
| }) | ||
| @Post('/emotion') | ||
| @UniformResponse(ModelName.PLAYER, PlayerDto) | ||
| @Authorize({ action: Action.create, subject: PlayerDto }) | ||
| public async setDailyEmotion( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This controller function should return nothing, since you return 201 status_code (means
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in my latest commit. |
||
| @LoggedUser() user: User, | ||
| @Body() body: UpdateEmotionDto, | ||
| ): Promise<void> { | ||
| const [error] = await this.service.addEmotion(user.player_id, body.emotion); | ||
|
|
||
| if (error) { | ||
| throw new BadRequestException(error[0].message); | ||
| } | ||
|
|
||
| } | ||
|
|
||
CapoMK25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Get player by _id | ||
| * | ||
| * @remarks Read Player data by its _id field | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { | ||
| dto: PlayerDto, | ||
| modelName: ModelName.PLAYER, | ||
| }, | ||
| success: { dto: PlayerDto, modelName: ModelName.PLAYER }, | ||
| errors: [400, 401, 404], | ||
| }) | ||
| @Get('/:_id') | ||
|
|
@@ -88,14 +126,11 @@ export default class PlayerController { | |
|
|
||
| /** | ||
| * Get all players | ||
| * | ||
| * @remarks Read all created Players. Remember about the pagination | ||
| * | ||
| * @remarks Read all created Players. Remember about the pagination. | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { | ||
| dto: PlayerDto, | ||
| modelName: ModelName.PLAYER, | ||
| }, | ||
| success: { dto: PlayerDto, modelName: ModelName.PLAYER }, | ||
| errors: [401, 404], | ||
| }) | ||
| @Get() | ||
|
|
@@ -109,14 +144,12 @@ export default class PlayerController { | |
|
|
||
| /** | ||
| * Update player | ||
| * Emit a server event if avatar clothes changed | ||
| * | ||
| * @remarks Update the Player, which _id is specified in the body. Only Player, which belong to the logged-in Profile can be changed. | ||
| * * Emit a server event if avatar clothes changed | ||
| * @remarks Update the Player, which _id is specified in the body. | ||
| * Only Player, which belong to the logged-in Profile can be changed. | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { | ||
| status: 204, | ||
| }, | ||
| success: { status: 204 }, | ||
| errors: [401, 403, 404, 409], | ||
| }) | ||
| @Put() | ||
|
|
@@ -125,33 +158,29 @@ export default class PlayerController { | |
| @UniformResponse() | ||
| public async update(@Body() body: UpdatePlayerDto) { | ||
| const [player, _] = await this.service.getPlayerById(body._id); | ||
|
|
||
| const playerUpdateResults = await this.service.updateOneById(body); | ||
|
|
||
| await this.emitEventIfAvatarChange(player, body); | ||
| return playerUpdateResults; | ||
|
|
||
| if (playerUpdateResults instanceof MongooseError) | ||
| return playerUpdateResults; | ||
| } | ||
|
|
||
| /** | ||
| * Delete player by _id | ||
| * | ||
| * @remarks Delete Player by its _id field. Notice that only Player, which belongs to loggen-in user Profile can be deleted. | ||
| * @remarks Delete Player by its _id field. Notice that only Player, which belongs to a logged-in user Profile can be deleted. | ||
| * In case when the Player is the only admin in some Clan and the Clan has some other Players, the Player can not be removed. | ||
| * User should be asked to first determine at least one admin for the Clan. | ||
| * | ||
| * Also, it is not recommended to delete the Player since it can itroduce unexpected behaviour for the user with Profile, | ||
| * Also, it is not recommended to delete the Player since it can introduce unexpected behaviour for the user with Profile, | ||
| * but without Player. The better way to remove the Player is do it via /profile DELETE. | ||
| * | ||
| * Player removal basically means removing all data, which is related to the Player: | ||
| * CustomCharacters, Clan, except for the Profile data. | ||
| * In the case when the Profile does not have a Player, user can only login to the system, but can not play the game. | ||
| */ | ||
| @ApiResponseDescription({ | ||
| success: { | ||
| status: 204, | ||
| }, | ||
| success: { status: 204 }, | ||
| errors: [400, 401, 403, 404], | ||
| }) | ||
| @Delete('/:_id') | ||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.