Skip to content

Commit

Permalink
wip endorsements
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhollmann committed May 30, 2024
1 parent fca2cff commit ce47a8d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FILE_TMP_LOCATION=./storage/tmp/
# API ENDPOINT BASE URIs #
##########################
VATSIM_API_BASE=https://api.vatsim.net/api/v2
VATEUD_API_USE=false
VATEUD_API_BASE=https://core.vateud.net/api
VATEUD_API_KEY=
VATGER_API_BASE=https://vatsim-germany.org/api
Expand Down
1 change: 1 addition & 0 deletions backend/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ router.use(
"/endorsement",
routerGroup((r: Router) => {
r.post("/", UserEndorsementAdminController.addEndorsement);
r.delete("/", UserEndorsementAdminController.deleteEndorsement);
})
);

Expand Down
13 changes: 9 additions & 4 deletions backend/src/controllers/user/UserEndorsementAdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,25 @@ async function addEndorsement(request: Request, response: Response, next: NextFu
});


/*

if (!(await createEndorsement(userEndorsement, endorsementGroup))) {
await userEndorsement.destroy();
throw new Error();
throw new Error("Could not create endorsement in VATEUD CORE.");
}
*/


response.status(HttpStatusCode.Created).send(endorsementGroup);
} catch (e) {
next(e);
}
}

// TODO: Paul (keine Ahnung, was du hier probierst :D)
/**
* Deletes an endorsement to a user
* @param request
* @param response
* @param next
*/
async function deleteEndorsement(request: Request, response: Response, next: NextFunction) {
try {
const requestingUser: User = response.locals.user;
Expand Down
2 changes: 2 additions & 0 deletions backend/src/core/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const required_env: Array<string> = [
"FRONTEND_URI",
"SESSION_COOKIE_NAME",
"VATSIM_API_BASE",
"VATEUD_API_USE",
"VATEUD_API_BASE",
"VATEUD_API_KEY",
"VATGER_API_BASE",
Expand Down Expand Up @@ -78,6 +79,7 @@ export const Config = {
},

VATEUD_CORE_CONFIG: {
USE: process.env.VATEUD_API_USE,
API_KEY: process.env.VATEUD_API_KEY,
},

Expand Down
5 changes: 5 additions & 0 deletions backend/src/libraries/vateud/VateudCoreLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export async function removeSolo(userSolo: UserSolo) {
* On success, it updates the corresponding endorsement with the returned VATEUD ID
*/
export async function createEndorsement(userEndorsement: EndorsementGroupsBelongsToUsers, endorsementGroup: EndorsementGroup | null) {

if(!Config.VATEUD_CORE_CONFIG.USE) {
return true;
}

if (!endorsementGroup) return false;
const endorsementInfo: VateudCoreEndorsementCreateT = {
local_id: userEndorsement.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function EndorsementGroupCreateView() {
description={"Dieser Wert kann NICHT mehr geändert werden."}>
<option value={"1"}>Tier 1</option>
<option value={"2"}>Tier 2</option>
<option value={"0"}>nur Solo</option>
</Select>

<Separator />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function EGVSettingsSubpage() {
className={"mt-5"}
disabled
preIcon={<TbListNumbers size={ICON_SIZE_OPTS.MD} />}
value={endorsementGroup?.tier.toString()}
value={Number(endorsementGroup?.tier) > 0 ? `Tier ${endorsementGroup?.tier}` : 'Solo only'}
/>

<Separator />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function UVAddEndorsementModal({
onClose();
})
.catch(() => {
ToastHelper.error("Fehler beim erstellen der Freigabe");
ToastHelper.error("Fehler beim Erstellen der Freigabe");
})
.finally(() => setSubmitting(false));
}
Expand Down

0 comments on commit ce47a8d

Please sign in to comment.