-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recalculate function, client modal, docs improvements
- Loading branch information
Showing
13 changed files
with
195 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/client/src/pages/seasons/components/RecalculateModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { | ||
Button, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
Text, | ||
useDisclosure, | ||
useToast, | ||
} from '@chakra-ui/react' | ||
import { FaRedoAlt } from 'react-icons/fa' | ||
import { useRecalculateSeasonMutation } from 'src/api/hooks/seasonHooks' | ||
|
||
export const RecalculateModal = ({ seasonId }: { seasonId: string }) => { | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
const { mutate } = useRecalculateSeasonMutation(seasonId) | ||
const toast = useToast() | ||
|
||
const onSubmit = () => { | ||
mutate(undefined, { | ||
onSuccess: () => { | ||
onClose() | ||
toast({ | ||
title: 'Az újraszámítás megkezdődött!', | ||
description: 'Kérlek légy türelemmel, hamarosan már a frissített eredmények fogod látni a versenyek publikus oldalán!', | ||
status: 'success', | ||
}) | ||
}, | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
<Button onClick={onOpen} colorScheme="red" leftIcon={<FaRedoAlt />}> | ||
Pontok újraszámítása | ||
</Button> | ||
|
||
<Modal size="lg" isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Pontok újraszámítása</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<Text mb={2} textAlign="justify"> | ||
<b> | ||
A piros gomb megnyomásával elindítod ezen szezon lezajlott versenyeinek értékelési eredményeinek újraszámítását a jelenlegi | ||
súlyértékekkel. Ez egy hosszabb és erőforrásigényesebb művelet is lehet{' '} | ||
</b> | ||
(a lezajlott versenyek számától függően), ezért lehetőleg ne használd túl gyakran. A folyamat elindítását követő pár percben | ||
lehet, hogy lassabban fog működni az oldal. Amennyiben a teljesítmény hosszabb idő után sem javul, vagy furcsa anomáliák | ||
történnek, kérlek jelezd a fejlesztőnek. Az admin felület Tudnivalók oldal alján láthatsz frissítéseket a folyamat | ||
haladásáról. | ||
<b> | ||
{' '} | ||
Azt is tarstd fejben, hogy az újraszámolástól a már publikált eredmények megváltozhatnak, tehát szezon közben jobb lenne ezt | ||
elkerülni. | ||
</b> | ||
</Text> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Button mr={3} onClick={onClose}> | ||
Mégse | ||
</Button> | ||
<Button onClick={onSubmit} colorScheme="red"> | ||
Újraszámítás | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions' | ||
import { AlertLevel, EventState, PontozoException } from '@pontozo/common' | ||
import * as df from 'durable-functions' | ||
import { newAlertItem } from '../../service/alert.service' | ||
import { getUserFromHeaderAndAssertAdmin } from '../../service/auth.service' | ||
import Event from '../../typeorm/entities/Event' | ||
import Season from '../../typeorm/entities/Season' | ||
import { getAppDataSource } from '../../typeorm/getConfig' | ||
import { handleException } from '../../util/handleException' | ||
import { validateId } from '../../util/validation' | ||
import { orchestratorName } from '../events/closeRating/closeRatingOrchestrator' | ||
|
||
/** | ||
* Function to initiate the recalculation of rating scores for every event in a season. | ||
* It is called when an admin clicks on the 'Recalculate scores' button on the season's weight adjustment page. | ||
* The state of all the events of the season that are no longer rateable will be set to 'INVALITED', then | ||
* the closeRating orchestration function is called, which will redo the validation and accumulation stages for these events. | ||
*/ | ||
const recalculateRatingsInSeason = async (req: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> => { | ||
try { | ||
const user = await getUserFromHeaderAndAssertAdmin(req, context) | ||
const seasonId = validateId(req) | ||
const ads = await getAppDataSource(context) | ||
|
||
const season = await ads.getRepository(Season).findOne({ where: { id: seasonId }, relations: { events: true } }) | ||
if (!season) { | ||
throw new PontozoException('A szezon nem talalhato!', 404) | ||
} | ||
|
||
await newAlertItem({ | ||
context, | ||
desc: `User #${user.szemely_id} initiated result recalculation for Season #${seasonId}`, | ||
level: AlertLevel.INFO, | ||
ads, | ||
}) | ||
|
||
const invalidatedEvents = season.events | ||
.filter((e) => e.state !== EventState.RATEABLE) | ||
.map((e) => ({ ...e, state: EventState.INVALIDATED })) | ||
|
||
if (invalidatedEvents.length > 0) { | ||
await ads.getRepository(Event).save(invalidatedEvents) | ||
const client = df.getClient(context) | ||
const instanceId = await client.startNew(orchestratorName, { | ||
input: invalidatedEvents.map((e) => ({ eventId: e.id, state: e.state })), | ||
}) | ||
context.log(`Started orchestration with ID = '${instanceId}'.`) | ||
} else { | ||
context.log(`No events to recalculate`) | ||
} | ||
return { | ||
status: 204, | ||
} | ||
} catch (error) { | ||
return handleException(req, context, error) | ||
} | ||
} | ||
|
||
app.http('season-recalculate', { | ||
route: 'seasons/{id}/recalculate', | ||
methods: ['POST'], | ||
handler: recalculateRatingsInSeason, | ||
extraInputs: [df.input.durableClient()], | ||
}) |