Skip to content

Commit

Permalink
Merge pull request #1597 from gettakaro/main-promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Oct 5, 2024
2 parents 3262f38 + f00fed5 commit 52a6004
Show file tree
Hide file tree
Showing 21 changed files with 411 additions and 214 deletions.
324 changes: 174 additions & 150 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"docker-compose": "0.24.8",
"dotenv": "16.4.5",
"eslint": "9.11.1",
"eslint-plugin-react": "7.37.0",
"eslint-plugin-react": "7.37.1",
"eslint-plugin-storybook": "0.9.0",
"fs-extra": "11.2.0",
"he": "1.2.0",
Expand All @@ -91,7 +91,7 @@
"typescript": "5.5.4",
"typescript-eslint": "8.8.0",
"vite-tsconfig-paths": "5.0.1",
"vitest": "2.1.1",
"vitest": "2.1.2",
"zx": "7.2.3"
},
"keywords": [],
Expand Down
12 changes: 10 additions & 2 deletions packages/app-api/src/controllers/StatsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class PogStatsInputDTO extends BaseStatsInputDTO {
playerId!: string;
}

class OptionalPogStatsInputDTO extends BaseStatsInputDTO {
@IsUUID('4')
gameServerId: string;
@IsUUID('4')
@IsOptional()
playerId?: string;
}

class PlayersOnlineInputDTO extends BaseStatsInputDTO {
@IsOptional()
@IsUUID('4')
Expand Down Expand Up @@ -100,9 +108,9 @@ export class StatsController {
@UseBefore(AuthService.getAuthMiddleware([PERMISSIONS.READ_PLAYERS]))
@ResponseSchema(StatsOutputDTOAPI)
@Get('/stats/currency')
async getCurrencyStats(@Req() req: AuthenticatedRequest, @QueryParams() query: PogStatsInputDTO) {
async getCurrencyStats(@Req() req: AuthenticatedRequest, @QueryParams() query: OptionalPogStatsInputDTO) {
const service = new StatsService(req.domainId);
return apiResponse(await service.getCurrency(query.playerId, query.gameServerId, query.startDate, query.endDate));
return apiResponse(await service.getCurrency(query.gameServerId, query.playerId, query.startDate, query.endDate));
}

@UseBefore(AuthService.getAuthMiddleware([]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,25 @@ const tests = [
},
expectedStatus: 404,
}),
new IntegrationTest<SetupGameServerPlayers.ISetupData>({
group,
snapshot: false,
name: 'Can remove expiration date of existing var',
setup: SetupGameServerPlayers.setup,
test: async function () {
const createRes = await this.client.variable.variableControllerCreate({
key: 'Test variable',
value: 'Test value',
expiresAt: new Date(Date.now() + 5000).toISOString(),
});

const updateRes = await this.client.variable.variableControllerUpdate(createRes.data.data.id, {
value: 'Updated value',
});

expect(updateRes.data.data.expiresAt).to.be.null;
},
}),
];

describe(group, function () {
Expand Down
8 changes: 7 additions & 1 deletion packages/app-api/src/db/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export class VariableRepo extends ITakaroRepo<VariablesModel, VariableOutputDTO,
if (!existing) throw new errors.NotFoundError();

const { query } = await this.getModel();
const res = await query.updateAndFetchById(id, data.toJSON()).returning('*');

const updateData = data.toJSON();
if (!updateData.expiresAt) {
updateData.expiresAt = null;
}

const res = await query.updateAndFetchById(id, updateData).returning('*');
return new VariableOutputDTO(res);
}
}
12 changes: 11 additions & 1 deletion packages/app-api/src/service/StatsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ export class StatsService extends TakaroService<TakaroModel, TakaroDTO<void>, Ta
return { values: data };
}

async getCurrency(playerId: string, gameserverId: string, startTime?: string, endTime?: string) {
async getCurrency(gameserverId: string, playerId?: string, startTime?: string, endTime?: string) {
if (!playerId) {
// Return global currency count
const data = await this.prometheusQuery(
`sum by(gameserver) (takaro_player_currency{domain="${this.domainId}", gameserver="${gameserverId}"})`,
startTime,
endTime,
);
return { values: data };
}

const data = await this.prometheusQuery(
`takaro_player_currency{job="worker", domain="${this.domainId}", player="${playerId}", gameserver="${gameserverId}"}`,
startTime,
Expand Down
2 changes: 1 addition & 1 deletion packages/app-api/src/workers/playerSyncWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export async function handlePlayerSync(gameServerId: string, domainId: string) {
ping: gamePlayer.ping,
}),
);
await log.debug(`Synced player ${gamePlayer.gameId} on game server ${gameServerId}`);
log.debug(`Synced player ${gamePlayer.gameId} on game server ${gameServerId}`);
}),
);

