diff --git a/src/controllers/solo/SoloAdminController.ts b/src/controllers/solo/SoloAdminController.ts index d4c663d..5d69670 100644 --- a/src/controllers/solo/SoloAdminController.ts +++ b/src/controllers/solo/SoloAdminController.ts @@ -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; @@ -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, diff --git a/src/libraries/vateud/VateudCoreLibrary.ts b/src/libraries/vateud/VateudCoreLibrary.ts index f0d459e..0878899 100644 --- a/src/libraries/vateud/VateudCoreLibrary.ts +++ b/src/libraries/vateud/VateudCoreLibrary.ts @@ -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; @@ -48,9 +49,19 @@ async function _send(props: SendT): Promise { * 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({ endpoint: "/solo", method: "post", @@ -111,8 +122,3 @@ async function removeSolo(soloInfo: VateudCoreSoloRemoveT) { }); } } - -export default { - createSolo, - removeSolo, -};