Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3311166
move swagger folder inside common folder
MikhailDeriabin May 12, 2025
498d6ba
improve naming in swagger folder
MikhailDeriabin May 12, 2025
aee30b0
add 500 error to all swagger definitions
MikhailDeriabin May 13, 2025
3a92dc0
add nest-cli configuration for swagger description auto generation
MikhailDeriabin May 14, 2025
9801a3e
add setup for adding default responses swagger definitions via decora…
MikhailDeriabin May 14, 2025
d71553a
add swagger descriptions for `APIError`
MikhailDeriabin May 14, 2025
ee2cd3c
add swagger descriptions via JSDocs and decorators for /clan starting…
MikhailDeriabin May 14, 2025
bb8dda7
fix failing tests
MikhailDeriabin May 14, 2025
449af3b
add swagger definitions for /auth endpoints
MikhailDeriabin May 16, 2025
57d6276
add swagger definitions for /box endpoints
MikhailDeriabin May 16, 2025
20c7fc2
add swagger definitions for /chat endpoints
MikhailDeriabin May 16, 2025
7958ac3
add swagger definitions for /item endpoints
MikhailDeriabin May 16, 2025
2e998d8
add swagger definitions for /room endpoints
MikhailDeriabin May 16, 2025
f701ba4
add swagger definitions for /soulhome endpoints
MikhailDeriabin May 16, 2025
46efd4b
add swagger definitions for /stock endpoints
MikhailDeriabin May 16, 2025
d5425c5
add swagger definitions for /clan-shop endpoints
MikhailDeriabin May 16, 2025
b2c1a5c
add swagger definitions for /dailyTask endpoints
MikhailDeriabin May 16, 2025
19e926d
add swagger definitions for /fleaMarket endpoints
MikhailDeriabin May 16, 2025
388acc5
add swagger definitions for /gameAnalytics endpoints
MikhailDeriabin May 16, 2025
26ecbb5
add swagger definitions for /gameData endpoints
MikhailDeriabin May 16, 2025
6ded105
add swagger definitions for /leaderboard endpoints
MikhailDeriabin May 16, 2025
1f5973d
add swagger definitions for /online-players endpoints
MikhailDeriabin May 16, 2025
c03469d
add swagger definitions for /player endpoints
MikhailDeriabin May 16, 2025
b2fc5a4
add swagger definitions for /customCharacter endpoints
MikhailDeriabin May 16, 2025
5d043c4
add swagger definitions for /profile endpoints
MikhailDeriabin May 16, 2025
613c50e
add swagger definitions for /voting endpoints
MikhailDeriabin May 16, 2025
75c1ffa
add swagger definitions for /clan/role endpoints
MikhailDeriabin May 16, 2025
de21aea
add swagger definition for _id path parameters
MikhailDeriabin May 16, 2025
82670bc
add swagger definition for rest of the tags
MikhailDeriabin May 16, 2025
7f299e5
add swagger definition for /box/testers endpoint
MikhailDeriabin May 16, 2025
ed9879c
make swagger tag for /box/dailyTask endpoint to be Box
MikhailDeriabin May 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
"include": "src/playerTasks/playerTasks.json",
"outDir": "dist"
}
],
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"dtoFileNameSuffix": [".dto.ts", ".schema.ts", "APIError.ts"],
"controllerFileNameSuffix": ".controller.ts",

"dtoKeyOfComment": "description",
"controllerKeyOfComment": "summary",

"classValidatorShim": true,
"introspectComments": true,
"skipAutoHttpCode": true,
"esmCompatible": false
}
}
]
}
}
1 change: 0 additions & 1 deletion src/__tests__/clanShop/clanShopService/buyItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ describe('ClanShopService.buyItem() test suite', () => {
additional: null,
field: 'gameCoins',
message: 'Clan does not have enough coins to buy the item',
objectType: 'ServiceError',
reason: 'LESS_THAN_MIN',
value: null,
},
Expand Down
18 changes: 18 additions & 0 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ThrowAuthErrorIfFound } from './decorator/ThrowAuthErrorIfFound.decorat
import { NoAuth } from './decorator/NoAuth.decorator';
import { AUTH_SERVICE } from './constant';
import BoxAuthService from './box/BoxAuthService';
import ApiResponseDescription from '../common/swagger/response/ApiResponseDescription';
import { ModelName } from '../common/enum/modelName.enum';
import { ProfileDto } from '../profile/dto/profile.dto';

