auto-set von "hat gespielt"
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 45s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 45s
This commit is contained in:
@@ -71,6 +71,35 @@ function normalizeIdList(list) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function memberIdsFromParticipants(...participantLists) {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const list of participantLists) {
|
||||
for (const participant of normalizeParticipantList(list)) {
|
||||
if (participant.type !== 'member') continue;
|
||||
const id = Number.parseInt(participant.memberId, 10);
|
||||
if (!Number.isInteger(id) || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
result.push(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function mergeIdLists(...lists) {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const list of lists) {
|
||||
const normalized = normalizeIdList(list) || [];
|
||||
for (const id of normalized) {
|
||||
if (seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
result.push(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function isMatchLocked(match) {
|
||||
const dateText = cleanString(match?.date);
|
||||
if (!dateText) return false;
|
||||
@@ -138,6 +167,13 @@ class FriendlyMatchService {
|
||||
throw new HttpError('Datum, Heimteam und Gastteam sind Pflichtfelder.', 400);
|
||||
}
|
||||
|
||||
const homeParticipants = normalizeParticipantList(payload.homeParticipants);
|
||||
const guestParticipants = normalizeParticipantList(payload.guestParticipants);
|
||||
const resultDetails = Array.isArray(payload.resultDetails) ? payload.resultDetails : [];
|
||||
const autoPlayed = (Boolean(payload.isCompleted) || resultDetails.length > 0)
|
||||
? memberIdsFromParticipants(homeParticipants, guestParticipants)
|
||||
: [];
|
||||
|
||||
const match = await FriendlyMatch.create({
|
||||
clubId,
|
||||
date,
|
||||
@@ -155,12 +191,12 @@ class FriendlyMatchService {
|
||||
homeMatchPoints: Number.parseInt(payload.homeMatchPoints, 10) || 0,
|
||||
guestMatchPoints: Number.parseInt(payload.guestMatchPoints, 10) || 0,
|
||||
isCompleted: Boolean(payload.isCompleted),
|
||||
homeParticipants: normalizeParticipantList(payload.homeParticipants),
|
||||
guestParticipants: normalizeParticipantList(payload.guestParticipants),
|
||||
resultDetails: Array.isArray(payload.resultDetails) ? payload.resultDetails : [],
|
||||
homeParticipants,
|
||||
guestParticipants,
|
||||
resultDetails,
|
||||
playersReady: [],
|
||||
playersPlanned: [],
|
||||
playersPlayed: [],
|
||||
playersPlayed: autoPlayed,
|
||||
});
|
||||
return toScheduleRow(match);
|
||||
}
|
||||
@@ -190,6 +226,13 @@ class FriendlyMatchService {
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'resultDetails')) {
|
||||
updates.resultDetails = Array.isArray(payload.resultDetails) ? payload.resultDetails : [];
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'resultDetails') || payload.isCompleted === true) {
|
||||
const playedParticipants = memberIdsFromParticipants(
|
||||
Object.prototype.hasOwnProperty.call(updates, 'homeParticipants') ? updates.homeParticipants : match.homeParticipants,
|
||||
Object.prototype.hasOwnProperty.call(updates, 'guestParticipants') ? updates.guestParticipants : match.guestParticipants,
|
||||
);
|
||||
updates.playersPlayed = mergeIdLists(match.playersPlayed, playedParticipants);
|
||||
}
|
||||
|
||||
await match.update(updates);
|
||||
return toScheduleRow(match);
|
||||
|
||||
@@ -52,6 +52,35 @@ function normalizeIdList(list) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function memberIdsFromParticipants(...participantLists) {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const list of participantLists) {
|
||||
for (const participant of normalizeArrayValue(list)) {
|
||||
if (participant?.type !== 'member') continue;
|
||||
const id = Number.parseInt(participant.memberId, 10);
|
||||
if (!Number.isInteger(id) || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
result.push(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function mergeIdLists(...lists) {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const list of lists) {
|
||||
const normalized = normalizeIdList(list) || [];
|
||||
for (const id of normalized) {
|
||||
if (seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
result.push(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function normalizeTextForSearch(value) {
|
||||
return String(value ?? '')
|
||||
.normalize('NFKD')
|
||||
@@ -268,6 +297,13 @@ class FriendlyMatchSharedService {
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'resultDetails')) {
|
||||
updates.resultDetails = Array.isArray(payload.resultDetails) ? payload.resultDetails : [];
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'resultDetails') || payload.isCompleted === true) {
|
||||
const playedParticipants = memberIdsFromParticipants(
|
||||
Object.prototype.hasOwnProperty.call(updates, 'homeParticipants') ? updates.homeParticipants : match.homeParticipants,
|
||||
Object.prototype.hasOwnProperty.call(updates, 'guestParticipants') ? updates.guestParticipants : match.guestParticipants,
|
||||
);
|
||||
updates.playersPlayed = mergeIdLists(match.playersPlayed, playedParticipants);
|
||||
}
|
||||
|
||||
await match.update(updates);
|
||||
return toSharedScheduleRow(match, clubId);
|
||||
|
||||
Reference in New Issue
Block a user