Skip to content

Commit

Permalink
wip eud solos
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhollmann committed Apr 7, 2024
1 parent 81643be commit 8528570
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/controllers/solo/SoloAdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { User } from "../../models/User";
import { EndorsementGroupsBelongsToUsers } from "../../models/through/EndorsementGroupsBelongsToUsers";
import { TrainingSession } from "../../models/TrainingSession";
import PermissionHelper from "../../utility/helper/PermissionHelper";
import { createSolo as vateudCreateSolo } from "../../libraries/vateud/VateudCoreLibrary";
import { EndorsementGroup } from "../../models/EndorsementGroup";

type CreateSoloRequestBody = {
solo_duration: string;
Expand Down Expand Up @@ -51,6 +53,14 @@ async function createSolo(request: Request, response: Response, next: NextFuncti
solo_id: solo.id,
});

const endorsementGroup = await EndorsementGroup.findOne({
where: {
id: Number(body.endorsement_group_id),
},
});

if (endorsementGroup) await vateudCreateSolo(solo, endorsementGroup);

const returnUser = await User.findOne({
where: {
id: body.trainee_id,
Expand Down
20 changes: 13 additions & 7 deletions src/libraries/vateud/VateudCoreLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Config } from "../../core/Config";
import { UserSolo } from "../../models/UserSolo";
import Logger, { LogLevels } from "../../utility/Logger";
import { EndorsementGroup } from "../../models/EndorsementGroup";

type SendT = {
method: Method;
Expand Down Expand Up @@ -48,9 +49,19 @@ async function _send<T>(props: SendT): Promise<T | undefined> {
* On success, it updates the corresponding UserSolo with the returned VATEUD Solo ID
* On failure, it schedules a job which repeats the same request n times until it succeeds
* - If it fails more than n times, then it really isn't our problem anymore tbh...
* @param soloInfo
*/
async function createSolo(soloInfo: VateudCoreSoloCreateT) {
export async function createSolo(userSolo: UserSolo, endorsementGroup: EndorsementGroup) {
const soloInfo: VateudCoreSoloCreateT = {
local_solo_id: userSolo.id,
post_data: {
user_id: userSolo.user_id,
position: endorsementGroup.name,
instructor_cid: userSolo.created_by,
starts_at: userSolo.current_solo_start?.toString() ?? "",
expires_at: userSolo.current_solo_end?.toString() ?? "",
},
};

const res = await _send<VateudCoreSoloCreateResponseT>({
endpoint: "/solo",
method: "post",
Expand Down Expand Up @@ -111,8 +122,3 @@ async function removeSolo(soloInfo: VateudCoreSoloRemoveT) {
});
}
}

export default {
createSolo,
removeSolo,
};

0 comments on commit 8528570

Please sign in to comment.