Skip to content

Commit

Permalink
fix: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
takaro-ci-bot[bot] committed Dec 14, 2024
1 parent 61a4a0d commit dc702e8
Show file tree
Hide file tree
Showing 32 changed files with 22,922 additions and 19,850 deletions.
20 changes: 9 additions & 11 deletions packages/app-api/src/controllers/Module/installations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Response } from 'express';
import { AllowedFilters } from '../shared.js';
import { InstallModuleDTO, ModuleInstallationOutputDTO } from '../../service/Module/dto.js';


class ModuleInstallationOutputDTOAPI extends APIOutput<ModuleInstallationOutputDTO> {
@Type(() => ModuleInstallationOutputDTO)
@ValidateNested()
Expand All @@ -25,7 +24,6 @@ class ModuleInstallationOutputArrayDTOAPI extends APIOutput<ModuleInstallationOu
declare data: ModuleInstallationOutputDTO[];
}


class ModuleInstallationSearchInputAllowedFilters extends AllowedFilters {
@IsOptional()
@IsUUID('4', { each: true })
Expand All @@ -48,7 +46,6 @@ class ModuleInstallationSearchInputDTO extends ITakaroQuery<ModuleInstallationSe
declare search: ModuleInstallationSearchInputAllowedFilters;
}


@OpenAPI({
security: [{ domainAuth: [] }],
tags: ['Module'],
Expand All @@ -61,7 +58,11 @@ export class ModuleInstallationsController {
summary: 'Search module installations',
})
@Post('/search')
async getInstalledModules(@Req() req: AuthenticatedRequest, @Res() res: Response, @Body() query: ModuleInstallationSearchInputDTO) {
async getInstalledModules(
@Req() req: AuthenticatedRequest,
@Res() res: Response,
@Body() query: ModuleInstallationSearchInputDTO,
) {
const service = new ModuleService(req.domainId);
const result = await service.findInstallations({
...query,
Expand All @@ -87,17 +88,14 @@ export class ModuleInstallationsController {
return apiResponse(res);
}


@UseBefore(AuthService.getAuthMiddleware([PERMISSIONS.MANAGE_GAMESERVERS]))
@ResponseSchema(ModuleInstallationOutputDTOAPI)
@OpenAPI({
description: 'Install a module on a gameserver. You can have multiple installations of the same module on the same gameserver.',
description:
'Install a module on a gameserver. You can have multiple installations of the same module on the same gameserver.',
})
@Post('/')
async installModule(
@Req() req: AuthenticatedRequest,
@Body() data: InstallModuleDTO,
) {
async installModule(@Req() req: AuthenticatedRequest, @Body() data: InstallModuleDTO) {
const service = new ModuleService(req.domainId);
return apiResponse(await service.installModule(data));
}
Expand All @@ -112,4 +110,4 @@ export class ModuleInstallationsController {
const service = new ModuleService(req.domainId);
return apiResponse(await service.uninstallModule(params.id));
}
}
}
3 changes: 0 additions & 3 deletions packages/app-api/src/controllers/Module/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ModuleSearchInputAllowedFilters extends AllowedFilters {
builtin: string[];
}


class ModuleSearchInputDTO extends ITakaroQuery<ModuleSearchInputAllowedFilters> {
@ValidateNested()
@Type(() => ModuleSearchInputAllowedFilters)
Expand All @@ -51,8 +50,6 @@ class ModuleSearchInputDTO extends ITakaroQuery<ModuleSearchInputAllowedFilters>
declare lessThan: RangeFilterCreatedAndUpdatedAt;
}



@OpenAPI({
security: [{ domainAuth: [] }],
tags: ['Module'],
Expand Down
46 changes: 33 additions & 13 deletions packages/app-api/src/controllers/Module/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import { errors } from '@takaro/util';
import { builtinModuleModificationMiddleware } from '../../middlewares/builtinModuleModification.js';
import { BuiltinModule, ICommand, ICommandArgument, ICronJob, IFunction, IHook } from '@takaro/modules';
import { AllowedFilters, RangeFilterCreatedAndUpdatedAt } from '../shared.js';
import { ModuleExportInputDTO, ModuleVersionCreateAPIDTO, ModuleVersionOutputDTO, ModuleVersionUpdateDTO } from '../../service/Module/dto.js';
import {
ModuleExportInputDTO,
ModuleVersionCreateAPIDTO,
ModuleVersionOutputDTO,
ModuleVersionUpdateDTO,
} from '../../service/Module/dto.js';
import { PermissionCreateDTO } from '../../service/RoleService.js';


export class ModuleVersionOutputDTOAPI extends APIOutput<ModuleVersionOutputDTO> {
@Type(() => ModuleVersionOutputDTO)
@ValidateNested()
Expand All @@ -38,7 +42,6 @@ class ModuleVersionSearchInputAllowedFilters extends AllowedFilters {
moduleId: string[];
}


class ModuleVersionSearchInputDTO extends ITakaroQuery<ModuleVersionSearchInputAllowedFilters> {
@ValidateNested()
@Type(() => ModuleVersionSearchInputAllowedFilters)
Expand All @@ -54,7 +57,6 @@ class ModuleVersionSearchInputDTO extends ITakaroQuery<ModuleVersionSearchInputA
declare lessThan: RangeFilterCreatedAndUpdatedAt;
}


class ModuleExportDTOAPI extends APIOutput<BuiltinModule<unknown>> {
@Type(() => BuiltinModule)
@ValidateNested()
Expand All @@ -73,7 +75,11 @@ export class ModuleVersionController {
summary: 'Search module versions',
})
@Post('/search')
async searchVersions(@Req() req: AuthenticatedRequest, @Res() res: Response, @Body() query: ModuleVersionSearchInputDTO) {
async searchVersions(
@Req() req: AuthenticatedRequest,
@Res() res: Response,
@Body() query: ModuleVersionSearchInputDTO,
) {
const service = new ModuleService(req.domainId);
const result = await service.findVersions({
...query,
Expand Down Expand Up @@ -103,10 +109,15 @@ export class ModuleVersionController {
@ResponseSchema(ModuleVersionOutputDTOAPI)
@OpenAPI({
summary: 'Update a version',
description: 'Update a version of a module, note that you can only update the "latest" version. Tagged versions are immutable',
description:
'Update a version of a module, note that you can only update the "latest" version. Tagged versions are immutable',
})
@Put('/:id')
async updateVersion(@Req() req: AuthenticatedRequest, @Params() params: ParamId, @Body() data: ModuleVersionUpdateDTO) {
async updateVersion(
@Req() req: AuthenticatedRequest,
@Params() params: ParamId,
@Body() data: ModuleVersionUpdateDTO,
) {
const service = new ModuleService(req.domainId);
const result = await service.updateVersion(params.id, data);
return apiResponse(result);
Expand All @@ -125,15 +136,19 @@ export class ModuleVersionController {
return apiResponse();
}


@UseBefore(AuthService.getAuthMiddleware([PERMISSIONS.MANAGE_MODULES]))
@ResponseSchema(ModuleVersionOutputDTOAPI)
@OpenAPI({
summary: 'Tag a new version',
description: 'Creates a new version of a module, copying all config (commands,hooks,cronjobs,...) from the "latest" version into a new, immutable version',
description:
'Creates a new version of a module, copying all config (commands,hooks,cronjobs,...) from the "latest" version into a new, immutable version',
})
@Post('/')
async tagVersion(@Req() req: AuthenticatedRequest, @Params() params: ParamId, @Body() data: ModuleVersionCreateAPIDTO) {
async tagVersion(
@Req() req: AuthenticatedRequest,
@Params() params: ParamId,
@Body() data: ModuleVersionCreateAPIDTO,
) {
const service = new ModuleService(req.domainId);
const result = await service.tagVersion(params.id, data.tag);
return apiResponse(result);
Expand All @@ -154,7 +169,13 @@ export class ModuleVersionController {
if (!mod) throw new errors.NotFoundError('Module not found');
if (!version) throw new errors.NotFoundError('Version not found');

const output = new BuiltinModule(mod.name, version.description, version.tag, version.configSchema, version.uiSchema);
const output = new BuiltinModule(
mod.name,
version.description,
version.tag,
version.configSchema,
version.uiSchema,
);
output.commands = await Promise.all(
version.commands.map(
(_) =>
Expand Down Expand Up @@ -234,5 +255,4 @@ export class ModuleVersionController {
const service = new ModuleService(req.domainId);
return apiResponse(await service.import(data));
}

}
}
6 changes: 1 addition & 5 deletions packages/app-api/src/db/gameserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { errors, traceableClass } from '@takaro/util';
import { GAME_SERVER_TYPE } from '@takaro/gameserver';
import { ITakaroRepo } from './base.js';
import { PLAYER_ON_GAMESERVER_TABLE_NAME, PlayerOnGameServerModel } from './playerOnGameserver.js';
import {
GameServerOutputDTO,
GameServerCreateDTO,
GameServerUpdateDTO,
} from '../service/GameServerService.js';
import { GameServerOutputDTO, GameServerCreateDTO, GameServerUpdateDTO } from '../service/GameServerService.js';
import { ITEMS_TABLE_NAME, ItemsModel } from './items.js';

export const GAMESERVER_TABLE_NAME = 'gameservers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ export async function builtinModuleModificationMiddleware(
log.error('Unexpected error in builtinModuleModificationMiddleware', error);
next(new errors.InternalServerError());
}

}
7 changes: 4 additions & 3 deletions packages/app-api/src/service/CommandService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ export class CommandService extends TakaroService<CommandModel, CommandOutputDTO
timestamp: chatMessage.timestamp,
...parsedCommand,
player: pog,
modules: await this.moduleService.getInstalledModules({ gameserverId: gameServerId, versionId: c.versionId }),
modules: await this.moduleService.getInstalledModules({
gameserverId: gameServerId,
versionId: c.versionId,
}),
},
};
}),
Expand Down Expand Up @@ -353,8 +356,6 @@ export class CommandService extends TakaroService<CommandModel, CommandOutputDTO
await redisClient.incr(commandsRunningKey(jobData));
await queueService.queues.commands.queue.add(jobData, { delay });
}


});

await Promise.all(promises);
Expand Down
2 changes: 1 addition & 1 deletion packages/app-api/src/service/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class EventCreateDTO extends TakaroDTO<EventCreateDTO> {
meta: BaseEvent<any>;
}

export class EventUpdateDTO extends TakaroDTO<EventUpdateDTO> { }
export class EventUpdateDTO extends TakaroDTO<EventUpdateDTO> {}

@traceableClass('service:event')
export class EventService extends TakaroService<EventModel, EventOutputDTO, EventCreateDTO, EventUpdateDTO> {
Expand Down
16 changes: 5 additions & 11 deletions packages/app-api/src/service/GameServerService.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { TakaroService } from './Base.js';
import { GameServerModel, GameServerRepo } from '../db/gameserver.js';
import {
IsBoolean,
IsEnum,
IsJSON,
IsObject,
IsOptional,
IsString,
Length,
} from 'class-validator';
import { IsBoolean, IsEnum, IsJSON, IsObject, IsOptional, IsString, Length } from 'class-validator';
import {
IMessageOptsDTO,
IGameServer,
Expand Down Expand Up @@ -154,9 +146,11 @@ export class GameServerService extends TakaroService<

async delete(id: string) {
const installedModules = await this.moduleService.findInstallations({
filters: { gameserverId: [id], }
filters: { gameserverId: [id] },
});
await Promise.all(installedModules.results.map((installation) => this.moduleService.uninstallModule(installation.id)));
await Promise.all(
installedModules.results.map((installation) => this.moduleService.uninstallModule(installation.id)),
);

gameClassCache.delete(id);

Expand Down
2 changes: 1 addition & 1 deletion packages/app-api/src/service/Module/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ export class InstallModuleDTO extends TakaroDTO<InstallModuleDTO> {
@IsJSON()
@IsOptional()
systemConfig?: string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ async function setup(this: IntegrationTest<IStandardSetupData>): Promise<IStanda

await connectedEvents;

const installation = (await this.client.module.moduleInstallationsControllerInstallModule({
gameServerId: gameserver.id,
versionId: mod.latestVersion.id,
})).data.data;
const installation = (
await this.client.module.moduleInstallationsControllerInstallModule({
gameServerId: gameserver.id,
versionId: mod.latestVersion.id,
})
).data.data;

if (!this.standardDomainId) throw new Error('No standard domain id set!');

Expand Down Expand Up @@ -178,9 +180,7 @@ const tests = [
z: 0,
});

await this.client.module.moduleInstallationsControllerUninstallModule(
this.setupData.installation.id
);
await this.client.module.moduleInstallationsControllerUninstallModule(this.setupData.installation.id);

await this.setupData.service.handleChatMessage(
new EventChatMessage({
Expand Down Expand Up @@ -217,19 +217,17 @@ const tests = [
name: 'Adds a delayed job when delay is configured',
setup,
test: async function () {
await this.client.module.moduleInstallationsControllerInstallModule(
{
gameServerId: this.setupData.gameserver.id,
versionId: this.setupData.mod.latestVersion.id,
systemConfig: JSON.stringify({
commands: {
[this.setupData.normalCommand.name]: {
delay: 5,
},
await this.client.module.moduleInstallationsControllerInstallModule({
gameServerId: this.setupData.gameserver.id,
versionId: this.setupData.mod.latestVersion.id,
systemConfig: JSON.stringify({
commands: {
[this.setupData.normalCommand.name]: {
delay: 5,
},
}),
},
);
},
}),
});

const addStub = sandbox.stub(queueService.queues.commands.queue, 'add');
sandbox.stub(EventService.prototype, 'create').resolves();
Expand Down Expand Up @@ -303,20 +301,18 @@ const tests = [
z: 0,
});

await this.client.module.moduleInstallationsControllerInstallModule(
{
gameServerId: this.setupData.gameserver.id,
versionId: this.setupData.mod.latestVersion.id,
await this.client.module.moduleInstallationsControllerInstallModule({
gameServerId: this.setupData.gameserver.id,
versionId: this.setupData.mod.latestVersion.id,

systemConfig: JSON.stringify({
commands: {
[this.setupData.normalCommand.name]: {
enabled: false,
},
systemConfig: JSON.stringify({
commands: {
[this.setupData.normalCommand.name]: {
enabled: false,
},
}),
},
);
},
}),
});

await this.setupData.service.handleChatMessage(
new EventChatMessage({
Expand All @@ -330,12 +326,10 @@ const tests = [

expect(addStub).to.not.have.been.calledOnce;

await this.client.module.moduleInstallationsControllerInstallModule(
{
gameServerId: this.setupData.gameserver.id,
versionId: this.setupData.mod.latestVersion.id,
}
);
await this.client.module.moduleInstallationsControllerInstallModule({
gameServerId: this.setupData.gameserver.id,
versionId: this.setupData.mod.latestVersion.id,
});

await this.setupData.service.handleChatMessage(
new EventChatMessage({
Expand Down
Loading

0 comments on commit dc702e8

Please sign in to comment.