Skip to content

Commit

Permalink
Merge pull request #1822 from gettakaro/main-promotion
Browse files Browse the repository at this point in the history
🤖 Merge development into main
  • Loading branch information
niekcandaele authored Dec 17, 2024
2 parents 43371ac + af69fee commit 012b05e
Show file tree
Hide file tree
Showing 38 changed files with 686 additions and 97 deletions.
59 changes: 32 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion packages/app-api/src/controllers/GameServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ import {
ModuleInstallDTO,
} from '../service/GameServerService.js';
import { AuthenticatedRequest, AuthService, checkPermissions } from '../service/AuthService.js';
import { Body, Get, Post, Delete, JsonController, UseBefore, Req, Put, Params, Res } from 'routing-controllers';
import {
Body,
Get,
Post,
Delete,
JsonController,
UseBefore,
Req,
Put,
Params,
Res,
ContentType,
} from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { Type } from 'class-transformer';
import { ParamId, PogParam } from '../lib/validators.js';
Expand Down Expand Up @@ -233,6 +245,17 @@ class ImportOutputDTO extends TakaroDTO<ImportOutputDTO> {
id!: string;
}

class MapTileInputDTO extends TakaroDTO<MapTileInputDTO> {
@IsUUID('4')
id: string;
@IsNumber()
z: number;
@IsNumber()
x: number;
@IsNumber()
y: number;
}

class ImportOutputDTOAPI extends APIOutput<ImportOutputDTO> {
@Type(() => ImportOutputDTO)
@ValidateNested()
Expand Down Expand Up @@ -588,4 +611,26 @@ export class GameServerController {
const result = await service.import(parsedImportData, validatedOptions);
return apiResponse(result);
}

@Get('/gameserver/:id/map/info')
@UseBefore(AuthService.getAuthMiddleware([]))
@OpenAPI({
description: 'Get map metadata for Leaflet',
})
async getMapInfo(@Req() req: AuthenticatedRequest, @Params() params: ParamId) {
const service = new GameServerService(req.domainId);
return apiResponse(await service.getMapInfo(params.id));
}

@Get('/gameserver/:id/map/tile/:x/:y/:z')
@UseBefore(AuthService.getAuthMiddleware([]))
@ContentType('image/png')
@OpenAPI({
description: 'Get a map tile for Leaflet',
})
async getMapTile(@Req() req: AuthenticatedRequest, @Params() params: MapTileInputDTO) {
const service = new GameServerService(req.domainId);
const result = await service.getMapTile(params.id, params.x, params.y, params.z);
return result;
}
}
17 changes: 16 additions & 1 deletion packages/app-api/src/controllers/Shop/Listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
ShopListingUpdateDTO,
ShopListingCreateDTO,
ShopImportOptions,
ShopListingItemMetaOutputDTO,
ShopListingItemMetaInputDTO,
} from '../../service/Shop/dto.js';
import multer from 'multer';

