Skip to content

Commit

Permalink
Merge pull request #1120 from gettakaro/main-promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Aug 17, 2024
2 parents 4ca2104 + 8f6eba9 commit 0e88ba3
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 113 deletions.
4 changes: 4 additions & 0 deletions packages/app-api/src/controllers/DomainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class DomainSearchInputAllowedFilters {
@IsOptional()
@IsEnum(Object.values(DOMAIN_STATES), { each: true })
state!: DOMAIN_STATES[];

@IsOptional()
@IsString({ each: true })
externalReference!: string[];
}

export class DomainSearchInputDTO extends ITakaroQuery<DomainOutputDTO> {
Expand Down
10 changes: 1 addition & 9 deletions packages/app-api/src/controllers/PlayerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,7 @@ export class PlayerController {
) {
const service = new PlayerService(req.domainId);

try {
await service.assignRole(params.roleId, params.id, data.gameServerId, data.expiresAt);
} catch (error) {
if (error instanceof Error && error.name === 'UniqueViolationError') {
throw new errors.BadRequestError('Role already assigned');
} else {
throw error;
}
}
await service.assignRole(params.roleId, params.id, data.gameServerId, data.expiresAt);

return apiResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ const tests = [
return this.client.player.playerControllerAssignRole(player.id, role.data.data.id);
},
}),
new IntegrationTest<SetupGameServerPlayers.ISetupData>({
group,
snapshot: true,
name: 'Assigning the same role twice should fail',
setup: SetupGameServerPlayers.setup,
test: async function () {
const permissions = await this.client.permissionCodesToInputs([PERMISSIONS.MANAGE_GAMESERVERS]);
const role = await this.client.role.roleControllerCreate({
name: 'Test role',
permissions,
});
const player = this.setupData.players[0];
await this.client.player.playerControllerAssignRole(player.id, role.data.data.id);
return this.client.player.playerControllerAssignRole(player.id, role.data.data.id);
},
expectedStatus: 400,
}),
new IntegrationTest<SetupGameServerPlayers.ISetupData>({
group,
snapshot: true,
Expand All @@ -58,27 +41,6 @@ const tests = [
});
},
}),
new IntegrationTest<SetupGameServerPlayers.ISetupData>({
group,
snapshot: true,
name: 'Assigning the same role for same gameserver should fail',
setup: SetupGameServerPlayers.setup,
test: async function () {
const permissions = await this.client.permissionCodesToInputs([PERMISSIONS.MANAGE_GAMESERVERS]);
const role = await this.client.role.roleControllerCreate({
name: 'Test role',
permissions,
});
const player = this.setupData.players[0];
await this.client.player.playerControllerAssignRole(player.id, role.data.data.id, {
gameServerId: this.setupData.gameServer1.id,
});
return this.client.player.playerControllerAssignRole(player.id, role.data.data.id, {
gameServerId: this.setupData.gameServer1.id,
});
},
expectedStatus: 400,
}),
new IntegrationTest<SetupGameServerPlayers.ISetupData>({
group,
snapshot: true,
Expand Down Expand Up @@ -202,6 +164,53 @@ const tests = [
},
filteredFields: ['name', 'playerId', 'steamId', 'roleId', 'gameServerId', 'epicOnlineServicesId', 'xboxLiveId'],
}),
new IntegrationTest<SetupGameServerPlayers.ISetupData>({
group,
snapshot: true,
name: 'Can override the expiry of a role assignment',
setup: SetupGameServerPlayers.setup,
test: async function () {
// Assign a role with expiry
// Assign same role with new expiry
// -> Role should have new expiry

const permissions = await this.client.permissionCodesToInputs([PERMISSIONS.MANAGE_GAMESERVERS]);

const role = await this.client.role.roleControllerCreate({
name: 'Test role',
permissions,
});

const player = this.setupData.players[0];
const expiresAt = new Date(Date.now() - 10).toISOString();
const newExpiresAt = new Date(Date.now() + 1000 * 60 * 60).toISOString();

await this.client.player.playerControllerAssignRole(player.id, role.data.data.id, {
expiresAt,
});

await this.client.player.playerControllerAssignRole(player.id, role.data.data.id, {
expiresAt: newExpiresAt,
});

const res = await this.client.player.playerControllerGetOne(player.id);
const roleAssignment = res.data.data.roleAssignments.find((a) => a.role.name === role.data.data.name);
if (!roleAssignment) throw new Error('Role assignment not found');

expect(roleAssignment.expiresAt).to.be.eq(newExpiresAt);
return res;
},
filteredFields: [
'name',
'playerId',
'steamId',
'roleId',
'gameServerId',
'epicOnlineServicesId',
'xboxLiveId',
'expiresAt',
],
}),
];

