Skip to content

Commit

Permalink
wip endorsement
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhollmann committed May 19, 2024
1 parent 095b22e commit 90d4d23
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 5 additions & 9 deletions backend/src/controllers/user/UserEndorsementAdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ async function addEndorsement(request: Request, response: Response, next: NextFu
},
include: [User.associations.endorsement_groups],
});
if(!user) {
throw new Error();
}


const endorsementGroup = await EndorsementGroup.findOne({where: {
id: Number(body.endorsement_group_id),
},})
if(!endorsementGroup) {
throw new Error();
}


const userEndorsement = await EndorsementGroupsBelongsToUsers.create({
user_id: user.id,
endorsement_group_id: endorsementGroup.id,
user_id: user?.id ?? -1,
endorsement_group_id: endorsementGroup?.id,
created_by: requestingUser.id,
});

Expand All @@ -40,7 +36,7 @@ async function addEndorsement(request: Request, response: Response, next: NextFu

if(!success){
await userEndorsement.destroy();
throw new Error();
throw new Error("Could not create endorsement in VATEUD CORE.");
}


Expand Down
6 changes: 4 additions & 2 deletions backend/src/libraries/vateud/VateudCoreLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function _send<T>(props: SendT): Promise<T | undefined> {

return res.data as T;
} catch (e: any) {
console.error(e)
Logger.log(LogLevels.LOG_WARN, e);
return undefined;
}
Expand Down Expand Up @@ -134,7 +135,8 @@ export async function removeSolo(userSolo: UserSolo) {
* 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...
*/
export async function createEndorsement(userEndorsement: EndorsementGroupsBelongsToUsers, endorsementGroup: EndorsementGroup) {
export async function createEndorsement(userEndorsement: EndorsementGroupsBelongsToUsers, endorsementGroup: EndorsementGroup | null) {
if(!endorsementGroup) return false;
const endorsementInfo: VateudCoreEndorsementCreateT = {
local_id: userEndorsement.id,
post_data: {
Expand All @@ -145,7 +147,7 @@ export async function createEndorsement(userEndorsement: EndorsementGroupsBelong
};

const res = await _send<VateudCoreSoloCreateResponseT>({
endpoint: `facility/endorsements/tier${endorsementGroup.tier}`,
endpoint: `facility/endorsements/tier-${endorsementGroup.tier}`,
method: "post",
data: endorsementInfo.post_data,
});
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/EndorsementGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class EndorsementGroup extends Model<InferAttributes<EndorsementGroup>, I
// Attributes
//
declare name: string;
declare tier: Number;
declare tier: number;

//
// Optional Attributes
Expand Down

0 comments on commit 90d4d23

Please sign in to comment.