Skip to content

Commit

Permalink
chore(merge): merge develop into main
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Sep 21, 2024
2 parents d93b796 + 777a5f1 commit d09081b
Show file tree
Hide file tree
Showing 18 changed files with 383 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,8 @@ const includes = [
include: [
{
required: true,
attributes: ['id'],
attributes: ['id', 'eventId'],
model: SubEventCompetition,
include: [
{
required: true,
attributes: ['id', 'visualCode'],
model: EventCompetition,
where: {
checkEncounterForFilledIn: true,
},
},
],
},
],
},
Expand Down Expand Up @@ -172,6 +162,7 @@ export class CheckEncounterProcessor {

// Processing encounters
for (const encounter of chunk) {
await this.loadEvent(encounter);
await this._syncEncounter(encounter, page);
encountersProcessed++;
}
Expand All @@ -192,6 +183,7 @@ export class CheckEncounterProcessor {

cronJob.amount++;
cronJob.lastRun = new Date();
cronJob.running = false;
await cronJob.save();

this.logger.log('Synced encounters');
Expand All @@ -206,12 +198,17 @@ export class CheckEncounterProcessor {
include: includes,
});

await this.loadEvent(encounter);

if (!encounter) {
this.logger.error(`Encounter ${job.data.encounterId} not found`);
return;
}

this.logger.debug(encounter.drawCompetition.subEventCompetition.eventCompetition.toJSON());

// Create browser
const browser = await getBrowser(false);
const browser = await getBrowser();
try {
const page = await browser.newPage();
page.setDefaultTimeout(10000);
Expand All @@ -236,6 +233,25 @@ export class CheckEncounterProcessor {
}
}

private async loadEvent(encounter: EncounterCompetition) {
const event = await encounter.drawCompetition.subEventCompetition.getEventCompetition({
attributes: ['id', 'visualCode', 'contactEmail', 'name'],
where: {
checkEncounterForFilledIn: true,
},
include: [
{
model: Player,
as: 'contact',
attributes: ['id', 'email'],
},
],
});

// set the event
encounter.drawCompetition.subEventCompetition.eventCompetition = event;
}

private async _syncEncounter(encounter: EncounterCompetition, page: Page) {
const url = await gotoEncounterPage({ page }, encounter);
this.logger.debug(`Syncing encounter ${url}`);
Expand All @@ -255,6 +271,11 @@ export class CheckEncounterProcessor {
`Encounter passed ${hoursPassed} hours ago, entered: ${entered}, accepted: ${accepted}, has comments: ${hasComment} ( ${url} )`,
);

// if we have a comment notify the event contact
if (hasComment) {
this.notificationService.notifyEncounterHasComment(encounter);
}

// not entered and passed 24 hours and no comment
if (!entered && hoursPassed > 24 && !hasComment) {
this.notificationService.notifyEncounterNotEntered(encounter);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* eslint-disable @typescript-eslint/no-var-requires */
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, sequelize) => {
return queryInterface.sequelize.transaction(async (t) => {
try {
await queryInterface.addColumn(
{
tableName: 'Settings',
schema: 'personal',
},
'encounterHasCommentNotification',
{
type: sequelize.DataTypes.INTEGER,
allowNull: false,
defaultValue: 2,
},
{ transaction: t },
);

await queryInterface.addColumn(
{
tableName: 'EventCompetitions',
schema: 'event',
},
'contactId',
{
type: sequelize.DataTypes.UUID,
allowNull: true,
references: {
model: {
tableName: 'Players',
schema: 'public',
},
key: 'id',
},
},
{ transaction: t },
);


} catch (err) {
console.error('We errored with', err?.message ?? err);
t.rollback();
}
});
},

down: async (queryInterface) => {
return queryInterface.sequelize.transaction(async (t) => {
try {
await queryInterface.removeColumn(
{
tableName: 'Settings',
schema: 'personal',
},
'encounterHasCommentNotification',
{ transaction: t },
);

await queryInterface.removeColumn(
{
tableName: 'EventCompetitions',
schema: 'event',
},
'contactId',
{ transaction: t },
);
} catch (err) {
console.error('We errored with', err);
t.rollback();
}
});
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LevelType, UsedRankingTiming } from '@badman/utils';
import { Field, ID, InputType, Int, ObjectType, OmitType, PartialType } from '@nestjs/graphql';
import {
BelongsToGetAssociationMixin,
BelongsToSetAssociationMixin,
CreationOptional,
HasManyAddAssociationMixin,
HasManyAddAssociationsMixin,
Expand All @@ -15,6 +17,7 @@ import {
InferCreationAttributes,
} from 'sequelize';
import {
BelongsTo,
Column,
DataType,
Default,
Expand All @@ -36,6 +39,7 @@ import {
Slugify,
} from '../../../types';
import { Relation } from '../../../wrapper';
import { Player } from '../../player.model';
import { Role } from '../../security';
import { AvailabilityException } from '../availability.model';
import { Comment } from './../../comment.model';
Expand Down Expand Up @@ -64,7 +68,7 @@ export class EventCompetition extends Model<
override createdAt?: Date;

@Unique('EventCompetitions_unique_constraint')
@Field(() => String, { nullable: true })
@Field(() => String, { nullable: false })
@Column(DataType.STRING)
name?: string;

Expand Down Expand Up @@ -95,7 +99,7 @@ export class EventCompetition extends Model<

@Field(() => Date, { nullable: true })
@Column(DataType.DATE)
changeCloseDatePeriod2?: Date;
changeCloseDatePeriod2?: Date;

@Field(() => Date, { nullable: true })
@Column(DataType.DATE)
Expand All @@ -115,6 +119,17 @@ export class EventCompetition extends Model<
@Column(DataType.STRING)
contactEmail?: string;

@Field(() => ID, { nullable: true })
@Column(DataType.UUIDV4)
contactId?: string;

@Field(() => Player, { nullable: true })
@BelongsTo(() => Player, {
foreignKey: 'contactId',
constraints: false,
})
contact?: Relation<Player>;

@Field(() => [Comment], { nullable: true })
@HasMany(() => Comment, {
foreignKey: 'linkId',
Expand Down Expand Up @@ -252,6 +267,10 @@ export class EventCompetition extends Model<
hasRole!: HasManyHasAssociationMixin<Role, string>;
hasRoles!: HasManyHasAssociationsMixin<Role, string>;
countRoles!: HasManyCountAssociationsMixin;

// Belongs to Contact
getContact!: BelongsToGetAssociationMixin<Player>;
setContact!: BelongsToSetAssociationMixin<Player, string>;
}

@InputType()
Expand All @@ -264,6 +283,7 @@ export class EventCompetitionUpdateInput extends PartialType(
'roles',
'exceptions',
'infoEvents',
'contact',
'meta',
] as const),
InputType,
Expand Down
7 changes: 7 additions & 0 deletions libs/backend/database/src/models/personal/setting.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export class Setting extends Model {
defaultValue: NotificationType.NONE,
})
encounterChangeFinishedNotification!: NotificationType;

@Field(() => Int)
@Column({
type: DataType.INTEGER,
defaultValue: NotificationType.NONE,
})
encounterHasCommentNotification!: NotificationType;

@Field(() => Int)
@Column({
Expand Down
29 changes: 29 additions & 0 deletions libs/backend/mailing/src/compile/templates/hasComment/html.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends ../../layouts/layout.pug

block title
h1.text-center
| Ontmoeting heeft een opmerking

block content
p.text-center
p
| Beste #{ contact },
br
br
|
| De ontmoeting
strong #{ encounter.home.name }
| tegen
strong #{ encounter.away.name }
| op
strong #{ date }
| heeft een opmerking.
br
p
a(href=`${url}`)
| Ga naar ontmoeting
p
| Met sportieve groeten,
br
|
| Badman
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,4 @@ block content
| Met sportieve groeten,
br
|
| Badman
p
| Disclaimer:
br
small
|
| Deze notificatie is nog in beta. Mocht je vragen of opmerkingen hebben, laat het ons weten via
a(href="mailto:[email protected]") badmintonvlaanderen
| Badman
12 changes: 3 additions & 9 deletions libs/backend/mailing/src/compile/templates/notentered/html.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ block content
br
br
|
| De ontmoeting
| De ontmoeting
strong #{ encounter.home.name }
| tegen
| tegen
strong #{ encounter.away.name }
| op
| op
strong #{ date }
| is nog niet ingevuld.
br
Expand All @@ -27,9 +27,3 @@ block content
br
|
| Badman
p
| Disclaimer:
br
|
| Deze notificatie is nog in beta. Mocht je vragen of opmerkingen hebben, laat het ons weten via
a(href="mailto:[email protected]") badmintonvlaanderen
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,4 @@ block content
| Met sportieve groeten,
br
|
| Badman
p
| Disclaimer:
br
small
|
| Deze notificatie is nog in beta. Mocht je vragen of opmerkingen hebben, laat het ons weten via
a(href="mailto:[email protected]") badmintonvlaanderen
| Badman
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,4 @@ block content
| Met sportieve groeten,
br
|
| Badman
p
| Disclaimer:
br
small
|
| Deze notificatie is nog in beta. Mocht je vragen of opmerkingen hebben, laat het ons weten via
a(href="mailto:[email protected]") badmintonvlaanderen
| Badman
Loading

0 comments on commit d09081b

Please sign in to comment.