describe(group, function () {
Expand Down
15 changes: 14 additions & 1 deletion packages/app-api/src/db/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,20 @@ export class PlayerRepo extends ITakaroRepo<PlayerModel, PlayerOutputDTO, Player
gameServerId,
};

await roleOnPlayerModel.query().insert(updateObj);
const whereObj: Record<string, unknown> = {
playerId,
roleId,
};

if (gameServerId) whereObj.gameServerId = gameServerId;

const existing = await roleOnPlayerModel.query().findOne(whereObj);

if (existing) {
await roleOnPlayerModel.query().update(updateObj).where(whereObj);
} else {
await roleOnPlayerModel.query().insert(updateObj);
}
}

async removeRole(playerId: string, roleId: string, gameServerId?: string): Promise<void> {
Expand Down
30 changes: 21 additions & 9 deletions packages/lib-apiclient/src/generated/api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* tslint:disable */
/* eslint-disable */
/**
*
* Takaro API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
* The version of the OpenAPI document: unset-unset-unset
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand Down Expand Up @@ -6148,6 +6148,12 @@ export interface PlayerOutputDTO {
* @memberof PlayerOutputDTO
*/
steamNumberOfVACBans?: number;
/**
*
* @type {number}
* @memberof PlayerOutputDTO
*/
steamLevel?: number;
/**
*
* @type {Array<PlayerOnGameserverOutputDTO>}
Expand Down Expand Up @@ -6294,6 +6300,12 @@ export interface PlayerOutputWithRolesDTO {
* @memberof PlayerOutputWithRolesDTO
*/
steamNumberOfVACBans?: number;
/**
*
* @type {number}
* @memberof PlayerOutputWithRolesDTO
*/
steamLevel?: number;
/**
*
* @type {Array<PlayerOnGameserverOutputDTO>}
Expand Down Expand Up @@ -7891,10 +7903,10 @@ export interface TakaroEventCommandExecuted {
data: any;
/**
*
* @type {Array<TakaroEventFunctionResult>}
* @type {TakaroEventFunctionResult}
* @memberof TakaroEventCommandExecuted
*/
result: Array<TakaroEventFunctionResult>;
result: TakaroEventFunctionResult;
/**
*
* @type {TakaroEventCommandDetails}
Expand Down Expand Up @@ -7941,10 +7953,10 @@ export interface TakaroEventCronjobExecuted {
data: any;
/**
*
* @type {Array<TakaroEventFunctionResult>}
* @type {TakaroEventFunctionResult}
* @memberof TakaroEventCronjobExecuted
*/
result: Array<TakaroEventFunctionResult>;
result: TakaroEventFunctionResult;
/**
*
* @type {TakaroEventCronjobDetails}
Expand Down Expand Up @@ -8079,10 +8091,10 @@ export interface TakaroEventHookExecuted {
data: any;
/**
*
* @type {Array<TakaroEventFunctionResult>}
* @type {TakaroEventFunctionResult}
* @memberof TakaroEventHookExecuted
*/
result: Array<TakaroEventFunctionResult>;
result: TakaroEventFunctionResult;
/**
*
* @type {TakaroEventHookDetails}
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-apiclient/src/generated/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* tslint:disable */
/* eslint-disable */
/**
*
* Takaro API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
* The version of the OpenAPI document: unset-unset-unset
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-apiclient/src/generated/common.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* tslint:disable */
/* eslint-disable */
/**
*
* Takaro API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
* The version of the OpenAPI document: unset-unset-unset
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-apiclient/src/generated/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* tslint:disable */
/* eslint-disable */
/**
*
* Takaro API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
* The version of the OpenAPI document: unset-unset-unset
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-apiclient/src/generated/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* tslint:disable */
/* eslint-disable */
/**
*
* Takaro API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
* The version of the OpenAPI document: unset-unset-unset
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-modules/src/dto/takaroEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TakaroEventCommandExecuted extends BaseEvent<TakaroEventCommandExec
@IsDefined()
data: Record<string, unknown>;

@ValidateNested({ each: true })
@ValidateNested()
@Type(() => TakaroEventFunctionResult)
result: TakaroEventFunctionResult;

Expand All @@ -161,7 +161,7 @@ export class TakaroEventHookExecuted extends BaseEvent<TakaroEventHookExecuted>
@IsDefined()
data: Record<string, unknown>;

@ValidateNested({ each: true })
@ValidateNested()
@Type(() => TakaroEventFunctionResult)
result: TakaroEventFunctionResult;

Expand All @@ -178,7 +178,7 @@ export class TakaroEventCronjobExecuted extends BaseEvent<TakaroEventCronjobExec
@IsDefined()
data: Record<string, unknown>;

@ValidateNested({ each: true })
@ValidateNested()
@Type(() => TakaroEventFunctionResult)
result: TakaroEventFunctionResult;

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0e88ba3

Please sign in to comment.