@@ -37,12 +37,17 @@ import { publicReferences } from './clan.schema';
3737import { RoomService } from '../clanInventory/room/room.service' ;
3838import { ItemService } from '../clanInventory/item/item.service' ;
3939import { PlayerService } from '../player/player.service' ;
40- import { ClanItemsResponseDto } from './join/dto/clanItemsResponse.dto' ;
4140import HasClanRights from './role/decorator/guard/HasClanRights' ;
4241import { ClanBasicRight } from './role/enum/clanBasicRight.enum' ;
4342import DetermineClanId from '../common/guard/clanId.guard' ;
4443import { APIError } from '../common/controller/APIError' ;
4544import { APIErrorReason } from '../common/controller/APIErrorReason' ;
45+ import { ApiStandardErrors } from '../common/swagger/response/errors/ApiStandardErrors.decorator' ;
46+ import { ApiSuccessResponse } from '../common/swagger/response/success/ApiSuccessResponse.decorator' ;
47+ import ApiResponseDescription from '../common/swagger/response/ApiResponseDescription' ;
48+ import ClanItemsDto from './dto/clanItems.dto' ;
49+ import { ApiExtraModels } from '@nestjs/swagger' ;
50+ import { ItemDto } from '../clanInventory/item/dto/item.dto' ;
4651
4752@Controller ( 'clan' )
4853export class ClanController {
@@ -54,15 +59,49 @@ export class ClanController {
5459 private readonly playerService : PlayerService ,
5560 ) { }
5661
62+ /**
63+ * Create a new Clan.
64+ *
65+ * @remarks The creator of the Clan becomes its admin.
66+ * Notice that if Player is creating a new Clan, he/she becomes a member of it,
67+ * that means that if Player is member of some Clan it can not create a new one, before leaving the old one.
68+ *
69+ * Also, endpoint creates Clan's Stock, as well as Clan's SoulHome and Rooms.
70+ *
71+ * For the created Clan a set of default Items will be added to Stock and to one of the SoulHome Rooms.
72+ */
73+ @ApiResponseDescription ( {
74+ success : {
75+ dto : ClanDto ,
76+ status : 201 ,
77+ modelName : ModelName . CLAN ,
78+ } ,
79+ errors : [ 400 , 401 , 403 , 409 ] ,
80+ } )
5781 @Post ( )
5882 @Authorize ( { action : Action . create , subject : ClanDto } )
5983 @UniformResponse ( ModelName . CLAN )
6084 public async create ( @Body ( ) body : CreateClanDto , @LoggedUser ( ) user : User ) {
6185 return this . service . createOne ( body , user . player_id ) ;
6286 }
6387
88+ /**
89+ * Get items of the logged-in user clan.
90+ *
91+ * @remarks Get items of the logged-in user clan.
92+ *
93+ * Notice that it will return 403 if the logged-in player is not in any clan.
94+ */
95+ @ApiResponseDescription ( {
96+ success : {
97+ dto : ClanItemsDto ,
98+ modelName : ModelName . ITEM ,
99+ } ,
100+ errors : [ 401 , 403 ] ,
101+ } )
102+ @ApiExtraModels ( ItemDto )
64103 @Get ( 'items' )
65- @UniformResponse ( ModelName . ITEM , ClanItemsResponseDto )
104+ @UniformResponse ( ModelName . ITEM , ClanItemsDto )
66105 async getClanItems ( @LoggedUser ( ) user : User ) {
67106 const clanId = await this . playerService . getPlayerClanId ( user . player_id ) ;
68107 const [ clan , clanErrors ] = await this . service . readOneById ( clanId , {
@@ -84,6 +123,19 @@ export class ClanController {
84123 return { stockItems, soulHomeItems } ;
85124 }
86125
126+ /**
127+ * Get Clan by _id.
128+ *
129+ * @remarks Read Clan data by its _id field
130+ */
131+ @ApiResponseDescription ( {
132+ success : {
133+ dto : ClanDto ,
134+ modelName : ModelName . CLAN ,
135+ } ,
136+ errors : [ 400 , 404 ] ,
137+ hasAuth : false ,
138+ } )
87139 @Get ( '/:_id' )
88140 @NoAuth ( )
89141 @UniformResponse ( ModelName . CLAN )
@@ -94,7 +146,26 @@ export class ClanController {
94146 return this . service . readOneById ( param . _id , { includeRefs } ) ;
95147 }
96148
149+ /**
150+ * Read all clans.
151+ *
152+ * @remarks Read all created Clans
153+ */
154+ @ApiResponseDescription ( {
155+ success : {
156+ dto : ClanDto ,
157+ modelName : ModelName . CLAN ,
158+ returnsArray : true ,
159+ } ,
160+ errors : [ 404 ] ,
161+ hasAuth : false ,
162+ } )
97163 @Get ( )
164+ @ApiSuccessResponse ( ClanDto , {
165+ modelName : ModelName . CLAN ,
166+ returnsArray : true ,
167+ } )
168+ @ApiStandardErrors ( 404 )
98169 @NoAuth ( )
99170 @UniformResponse ( ModelName . CLAN , ClanDto )
100171 @OffsetPaginate ( ModelName . CLAN )
@@ -104,6 +175,19 @@ export class ClanController {
104175 return this . service . readAll ( query ) ;
105176 }
106177
178+ /**
179+ * Update a clan
180+ *
181+ * @remarks Update the Clan, which _id is specified in the body.
182+ *
183+ * Notice that the player must be in the same clan and it must have a basic right "Edit clan data"
184+ */
185+ @ApiResponseDescription ( {
186+ success : {
187+ status : 204 ,
188+ } ,
189+ errors : [ 400 , 401 , 403 , 404 , 409 ] ,
190+ } )
107191 @Put ( )
108192 @DetermineClanId ( )
109193 @HasClanRights ( [ ClanBasicRight . EDIT_CLAN_DATA ] )
@@ -121,11 +205,25 @@ export class ClanController {
121205 } ) ,
122206 ] ,
123207 ] ;
124-
125208 const [ , errors ] = await this . service . updateOneById ( body ) ;
126209 if ( errors ) return [ null , errors ] ;
127210 }
128211
212+ /**
213+ * Delete a clan
214+ *
215+ * @remarks Delete Clan its _id field.
216+ *
217+ * Notice that only Clan admins can delete the Clan.
218+ *
219+ * Notice that the player must be in the same clan and it must have a basic right "Edit clan data"
220+ */
221+ @ApiResponseDescription ( {
222+ success : {
223+ status : 204 ,
224+ } ,
225+ errors : [ 400 , 401 , 403 , 404 ] ,
226+ } )
129227 @Delete ( '/:_id' )
130228 @Authorize ( { action : Action . delete , subject : UpdateClanDto } )
131229 @UniformResponse ( )
@@ -134,20 +232,63 @@ export class ClanController {
134232 if ( errors ) return [ null , errors ] ;
135233 }
136234
235+ /**
236+ * Player requests join to clan
237+ *
238+ * @remarks Request to join a Clan.
239+ *
240+ * Notice that if the Clan is open the Player will be joined automatically without admin approval.
241+ *
242+ * Notice that if the Player was in another Clan then he/she will be removed from the old one and if in this Clan was no other Players, it will be removed.
243+ */
244+ @ApiResponseDescription ( {
245+ success : {
246+ dto : JoinDto ,
247+ modelName : ModelName . JOIN ,
248+ status : 201 ,
249+ } ,
250+ errors : [ 400 , 401 , 403 , 404 ] ,
251+ } )
137252 @Post ( 'join' )
138253 @Authorize ( { action : Action . create , subject : JoinDto } )
139254 @BasicPOST ( JoinDto )
140255 public async createJoin ( @Body ( ) body : JoinRequestDto ) {
141256 return this . joinService . handleJoinRequest ( body ) ;
142257 }
143258
259+ /**
260+ * Player requests leave a clan
261+ *
262+ * @remarks Request to leave a Clan.
263+ *
264+ * Notice that Player can leave any Clan without admin approval.
265+ */
266+ @ApiResponseDescription ( {
267+ success : {
268+ status : 204 ,
269+ } ,
270+ errors : [ 401 , 404 ] ,
271+ } )
144272 @Post ( 'leave' )
145273 @HttpCode ( 204 )
146274 @Authorize ( { action : Action . create , subject : PlayerLeaveClanDto } )
147275 public leaveClan ( @Req ( ) request : Request , @LoggedUser ( ) user : User ) {
148276 return this . joinService . leaveClan ( user . player_id ) ;
149277 }
150278
279+ /**
280+ * Exclude the player from clan.
281+ *
282+ * @remarks Request exclude the player from clan.
283+ *
284+ * Notice that only Clan admin can remove the Player
285+ */
286+ @ApiResponseDescription ( {
287+ success : {
288+ status : 204 ,
289+ } ,
290+ errors : [ 400 , 401 , 404 ] ,
291+ } )
151292 @Post ( 'exclude' )
152293 @HttpCode ( 204 )
153294 @DetermineClanId ( )
0 commit comments