Expand Down
51 changes: 40 additions & 11 deletions packages/lib-apiclient/src/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - beba7b82477f27e48a128b4b6028e6fdfa149ec4
* The version of the OpenAPI document: development - 3b2d157a1e9a975202df8d28b26a2df38fa03417
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -5729,6 +5729,37 @@ export interface NOTDOMAINSCOPEDTakaroModelDTO {
*/
export type NOTDOMAINSCOPEDTakaroModelDTOCreatedAt = string;

/**
*
* @export
* @interface OptionalPogStatsInputDTO
*/
export interface OptionalPogStatsInputDTO {
/**
*
* @type {string}
* @memberof OptionalPogStatsInputDTO
*/
gameServerId: string;
/**
*
* @type {string}
* @memberof OptionalPogStatsInputDTO
*/
playerId?: string;
/**
*
* @type {StatsControllerGetPingStatsStartDateParameter}
* @memberof OptionalPogStatsInputDTO
*/
startDate?: StatsControllerGetPingStatsStartDateParameter;
/**
*
* @type {StatsControllerGetPingStatsStartDateParameter}
* @memberof OptionalPogStatsInputDTO
*/
endDate?: StatsControllerGetPingStatsStartDateParameter;
}
/**
*
* @export
Expand Down Expand Up @@ -21916,23 +21947,21 @@ export const StatsApiAxiosParamCreator = function (configuration?: Configuration
* Required permissions: `READ_PLAYERS`
* @summary Get currency stats
* @param {string} gameServerId
* @param {string} playerId
* @param {string} [playerId]
* @param {StatsControllerGetPingStatsStartDateParameter} [startDate]
* @param {StatsControllerGetPingStatsStartDateParameter} [endDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
statsControllerGetCurrencyStats: async (
gameServerId: string,
playerId: string,
playerId?: string,
startDate?: StatsControllerGetPingStatsStartDateParameter,
endDate?: StatsControllerGetPingStatsStartDateParameter,
options: RawAxiosRequestConfig = {},
): Promise<RequestArgs> => {
// verify required parameter 'gameServerId' is not null or undefined
assertParamExists('statsControllerGetCurrencyStats', 'gameServerId', gameServerId);
// verify required parameter 'playerId' is not null or undefined
assertParamExists('statsControllerGetCurrencyStats', 'playerId', playerId);
const localVarPath = `/stats/currency`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
Expand Down Expand Up @@ -22299,15 +22328,15 @@ export const StatsApiFp = function (configuration?: Configuration) {
* Required permissions: `READ_PLAYERS`
* @summary Get currency stats
* @param {string} gameServerId
* @param {string} playerId
* @param {string} [playerId]
* @param {StatsControllerGetPingStatsStartDateParameter} [startDate]
* @param {StatsControllerGetPingStatsStartDateParameter} [endDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async statsControllerGetCurrencyStats(
gameServerId: string,
playerId: string,
playerId?: string,
startDate?: StatsControllerGetPingStatsStartDateParameter,
endDate?: StatsControllerGetPingStatsStartDateParameter,
options?: RawAxiosRequestConfig,
Expand Down Expand Up @@ -22531,15 +22560,15 @@ export const StatsApiFactory = function (configuration?: Configuration, basePath
* Required permissions: `READ_PLAYERS`
* @summary Get currency stats
* @param {string} gameServerId
* @param {string} playerId
* @param {string} [playerId]
* @param {StatsControllerGetPingStatsStartDateParameter} [startDate]
* @param {StatsControllerGetPingStatsStartDateParameter} [endDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
statsControllerGetCurrencyStats(
gameServerId: string,
playerId: string,
playerId?: string,
startDate?: StatsControllerGetPingStatsStartDateParameter,
endDate?: StatsControllerGetPingStatsStartDateParameter,
options?: RawAxiosRequestConfig,
Expand Down Expand Up @@ -22702,7 +22731,7 @@ export class StatsApi extends BaseAPI {
* Required permissions: `READ_PLAYERS`
* @summary Get currency stats
* @param {string} gameServerId
* @param {string} playerId
* @param {string} [playerId]
* @param {StatsControllerGetPingStatsStartDateParameter} [startDate]
* @param {StatsControllerGetPingStatsStartDateParameter} [endDate]
* @param {*} [options] Override http request option.
Expand All @@ -22711,7 +22740,7 @@ export class StatsApi extends BaseAPI {
*/
public statsControllerGetCurrencyStats(
gameServerId: string,
playerId: string,
playerId?: string,
startDate?: StatsControllerGetPingStatsStartDateParameter,
endDate?: StatsControllerGetPingStatsStartDateParameter,
options?: RawAxiosRequestConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - beba7b82477f27e48a128b4b6028e6fdfa149ec4
* The version of the OpenAPI document: development - 3b2d157a1e9a975202df8d28b26a2df38fa03417
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - beba7b82477f27e48a128b4b6028e6fdfa149ec4
* The version of the OpenAPI document: development - 3b2d157a1e9a975202df8d28b26a2df38fa03417
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - beba7b82477f27e48a128b4b6028e6fdfa149ec4
* The version of the OpenAPI document: development - 3b2d157a1e9a975202df8d28b26a2df38fa03417
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - beba7b82477f27e48a128b4b6028e6fdfa149ec4
* The version of the OpenAPI document: development - 3b2d157a1e9a975202df8d28b26a2df38fa03417
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cloneElement, forwardRef, ReactElement } from 'react';
import { Color, Size } from '../../../styled/types';
import { Badge } from '../../../components';
import { Default } from './style';

export interface IconButtonProps {
Expand Down Expand Up @@ -35,7 +36,7 @@ export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(functio
return (
<Default type="button" color={color} onClick={onClick} ref={ref} disabled={disabled} aria-label={ariaLabel}>
{cloneElement(icon, { size: getSize(size) })}
{badge && <div>{badge}</div>}
{badge && <Badge>{badge}</Badge>}
</Default>
);
});
19 changes: 0 additions & 19 deletions packages/lib-components/src/components/actions/IconButton/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,6 @@ export const Default = styled.button<{ color: Color }>`
}
}
div {
background-color: ${({ theme }) => theme.colors.background};
color: ${({ theme }) => theme.colors.text};
font-size: ${({ theme }) => theme.fontSize.tiny};
font-weight: 600;
border-radius: ${({ theme }) => theme.borderRadius.small};
width: fit-content;
height: 1.5rem;
line-height: 1.1rem;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: -${({ theme }) => theme.spacing['0_75']};
right: -${({ theme }) => theme.spacing['0_75']};
padding: ${({ theme }) => theme.spacing['0_25']};
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
}
svg {
cursor: pointer;
fill: ${({ theme }) => theme.colors.text};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { Meta, StoryFn } from '@storybook/react';
import { Badge, BadgeProps } from '.';

export default {
title: 'Feedback/Badge',
component: Badge,
args: {
variant: 'warning',
animate: false,
},
} as Meta<BadgeProps>;

export const Default: StoryFn<BadgeProps> = (args) => (
<div>
<h2 style={{ backgroundColor: 'orange', position: 'relative', width: 'fit-content' }}>
this is the title{' '}
<Badge variant={args.variant} animate={args.animate}>
here
</Badge>
</h2>
</div>
);
47 changes: 47 additions & 0 deletions packages/lib-components/src/components/feedback/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { forwardRef, PropsWithChildren } from 'react';
import { pulseAnimation, styled } from '../../../styled';
import { AlertVariants, Color } from '../../../styled';
import { shade } from 'polished';

type ColorVariant = AlertVariants | Color | 'default';

const Container = styled.div<{ variant: ColorVariant; animate: boolean }>`
background-color: ${({ theme, variant }) =>
variant === 'default' ? theme.colors.background : shade('0.8', theme.colors[variant])};
color: ${({ theme, variant }) => (variant === 'default' ? theme.colors.text : theme.colors[variant])};
font-size: ${({ theme }) => theme.fontSize.tiny};
font-weight: 600;
border-radius: ${({ theme }) => theme.borderRadius.small};
width: fit-content;
height: 1.5rem;
line-height: 1.1rem;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: -${({ theme }) => theme.spacing['1']};
right: -${({ theme }) => theme.spacing['0_75']};
padding: ${({ theme }) => theme.spacing['0_25']};
border: 1px solid
${({ theme, variant }) => (variant === 'default' ? theme.colors.backgroundAccent : theme.colors[variant])};
animation: ${({ animate, variant, theme }) =>
animate ? pulseAnimation(variant === 'default' ? theme.colors.backgroundAccent : theme.colors[variant]) : 'none'}
5s infinite ease-in-out;
`;

export interface BadgeProps {
variant?: ColorVariant;
animate?: boolean;
}

export const Badge = forwardRef<HTMLDivElement, PropsWithChildren<BadgeProps>>(function Badge(
{ variant = 'default', children, animate = false },
ref,
) {
return (
<Container ref={ref} variant={variant} animate={animate}>
{children}
</Container>
);
});
3 changes: 3 additions & 0 deletions packages/lib-components/src/components/feedback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ export type { ErrorPageProps } from './ErrorPage';

export { FormError } from './FormError';
export type { FormErrorProps } from './FormError';

export { Badge } from './Badge';
export type { BadgeProps } from './Badge';
Loading

0 comments on commit 52a6004

Please sign in to comment.