Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.45.0 #344

Merged
merged 9 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "game-services",
"version": "0.44.0",
"version": "0.45.0",
"description": "",
"main": "src/index.ts",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import UserPinnedGroup from './user-pinned-group'
import PlayerAuthActivity from './player-auth-activity'
import PlayerAuth from './player-auth'
import GameFeedback from './game-feedback'
Expand Down Expand Up @@ -33,6 +34,7 @@ import PlayerGroup from './player-group'
import GameSecret from './game-secret'

export default [
UserPinnedGroup,
PlayerAuthActivity,
PlayerAuth,
GameFeedback,
Expand Down
4 changes: 3 additions & 1 deletion src/entities/subscribers/player.subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default class PlayerSubscriber implements EventSubscriber {
const em = (args.em as EntityManager).fork()

const changeSets = args.uow.getChangeSets()
const cs = changeSets.find((cs) => [ChangeSetType.CREATE, ChangeSetType.UPDATE].includes(cs.type) && cs.entity instanceof Player)
const cs = changeSets.find((cs) => {
return [ChangeSetType.CREATE, ChangeSetType.UPDATE].includes(cs.type) && cs.entity instanceof Player
})

if (cs) {
await checkGroupMemberships(em, cs.entity as Player)
Expand Down
24 changes: 24 additions & 0 deletions src/entities/user-pinned-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Entity, ManyToOne, PrimaryKey, Property, Unique } from '@mikro-orm/mysql'
import User from './user'
import PlayerGroup from './player-group'

@Entity()
@Unique({ properties: ['user', 'group'] })
export default class UserPinnedGroup {
@PrimaryKey()
id: number

@ManyToOne(() => User, { eager: true })
user: User

@ManyToOne(() => PlayerGroup, { eager: true })
group: PlayerGroup

@Property()
createdAt: Date = new Date()

constructor(user: User, group: PlayerGroup) {
this.user = user
this.group = group
}
}
4 changes: 2 additions & 2 deletions src/lib/dates/dateValidationSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBefore, isValid } from 'date-fns'
import { isBefore, isSameDay, isValid } from 'date-fns'
import { Request, Validatable, ValidationCondition } from 'koa-clay'

const schema: Validatable = {
Expand All @@ -15,7 +15,7 @@ const schema: Validatable = {
break: true
},
{
check: isValid(endDate) ? isBefore(startDate, endDate) : true,
check: isValid(endDate) ? (isBefore(startDate, endDate) || isSameDay(startDate, endDate)) : true,
error: 'Invalid start date, it should be before the end date'
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/checkGroupMemberships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function checkGroupMemberships(em: EntityManager, player: P

if (playerIsEligible && !playerCurrentlyInGroup) {
group.members.add(player)
} else if (playerCurrentlyInGroup) {
} else if (!playerIsEligible && playerCurrentlyInGroup) {
group.members.remove(group.members.getItems().find((member) => member.id === player.id))
}
}
Expand Down
116 changes: 116 additions & 0 deletions src/migrations/.snapshot-gs_dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -3122,6 +3122,122 @@
},
"nativeEnums": {}
},
{
"columns": {
"id": {
"name": "id",
"type": "int",
"unsigned": true,
"autoincrement": true,
"primary": true,
"nullable": false,
"length": null,
"mappedType": "integer"
},
"user_id": {
"name": "user_id",
"type": "int",
"unsigned": true,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": null,
"mappedType": "integer"
},
"group_id": {
"name": "group_id",
"type": "varchar(255)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 255,
"mappedType": "string"
},
"created_at": {
"name": "created_at",
"type": "datetime",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": null,
"mappedType": "datetime"
}
},
"name": "user_pinned_group",
"indexes": [
{
"columnNames": [
"user_id"
],
"composite": false,
"keyName": "user_pinned_group_user_id_index",
"constraint": false,
"primary": false,
"unique": false
},
{
"columnNames": [
"group_id"
],
"composite": false,
"keyName": "user_pinned_group_group_id_index",
"constraint": false,
"primary": false,
"unique": false
},
{
"keyName": "user_pinned_group_user_id_group_id_unique",
"columnNames": [
"user_id",
"group_id"
],
"composite": true,
"constraint": true,
"primary": false,
"unique": true
},
{
"keyName": "PRIMARY",
"columnNames": [
"id"
],
"composite": false,
"constraint": true,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {
"user_pinned_group_user_id_foreign": {
"constraintName": "user_pinned_group_user_id_foreign",
"columnNames": [
"user_id"
],
"localTableName": "user_pinned_group",
"referencedColumnNames": [
"id"
],
"referencedTableName": "user",
"updateRule": "cascade"
},
"user_pinned_group_group_id_foreign": {
"constraintName": "user_pinned_group_group_id_foreign",
"columnNames": [
"group_id"
],
"localTableName": "user_pinned_group",
"referencedColumnNames": [
"id"
],
"referencedTableName": "player_group",
"updateRule": "cascade"
}
},
"nativeEnums": {}
},
{
"columns": {
"id": {
Expand Down
19 changes: 19 additions & 0 deletions src/migrations/20241001194252CreateUserPinnedGroupsTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Migration } from '@mikro-orm/migrations'

export class CreateUserPinnedGroupsTable extends Migration {

override async up(): Promise<void> {
this.addSql('create table `user_pinned_group` (`id` int unsigned not null auto_increment primary key, `user_id` int unsigned not null, `group_id` varchar(255) not null, `created_at` datetime not null) default character set utf8mb4 engine = InnoDB;')
this.addSql('alter table `user_pinned_group` add index `user_pinned_group_user_id_index`(`user_id`);')
this.addSql('alter table `user_pinned_group` add index `user_pinned_group_group_id_index`(`group_id`);')
this.addSql('alter table `user_pinned_group` add unique `user_pinned_group_user_id_group_id_unique`(`user_id`, `group_id`);')

this.addSql('alter table `user_pinned_group` add constraint `user_pinned_group_user_id_foreign` foreign key (`user_id`) references `user` (`id`) on update cascade;')
this.addSql('alter table `user_pinned_group` add constraint `user_pinned_group_group_id_foreign` foreign key (`group_id`) references `player_group` (`id`) on update cascade;')
}

override async down(): Promise<void> {
this.addSql('drop table if exists `user_pinned_group`;')
}

}
5 changes: 5 additions & 0 deletions src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { CreatePlayerAuthActivityTable } from './20240725183402CreatePlayerAuthA
import { UpdatePlayerAliasServiceColumn } from './20240916213402UpdatePlayerAliasServiceColumn'
import { AddPlayerAliasAnonymisedColumn } from './20240920121232AddPlayerAliasAnonymisedColumn'
import { AddLeaderboardEntryPropsColumn } from './20240922222426AddLeaderboardEntryPropsColumn'
import { CreateUserPinnedGroupsTable } from './20241001194252CreateUserPinnedGroupsTable'

export default [
{
Expand Down Expand Up @@ -154,5 +155,9 @@ export default [
{
name: 'AddLeaderboardEntryPropsColumn',
class: AddLeaderboardEntryPropsColumn
},
{
name: 'CreateUserPinnedGroupsTable',
class: CreateUserPinnedGroupsTable
}
]
14 changes: 14 additions & 0 deletions src/policies/player-group.policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ export default class PlayerGroupPolicy extends Policy {

return await this.canAccessGame(Number(gameId))
}

async indexPinned(req: Request): Promise<PolicyResponse> {
const { gameId } = req.params
return await this.canAccessGame(Number(gameId))
}

async togglePinned(req: Request): Promise<PolicyResponse> {
const { gameId, id } = req.params

this.ctx.state.group = await this.em.getRepository(PlayerGroup).findOne(id)
if (!this.ctx.state.group) return new PolicyDenial({ message: 'Group not found' }, 404)

return await this.canAccessGame(Number(gameId))
}
}
Loading