Skip to content

Commit

Permalink
Only unique strengths are added if they are not in the profile
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardodeValle committed Jun 14, 2024
1 parent 1907b70 commit 1fffdca
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions services/rag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,27 @@ async function setUserPCP(
}

// set the strengths of the user
const strengthsArray = Array.from(newStrengthsIds);
for (const strengthId of strengthsArray) {

const oldStrengths: Set<number> = new Set();

const oldStrengthsArray = await db
.select({ skillId: skill.id })
.from(userSkill)
.where(eq(userSkill.userId, userId));

oldStrengthsArray.forEach((userStrength) => {
oldStrengths.add(userStrength.skillId as number);
});

const newStrengths = new Set<number>();

for (const id of Array.from(feedbackStrengthsIds)) {
if (!oldStrengths.has(id)) {
newStrengths.add(id);
}
}

for (const strengthId of Array.from(newStrengths)) {
await db.insert(userSkill).values({
userId: userId,
skillId: strengthId,
Expand Down

0 comments on commit 1fffdca

Please sign in to comment.