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

Ontmoetingsformulier changes #611

Open
wants to merge 7 commits into
base: pandapanda_development
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */

const columnsToAdd = ["homeCaptainPresent", "awayCaptainPresent", "gameLeaderPresent", "homeCaptainAccepted", "awayCaptainAccepted", "gameLeaderAccepted"];

module.exports = {
async up (queryInterface, Sequelize) {
return queryInterface.sequelize.transaction(t => {
return Promise.all(
columnsToAdd.map(column => queryInterface.addColumn(
{ tableName: 'EncounterCompetitions', schema: 'event' },
column,
{
type: Sequelize.DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
{ transaction: t },
))
);
});
},

async down (queryInterface, Sequelize) {
return queryInterface.sequelize.transaction(t => {
return Promise.all(
columnsToAdd.map(column => queryInterface.removeColumn(
{ tableName: 'EncounterCompetitions', schema: 'event' },
column,
{
type: Sequelize.DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
{ transaction: t },
))
);
});
}
};
41 changes: 41 additions & 0 deletions database/migrations/20250220103101-add_encounterId_to_comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const columnsToAdd = ["encounterId"];

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
return queryInterface.sequelize.transaction(t => {
return Promise.all(
columnsToAdd.map(column => queryInterface.addColumn(
{ tableName: 'Comments', schema: 'public' },
column,
{
type: Sequelize.DataTypes.UUID,
allowNull: true,
references: {
model: {
tableName: 'EncounterCompetitions',
schema: 'event',
},
key: 'id',
},
},
{ transaction: t },
))
);
});
},

async down (queryInterface, Sequelize) {
return queryInterface.sequelize.transaction(t => {
return Promise.all(
columnsToAdd.map(column => queryInterface.removeColumn(
{ tableName: 'Comments', schema: 'public' },
column,
{ transaction: t },
))
);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
const t = await queryInterface.sequelize.transaction();

try {
await queryInterface.addConstraint(
{ tableName: 'Comments', schema: 'public' },
{
fields: ['encounterId'],
type: 'foreign key',
references: {
table: {tableName: 'EncounterCompetitions', schema: 'event'},
field: 'id',
},
onDelete: 'cascade',
onUpdate: 'cascade',
name: 'Comments_encounterId_fkey',

},
{transaction: t}
);
return t.commit();
} catch (error) {
console.log('error', error)
await t.rollback();
throw error;
}
},

async down (queryInterface, Sequelize) {
const t = await queryInterface.sequelize.transaction();

try {
await queryInterface.removeConstraint(
{ tableName: 'Comments', schema: 'public' },
'Comments_encounterId_fkey',
{ transaction: t },
);
return t.commit();
} catch (error) {
await t.rollback();
throw error;
}
},
};
Binary file added dump.rdb
Binary file not shown.
6 changes: 6 additions & 0 deletions libs/backend/database/src/models/comment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export class Comment extends Model {
@Column(DataType.UUIDV4)
clubId?: string;

@ForeignKey(() => EncounterCompetition)
@Index
@Field(() => ID, { nullable: true })
@Column(DataType.UUIDV4)
encounterId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field isn't needed, this is handeled by the linkId and linkType


@BelongsTo(() => EventCompetition, {
foreignKey: 'linkId',
constraints: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, ID, Int, ObjectType } from '@nestjs/graphql';
import { Field, ID, InputType, Int, ObjectType } from '@nestjs/graphql';
import {
BelongsToGetAssociationMixin,
BelongsToSetAssociationMixin,
Expand Down Expand Up @@ -145,6 +145,30 @@ export class EncounterCompetition extends Model<
@BelongsTo(() => Player, 'acceptedById')
acceptedBy?: Relation<Player>;

@Field(() => Boolean, { nullable: false })
@Column(DataType.BOOLEAN)
homeCaptainPresent?: boolean;

@Field(() => Boolean, { nullable: false })
@Column(DataType.BOOLEAN)
awayCaptainPresent?: boolean;

@Field(() => Boolean, { nullable: false })
@Column(DataType.BOOLEAN)
gameLeaderPresent?: boolean;

@Field(() => Boolean, { nullable: false })
@Column(DataType.BOOLEAN)
gameLeaderAccepted?: boolean;

@Field(() => Boolean, { nullable: false })
@Column(DataType.BOOLEAN)
homeCaptainAccepted?: boolean;

@Field(() => Boolean, { nullable: false })
@Column(DataType.BOOLEAN)
awayCaptainAccepted?: boolean;

@Field(() => Date, { nullable: true })
@Column(DataType.DATE)
enteredOn?: Date;
Expand Down Expand Up @@ -256,6 +280,16 @@ export class EncounterCompetition extends Model<
})
awayCommentsChange?: Relation<Comment[]>;

@Field(() => Comment, { nullable: true })
@HasOne(() => Comment, {
foreignKey: 'linkId',
constraints: true,
scope: {
linkType: 'encounter',
},
})
encounterComment?: Relation<Comment>;

// Has many Game
getGames!: HasManyGetAssociationsMixin<Game>;
setGames!: HasManySetAssociationsMixin<Game, string>;
Expand All @@ -279,6 +313,10 @@ export class EncounterCompetition extends Model<
getAway!: BelongsToGetAssociationMixin<Team>;
setAway!: BelongsToSetAssociationMixin<Team, string>;

// Belongs to Away
getAcceptedBy!: BelongsToGetAssociationMixin<Player>;
setAccdeptedBy!: BelongsToSetAssociationMixin<Player, string>;

// Has one EncounterChange
getEncounterChange!: HasOneGetAssociationMixin<EncounterChange>;
setEncounterChange!: HasOneSetAssociationMixin<EncounterChange, string>;
Expand Down Expand Up @@ -324,6 +362,11 @@ export class EncounterCompetition extends Model<
hasAwayComments!: HasManyHasAssociationsMixin<Comment, string>;
countAwayComments!: HasManyCountAssociationsMixin;

// Has one EncounterComment
getEncounterComment!: BelongsToGetAssociationMixin<Comment>;
setEncounterComment!: BelongsToSetAssociationMixin<Comment, string>;


// Has many HomeCommentsChange
getHomeCommentsChanges!: HasManyGetAssociationsMixin<Comment>;
setHomeCommentsChanges!: HasManySetAssociationsMixin<Comment, string>;
Expand All @@ -346,3 +389,42 @@ export class EncounterCompetition extends Model<
hasAwayCommentsChanges!: HasManyHasAssociationsMixin<Comment, string>;
countAwayCommentsChanges!: HasManyCountAssociationsMixin;
}

@InputType()
export class updateEncounterCompetitionInput {
@Field(() => Boolean, { nullable: true })
gameLeaderPresent?: boolean;

@Field(() => Boolean, { nullable: true })
homeCaptainPresent?: boolean;

@Field(() => Boolean, { nullable: true })
awayCaptainPresent?: boolean;

@Field(() => Boolean, { nullable: true })
gameLeaderAccepted?: boolean;

@Field(() => Boolean, { nullable: true })
homeCaptainAccepted?: boolean;

@Field(() => Boolean, { nullable: true })
awayCaptainAccepted?: boolean;

@Field(() => String, { nullable: true })
startHour?: string;

@Field(() => String, { nullable: true })
endHour?: string;

@Field(() => String, { nullable: true })
shuttle?: string;

@Field(() => Boolean, { nullable: true })
accepted?: boolean;

@Field(() => String, { nullable: true })
acceptedById?: string;

@Field(() => Date, { nullable: true })
acceptedOn?: Date;
}
45 changes: 44 additions & 1 deletion libs/backend/database/src/models/event/game.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import { SocketEmitter, EVENTS } from '../../../sockets';
import { Field, ID, Int, ObjectType } from '@nestjs/graphql';
import { Field, ID, InputType, Int, ObjectType, OmitType, PartialType } from '@nestjs/graphql';
import {
BelongsToGetAssociationMixin,
BelongsToManyAddAssociationMixin,
Expand Down Expand Up @@ -265,3 +265,46 @@ export class Game extends Model<InferAttributes<Game>, InferCreationAttributes<G
hasPlayers!: BelongsToManyHasAssociationsMixin<Player, string>;
countPlayer!: BelongsToManyCountAssociationsMixin;
}

@InputType()
export class GameNewInputPlayers {
@Field(() => ID)
id!: string;

@Field(() => ID)
systemId!: string;

@Field(() => Int)
team!: number;

@Field(() => Int)
player!: number;
}

@InputType()
export class GameNewInput extends PartialType(
OmitType(Game, ['id', 'visualCode', "rankingPoints", "players", 'competition','linkId', 'linkType', "tournament", "createdAt", "updatedAt"] as const),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually take the updatemodel as base so:

OmitType(GameUpdateInput, ['id'] as const),

InputType
) {
@Field(() => ID, { nullable: true })
linkId!: string;

@Field(() => String, { nullable: true })
linkType!: string;

@Field(() => [GameNewInputPlayers], { nullable: true })
players!: GameNewInputPlayers[];
}

@InputType()
export class GameUpdateInput extends PartialType(
OmitType(Game, ['id', 'visualCode', "rankingPoints", "players", 'competition','linkId', 'linkType', "tournament", "createdAt", "updatedAt"] as const),
InputType
) {
@Field(() => ID, { nullable: true })
linkId!: string;

@Field(() => ID, { nullable: true })
gameId!: string;
}

22 changes: 13 additions & 9 deletions libs/backend/graphql/src/resolvers/comment/comment.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class CommentResolver {
playerId: user.id,
linkId: newCommentData.linkId,
linkType: newCommentData.linkType,
clubId: newCommentData.clubId,
...(newCommentData.clubId ? {clubId: newCommentData.clubId} : {}),
...(newCommentData.encounterId ? {encounterId: newCommentData.encounterId} : {}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, this value should be filled in on linkId

},
defaults: {
...newCommentData,
Expand Down Expand Up @@ -105,7 +106,7 @@ export class CommentResolver {
if (!(link instanceof EncounterCompetition)) {
throw new BadRequestException(`linkType is not home_comment_chamge`);
}
await this.encounterComment(link, comment, user, transaction);
await this.encounterComment(link, comment, user, transaction);
break;
}

Expand Down Expand Up @@ -177,6 +178,8 @@ export class CommentResolver {
return EventCompetition.findByPk(linkId);
case 'encounterChange':
return EncounterCompetition.findByPk(linkId);
case 'encounter':
return EncounterCompetition.findByPk(linkId);
default:
throw new NotFoundException(`${linkType}: ${linkId}`);
}
Expand Down Expand Up @@ -230,13 +233,14 @@ export class CommentResolver {
) {
throw new UnauthorizedException(`You do not have permission to edit this comment`);
}

if (home.clubId === comment.clubId) {
await link.addHomeComment(comment, { transaction });
} else if (away.clubId === comment.clubId) {
await link.addAwayComment(comment, { transaction });
} else {
throw new BadRequestException(`clubId: ${comment.clubId} is not home or away`);
if (comment.clubId !== null && comment.encounterId === null) {
if (home.clubId === comment.clubId) {
await link.addHomeComment(comment, { transaction });
} else if (away.clubId === comment.clubId) {
await link.addAwayComment(comment, { transaction });
} else {
throw new BadRequestException(`clubId: ${comment.clubId} is not home or away`);
}
}
}
}
Loading
Loading