@NoAuth()
@Controller('auth')
Expand All @@ -14,6 +17,21 @@ export class AuthController {
private readonly authService: AuthService | BoxAuthService,
) {}

/**
* Log in to the system.
*
* @remarks After the profile with player was created, the user can log in to the system and get a JWT token to access resources.
*
* If the user provides the correct credentials, the access token will be returned, which should be used as a Bearer token in the Authorization header.
*/
@ApiResponseDescription({
success: {
status: 201,
modelName: ModelName.CLAN,
type: ProfileDto,
},
errors: [400, 401],
})
@Post('/signIn')
@ThrowAuthErrorIfFound()
public signIn(@Body() body: SignInDto) {
Expand Down
10 changes: 10 additions & 0 deletions src/auth/dto/signIn.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ import AddType from '../../common/base/decorator/AddType.decorator';

@AddType('SignInDto')
export class SignInDto {
/**
* Unique username used by the player to sign in
*
* @example "DragonSlayer42"
*/
@IsString()
username: string;

/**
* Password for player authentication
*
* @example "myStrongP@ssw0rd"
*/
@IsString()
password: string;
}
104 changes: 104 additions & 0 deletions src/box/box.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { BoxUser } from './auth/BoxUser';
import { LoggedUser } from '../common/decorator/param/LoggedUser.decorator';
import { BoxAuthGuard } from './auth/boxAuth.guard';
import SessionStarterService from './sessionStarter/sessionStarter.service';
import ApiResponseDescription from '../common/swagger/response/ApiResponseDescription';
import { BoxDto } from './dto/box.dto';

@Controller('box')
@UseGuards(BoxAuthGuard)
Expand All @@ -42,6 +44,24 @@ export class BoxController {
private readonly sessionStarter: SessionStarterService,
) {}

/**
* Claim tester account.
*
* @remarks Tester can claim his/her account for the testing box.
*
* Notice that the tester should know the shared testers password in order to be able to clain the account.
* This password is available after the group admin has started the session.
*
* Notice that the endpoint should be called only from browser, since a cookie should be added by the API
*/
@ApiResponseDescription({
success: {
status: 200,
type: ClaimAccountResponseDto,
},
errors: [400, 403, 404],
hasAuth: false,
})
@NoAuth()
@Get('claim-account')
@UniformResponse(undefined, ClaimAccountResponseDto)
Expand All @@ -65,6 +85,22 @@ export class BoxController {
return res.send(data);
}

/**
* Create a testing box.
*
* @remarks Create a testing box.
*
* Notice that in order t0 create the testing box a group admin password need to be obtained from backend team
*/
@ApiResponseDescription({
success: {
status: 201,
dto: CreatedBoxDto,
modelName: ModelName.BOX,
},
errors: [400, 404],
hasAuth: false,
})
@NoAuth()
@Post()
@UniformResponse(ModelName.BOX, CreatedBoxDto)
Expand All @@ -81,6 +117,21 @@ export class BoxController {
return [{ ...createdBox, accessToken: groupAdminAccessToken }, null];
}

/**
* Reset testing box.
*
* @remarks Reset testing box data, which means removing all the data created during the testing session and returning the box state to the PREPARING stage.
* For more information refer to the testing box documentation.
*
* Notice that only box admin can do the action.
*/
@ApiResponseDescription({
success: {
dto: CreatedBoxDto,
modelName: ModelName.BOX,
},
errors: [401, 403, 404],
})
@Put('reset')
@UniformResponse(ModelName.BOX)
@IsGroupAdmin()
Expand All @@ -102,13 +153,41 @@ export class BoxController {
return [{ ...createdBox, accessToken: groupAdminAccessToken }, null];
}

/**
* Delete box data.
*
* @remarks Delete box data associated with the logged-in user.
*
* Notice that the box can be removed only by the box admin.
*/
@ApiResponseDescription({
success: {
status: 204,
},
errors: [400, 404],
})
@Delete()
@IsGroupAdmin()
@UniformResponse()
async deleteBoxAndAdmin(@LoggedUser() user: BoxUser) {
return await this.service.deleteBox(user.box_id);
}

/**
* Start testing session
*
* @remarks Endpoint for starting testing session.
*
* Notice that only box admin can start a testing session.
*
* Notice that the minimum box data should be initialized at the moment of starting of testing session. That data is at least 2 tester accounts added.
*/
@ApiResponseDescription({
success: {
status: 204,
},
errors: [401, 403, 404],
})
@Post('/start')
@UniformResponse(ModelName.BOX)
@IsGroupAdmin()
Expand All @@ -117,6 +196,19 @@ export class BoxController {
if (errors) return [null, errors];
}

/**
* Get box by _id, For time of development only
*
* @remarks Endpoint for getting box data by its _id
*/
@ApiResponseDescription({
success: {
dto: BoxDto,
modelName: ModelName.BOX,
},
errors: [404],
hasAuth: false,
})
//For time of development only
@NoAuth()
@Get('/:_id')
Expand All @@ -129,6 +221,18 @@ export class BoxController {
return this.service.readOneById(param._id, { includeRefs });
}

/**
* Delete box by _id
*
* @remarks Endpoint for deleting a box by _id
*/
@ApiResponseDescription({
success: {
status: 204,
},
errors: [404],
hasAuth: false,
})
//For time of development only
@NoAuth()
@Delete('/:_id')
Expand Down
2 changes: 1 addition & 1 deletion src/box/box.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class BoxService {
private getTesterAccount(box: BoxDto): Tester {
const account = box.testers.find((tester) => {
return tester.isClaimed !== true;
});
}) as unknown as Tester;
if (!account) {
throw new ServiceError({
reason: SEReason.NOT_FOUND,
Expand Down
60 changes: 60 additions & 0 deletions src/box/dailyTask/dailyTask.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,32 @@ import { APIError } from '../../common/controller/APIError';
import { APIErrorReason } from '../../common/controller/APIErrorReason';
import BoxAuthHandler from '../auth/BoxAuthHandler';
import { IsGroupAdmin } from '../auth/decorator/IsGroupAdmin';
import ApiResponseDescription from '../../common/swagger/response/ApiResponseDescription';
import SwaggerTags from '../../common/swagger/tags/SwaggerTags.decorator';

@SwaggerTags('Box')
@Controller('/box/dailyTask')
export class DailyTaskController {
constructor(
private readonly taskService: DailyTaskService,
private readonly boxAuthHandler: BoxAuthHandler,
) {}

/**
* Add a daily task to box
*
* @remarks Add a daily task to array of predefined daily tasks.
*
* Notice that the logged-in player has to be a group admin
*/
@ApiResponseDescription({
success: {
status: 201,
dto: PredefinedDailyTaskDto,
modelName: ModelName.DAILY_TASK,
},
errors: [400, 401, 403, 404],
})
@Post()
@IsGroupAdmin()
@UniformResponse(ModelName.DAILY_TASK, PredefinedDailyTaskDto)
Expand All @@ -31,6 +49,22 @@ export class DailyTaskController {
return this.taskService.addOne(user.box_id, body);
}

/**
* Add multiple daily tasks
*
* @remarks Add multiple daily tasks at once to daily tasks array of the box.
*
* Notice that only group admin can add the tasks.
*/
@ApiResponseDescription({
success: {
status: 201,
dto: PredefinedDailyTaskDto,
modelName: ModelName.DAILY_TASK,
returnsArray: true,
},
errors: [400, 401, 403, 404],
})
@Post('/multiple')
@IsGroupAdmin()
@UniformResponse(ModelName.DAILY_TASK, PredefinedDailyTaskDto)
Expand All @@ -55,6 +89,19 @@ export class DailyTaskController {
return this.taskService.addMultiple(user.box_id, body);
}

/**
* Update box daily task
*
* @remarks Update a predefined daily task of a box by its _id.
*
* Notice that only group admin can update the tasks
*/
@ApiResponseDescription({
success: {
status: 204,
},
errors: [400, 401, 403, 404],
})
@Put()
@IsGroupAdmin()
@UniformResponse(ModelName.DAILY_TASK)
Expand All @@ -69,6 +116,19 @@ export class DailyTaskController {
if (errors) return [null, errors];
}

/**
* Delete box daily task by _id
*
* @remarks Delete daily task from predefined daily tasks array of the box.
*
* Notice that only group admin can delete the tasks
*/
@ApiResponseDescription({
success: {
status: 204,
},
errors: [400, 401, 403, 404],
})
@Delete('/:_id')
@IsGroupAdmin()
@UniformResponse(ModelName.DAILY_TASK)
Expand Down
Loading