From 664db1355a945d2e036972cebde45ad5fe277306 Mon Sep 17 00:00:00 2001 From: Linnea Myllynen Date: Thu, 27 Apr 2023 16:01:41 +0300 Subject: [PATCH] add more logging and update kuksa fields --- src/auth.js | 29 ++++++++++++++--------------- src/groups.js | 6 ++++-- src/profile.js | 7 ++++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/auth.js b/src/auth.js index 3d78234..6ebc898 100644 --- a/src/auth.js +++ b/src/auth.js @@ -42,23 +42,22 @@ module.exports.configurePassport = async (clientUrl) => { try { //TODO: Is there a way to not hard code these? - const restrictedAgeGroups = [35, 21, 13] //sudenpennut, seikkailijat, tarpojat - const memberData = await request( - `${process.env.KUKSA}/members/${profile.membernumber}`, - { - json: true, - auth: { - user: process.env.KUKSA_USER, - pass: process.env.KUKSA_PASS, - }, - } - ) + const url = `${process.env.KUKSA}/members/${profile.membernumber}` + console.log('Kuksa URL: ', url) + const restrictedAgeGroups = [4, 5, 6] //sudenpennut, seikkailijat, tarpojat + const memberData = await request(url, { + json: true, + auth: { + user: process.env.KUKSA_USER, + pass: process.env.KUKSA_PASS, + }, + }) console.log('membeData: ', memberData) - console.log('memberData.ageGroupId: ', memberData.ageGroupId) + console.log('memberData.ageGroupId: ', memberData.age_groupId) - let ageGroup = 35 //Sudenpennut - if (memberData.ageGroupId !== null) { - ageGroup = memberData.ageGroupId + let ageGroup = 4 //Sudenpennut + if (memberData.age_groupId !== null) { + ageGroup = memberData.age_groupId } console.log('ageGroupId: ', ageGroup) scout.canMarkDone = !restrictedAgeGroups.includes(ageGroup) diff --git a/src/groups.js b/src/groups.js index 8bb2bf8..4638268 100644 --- a/src/groups.js +++ b/src/groups.js @@ -58,10 +58,12 @@ async function getAllGroups(userNumber) { const groupInfo = await getGroupInfo(userNumber, group.id) const groupMembers = await getGroupMembers(userNumber, group.id) const memberData = await getMemberData(groupMembers) + console.log('memberData: ', memberData) const ageGroupId = (memberData[0] && - (await getMember(memberData[0].memberId)).ageGroupId) || + (await getMember(memberData[0].memberId)).age_groupId) || 4 + return Object.assign( {}, { @@ -70,7 +72,7 @@ async function getAllGroups(userNumber) { ageGroup: groupInfo.ageGroups[0], ageGroupId, troop: groupInfo.troops.filter( - (troop) => troop.id === member.defaultTroopId + (troop) => troop.id === member.default_troop_id ), members: memberData, } diff --git a/src/profile.js b/src/profile.js index 012c946..09616bd 100644 --- a/src/profile.js +++ b/src/profile.js @@ -8,9 +8,9 @@ export async function getProfile(userNumber) { {}, { name: `${member.name.firstname} ${member.name.lastname}`, - defaultTroopId: member.defaultTroopId, - ageGroupId: member.ageGroupId || 35, - ageGroup: member.ageGroup || 'Sudenpennut', + defaultTroopId: member.defaul_troop_id, + ageGroupId: member.age_roupId || 4, + ageGroup: member.age_group || 'Sudenpennut', language: 'fi', troops: member.troops, isLeader: member.isLeader || false, @@ -18,5 +18,6 @@ export async function getProfile(userNumber) { } ) + console.log('PROFILE: ', profile) return profile }