Skip to content

Commit

Permalink
Merge pull request #1589 from gettakaro/main-promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Oct 4, 2024
2 parents d4cfb0e + a856e00 commit 3262f38
Show file tree
Hide file tree
Showing 22 changed files with 313 additions and 48 deletions.
4 changes: 4 additions & 0 deletions containers/homer/assets/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ services:
subtitle: "Mail server"
url: "http://127.0.0.1:8025"
target: "_blank"
- name: "Redis Insight"
icon: "fas fa-database"
subtitle: "Redis UI"
url: "http://127.0.0.1:5540"
9 changes: 8 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
POSTGRES_DB: ${POSTGRES_DB}

redis:
image: redis:alpine
image: redis:7.2-alpine
# enables memory overcommit on reboot
# echo "vm.overcommit_memory = 1" | sudo tee /etc/sysctl.d/takaro-aio-memory-overcommit.conf
# sudo sysctl -w vm.overcommit_memory=1 (enables on-the-fly temporary)
Expand All @@ -31,6 +31,13 @@ services:
ports:
- 6379:6379

redis-insight:
image: redis/redisinsight:2.58
ports:
- "5540:5540"
volumes:
- ./_data/redis-insight:/data

takaro:
build:
context: .
Expand Down
81 changes: 57 additions & 24 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@types/ms": "0.7.34",
"@types/multer": "1.4.12",
"@types/node": "20.16.10",
"@types/react": "18.3.10",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.0",
"@types/safe-regex": "1.1.6",
"@types/sinon": "17.0.3",
Expand Down Expand Up @@ -118,7 +118,7 @@
"ajv": "8.17.1",
"axios": "1.7.7",
"body-parser": "1.20.3",
"bullmq": "5.13.2",
"bullmq": "5.15.0",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"class-validator-jsonschema": "5.0.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/app-api/src/controllers/Shop/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class ShopOrderSearchInputAllowedFilters extends AllowedFilters {
listingId: string[];
@IsOptional()
@IsUUID(4, { each: true })
gameServerId: string[];
@IsOptional()
@IsUUID(4, { each: true })
userId: string[];
@IsOptional()
@IsNumber({}, { each: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ interface IShopSetup extends SetupGameServerPlayers.ISetupData {
client1: Client;
user2: UserOutputDTO;
client2: Client;
user3: UserOutputDTO;
client3: Client;
user4: UserOutputDTO;
client4: Client;
}

const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IShopSetup> {
Expand All @@ -74,6 +78,11 @@ const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IS
gameServerId: setupData.gameServer1.id,
});

await this.client.settings.settingsControllerSet('economyEnabled', {
value: 'true',
gameServerId: setupData.gameServer2.id,
});

await this.client.settings.settingsControllerSet('currencyName', {
gameServerId: setupData.gameServer1.id,
value: 'test coin',
Expand Down Expand Up @@ -107,6 +116,18 @@ const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IS
{ currency: 250 },
);

await this.client.playerOnGameserver.playerOnGameServerControllerAddCurrency(
setupData.gameServer2.id,
setupData.pogs2[0].playerId,
{ currency: 250 },
);

await this.client.playerOnGameserver.playerOnGameServerControllerAddCurrency(
setupData.gameServer2.id,
setupData.pogs2[1].playerId,
{ currency: 250 },
);

const { client: user1Client, user: user1 } = await createUserForPlayer(
this.client,
setupData.pogs1[0].playerId,
Expand All @@ -119,6 +140,18 @@ const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IS
setupData.gameServer1.id,
);

const { client: user3Client, user: user3 } = await createUserForPlayer(
this.client,
setupData.pogs2[0].playerId,
setupData.gameServer2.id,
);

const { client: user4Client, user: user4 } = await createUserForPlayer(
this.client,
setupData.pogs2[1].playerId,
setupData.gameServer2.id,
);

return {
...setupData,
items,
Expand All @@ -128,6 +161,10 @@ const shopSetup = async function (this: IntegrationTest<IShopSetup>): Promise<IS
client1: user1Client,
user2,
client2: user2Client,
user3,
client3: user3Client,
user4,
client4: user4Client,
};
};

Expand Down Expand Up @@ -676,6 +713,53 @@ const tests = [
return res;
},
}),
new IntegrationTest<IShopSetup>({
group,
snapshot: false,
name: 'Can filter shop orders by gameserver ID',
setup: shopSetup,
test: async function () {
/**
* Setup listings on both gameservers
* Create orders for both listings
* Then, filter orders by gameserver ID
* Expect to only get orders for that gameserver
*/
const listingGameserver1 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer1.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
price: 1,
name: 'Test item 1',
})
).data.data;

const listingGameserver2 = (
await this.client.shopListing.shopListingControllerCreate({
gameServerId: this.setupData.gameServer2.id,
items: [{ itemId: this.setupData.items[0].id, amount: 1 }],
price: 1,
name: 'Test item 2',
})
).data.data;

await this.setupData.client1.shopOrder.shopOrderControllerCreate({
listingId: listingGameserver1.id,
amount: 1,
});

await this.setupData.client3.shopOrder.shopOrderControllerCreate({
listingId: listingGameserver2.id,
amount: 1,
});

const filteredOrders = await this.client.shopOrder.shopOrderControllerSearch({
filters: { gameServerId: [this.setupData.gameServer1.id] },
});

expect(filteredOrders.data.data).to.have.length(1);
},
}),
];

describe(group, function () {
Expand Down
4 changes: 4 additions & 0 deletions packages/app-api/src/db/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export class PlayerRepo extends ITakaroRepo<PlayerModel, PlayerOutputDTO, Player
.andWhere(function () {
this.where('steamLastFetch', '<', refreshOlderThanDate).orWhere('steamLastFetch', 'is', null);
})
// Ensure we only get valid steam IDs
// The mock server returns bad IDs and we don't want to send these to Steam
// Check for 17 digits, only numeric and starting with 7
.andWhere('steamId', '~', '^7[0-9]{16}$')
.orderBy('steamLastFetch', 'asc')
.limit(config.get('steam.refreshBatchSize'));

Expand Down
11 changes: 10 additions & 1 deletion packages/app-api/src/db/shopOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ export class ShopOrderRepo extends ITakaroRepo<

async find(filters: ITakaroQuery<ShopOrderOutputDTO>) {
const { query } = await this.getModel();
const result = await new QueryBuilder<ShopOrderModel, ShopOrderOutputDTO>({
const qry = new QueryBuilder<ShopOrderModel, ShopOrderOutputDTO>({
...filters,
}).build(query);

if (filters.filters?.gameServerId && Array.isArray(filters.filters.gameServerId)) {
qry
.join(ShopListingModel.tableName, `${ShopListingModel.tableName}.id`, `${ShopOrderModel.tableName}.listingId`)
.whereIn(`${ShopListingModel.tableName}.gameServerId`, filters.filters.gameServerId as string[]);
}

const result = await qry;

return {
total: result.total,
results: await Promise.all(result.results.map((item) => new ShopOrderOutputDTO(item))),
Expand Down
Loading

0 comments on commit 3262f38

Please sign in to comment.