Skip to content

Commit e4a4c81

Browse files
committed
Issues-93:follow/unfollow categories
1 parent f441ffc commit e4a4c81

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/services/vanilla.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ async function manageVanillaUser (data) {
8787
await vanillaClient.updateUser(vanillaUser.userID, userData)
8888
}
8989

90-
const { body: categories } = await vanillaClient.getCategoriesByParentUrlCode(challengeId)
90+
let categories = []
91+
const { body: nestedCategories } = await vanillaClient.getCategoriesByParentUrlCode(challengeId)
92+
categories = nestedCategories
93+
94+
// Some group might not have nested categories
95+
if (categories.length === 0) {
96+
const { body: parentCategory } = await vanillaClient.getCategoryByUrlcode(challengeId)
97+
categories.push(parentCategory)
98+
}
9199

92100
// Choose action to perform
93101
switch (action) {
@@ -100,6 +108,8 @@ async function manageVanillaUser (data) {
100108
for (const category of categories) {
101109
await vanillaClient.watchCategory(category.categoryID, vanillaUser.userID, { watched: true })
102110
logger.info(`The user ${vanillaUser.name} watches categoryID=${category.categoryID} associated with challenge ${challengeId}`)
111+
await vanillaClient.followCategory(category.categoryID, { followed: true, userID: vanillaUser.userID })
112+
logger.info(`The user ${vanillaUser.name} follows categoryID=${category.categoryID} associated with challenge ${challengeId}`)
103113
}
104114
break
105115
}
@@ -108,6 +118,8 @@ async function manageVanillaUser (data) {
108118
for (const category of categories) {
109119
await vanillaClient.watchCategory(category.categoryID, vanillaUser.userID, { watched: false })
110120
logger.info(`The user ${vanillaUser.name} stopped watching categoryID=${category.categoryID} associated with challenge ${challengeId}`)
121+
await vanillaClient.followCategory(category.categoryID, { followed: false, userID: vanillaUser.userID })
122+
logger.info(`The user ${vanillaUser.name} unfollows categoryID=${category.categoryID} associated with challenge ${challengeId}`)
111123
}
112124
await vanillaClient.removeUserFromGroup(group.groupID, vanillaUser.userID)
113125
logger.info(`The user '${vanillaUser.name}' was removed from the group '${group.name}'`)

src/utils/vanilla-client.util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ function getVanillaClient () {
2424
throw err
2525
})
2626
},
27+
followCategory: (categoryId, data) => {
28+
return request.put(`${config.VANILLA.API_URL}/categories/${categoryId}/follow`)
29+
.query({ access_token: config.VANILLA.ADMIN_ACCESS_TOKEN })
30+
.send(data)
31+
},
2732
updateCategory: (categoryId, data) => {
2833
return request.patch(`${config.VANILLA.API_URL}/categories/${categoryId}`)
2934
.query({ access_token: config.VANILLA.ADMIN_ACCESS_TOKEN })

0 commit comments

Comments
 (0)