Expand Down Expand Up @@ -156,7 +158,20 @@ export class ShopListingController {
const rawImportData = JSON.parse(req.body.import);
const rawOptions = JSON.parse(req.body.options);

const importData: ShopListingCreateDTO[] = rawImportData.map((item: any) => new ShopListingCreateDTO(item));
const importData: ShopListingCreateDTO[] = rawImportData.map(
(listing: any) =>
new ShopListingCreateDTO({
...listing,
items: listing.items.map(
(item: ShopListingItemMetaOutputDTO) =>
new ShopListingItemMetaInputDTO({
amount: item.amount,
quality: item.quality,
code: item.item.code,
}),
),
}),
);
const options = new ShopImportOptions(rawOptions);

await Promise.all(importData.map((item) => item.validate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IS
value: 'test coin',
});

const items = (await this.client.item.itemControllerSearch({ sortBy: 'name' })).data.data;
const items = (
await this.client.item.itemControllerSearch({
sortBy: 'name',
filters: { gameserverId: [setupData.gameServer1.id] },
})
).data.data;

const listingRes = await this.client.shopListing.shopListingControllerCreate({
gameServerId: setupData.gameServer1.id,
items: [{ itemId: items[0].id, amount: 1 }],
items: [{ code: items[0].code, amount: 1 }],
price: 100,
name: 'Test item',
});
Expand Down Expand Up @@ -60,7 +65,7 @@ const tests = [
const items = (await this.client.item.itemControllerSearch({ filters: { name: ['Stone'] } })).data.data;
const res = await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: items[0].id, amount: 1 }],
items: [{ code: items[0].code, amount: 1 }],
price: 150,
name: 'Test item',
});
Expand All @@ -80,7 +85,7 @@ const tests = [
test: async function () {
const res = await this.client.shopListing.shopListingControllerUpdate(this.setupData.listing.id, {
price: 200,
items: [{ itemId: this.setupData.items[1].id, amount: 5 }],
items: [{ code: this.setupData.items[1].code, amount: 5 }],
gameServerId: this.setupData.gameServer1.id,
name: 'Updated item',
});
Expand Down Expand Up @@ -132,7 +137,7 @@ const tests = [
test: async function () {
return this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[1].code, amount: 1 }],
price: -100,
name: 'Test item',
});
Expand All @@ -148,7 +153,7 @@ const tests = [
test: async function () {
return this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[1].code, amount: 1 }],
price: 0,
name: 'Test item',
});
Expand Down Expand Up @@ -180,7 +185,7 @@ const tests = [
Array.from({ length: listingsToMake }).map(async (_, i) => {
return this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: items[0].id, amount: 1 }],
items: [{ code: items[0].code, amount: 1 }],
price: 100 + i,
name: `Test item ${i}`,
});
Expand Down Expand Up @@ -222,6 +227,8 @@ const tests = [
expect(shop2Listings).to.have.length(shop1Listings.length);
// Check createdAt and compare to before to ensure these are new listings
expect(shop2ListingsBefore.every((l) => shop2Listings.some((l2) => l2.createdAt < l.createdAt))).to.be.true;
// Ensure there are items in the listing
expect(shop2Listings.every((l) => l.items.length > 0)).to.be.true;
},
}),
new IntegrationTest<IShopSetup>({
Expand All @@ -237,7 +244,7 @@ const tests = [
Array.from({ length: listingsToMake }).map(async (_, i) => {
return this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: items[0].id, amount: 1 }],
items: [{ code: items[0].code, amount: 1 }],
price: 100 + i,
name: `Test item ${i}`,
});
Expand Down Expand Up @@ -277,6 +284,8 @@ const tests = [
})
).data.data;
expect(shop2Listings).to.have.length(shop1Listings.length + shop2ListingsBefore.length);
// Ensure there are items in the listing
expect(shop2Listings.every((l) => l.items.length > 0)).to.be.true;
},
}),
new IntegrationTest<IShopSetup>({
Expand All @@ -292,7 +301,7 @@ const tests = [
Array.from({ length: listingsToMake }).map(async (_, i) => {
return this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: items[0].id, amount: 1 }],
items: [{ code: items[0].code, amount: 1 }],
price: 100 + i,
name: `Test item ${i}`,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IS

const listing100Res = await this.client.shopListing.shopListingControllerCreate({
gameServerId: setupData.gameServer1.id,
items: [{ itemId: items[0].id, amount: 1 }],
items: [{ code: items[0].code, amount: 1 }],
price: 100,
name: 'Test item',
});

const listing33Res = await this.client.shopListing.shopListingControllerCreate({
gameServerId: setupData.gameServer1.id,
items: [{ itemId: items[1].id, amount: 1 }],
items: [{ code: items[1].code, amount: 1 }],
price: 33,
name: 'Test item 2',
});
Expand Down Expand Up @@ -728,7 +728,7 @@ const tests = [
const listingGameserver1 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[0].code, amount: 1 }],
price: 1,
name: 'Test item 1',
})
Expand All @@ -737,7 +737,7 @@ const tests = [
const listingGameserver2 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer2.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[0].code, amount: 1 }],
price: 1,
name: 'Test item 2',
})
Expand Down Expand Up @@ -780,7 +780,7 @@ const tests = [
const listingGameserver1 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[0].code, amount: 1 }],
price: 1,
name: 'Test item 1',
})
Expand All @@ -789,7 +789,7 @@ const tests = [
const listingGameserver2 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer2.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[0].code, amount: 1 }],
price: 1,
name: 'Test item 2',
})
Expand Down Expand Up @@ -831,7 +831,7 @@ const tests = [
const listingGameserver1 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[0].code, amount: 1 }],
price: 1,
name: 'Test item 1',
})
Expand All @@ -840,7 +840,7 @@ const tests = [
const listingGameserver2 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer2.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
items: [{ code: this.setupData.items[0].code, amount: 1 }],
price: 1,
name: 'Test item 2',
})
Expand Down
Loading

0 comments on commit 012b05e

Please sign in to comment.