Skip to content

Commit

Permalink
Update AddSkillInput to use skillIds instead of skillId
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewquang512 committed Nov 26, 2023
1 parent ff815e7 commit 0f93e62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ IS_LOGGING=1
# For tool generatePosts
AWS_ACCESS_KEY=
AWS_SECRET_ACCESS=
AWS_BUCKET_NAME=
AWS_BUCKET_NAME=
APP_ID=
2 changes: 1 addition & 1 deletion src/Type_Definitions/User_User.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const userDefs = gql`
input AddSkillInput {
userId: ID!
skillId: String!
skillIds: [String]!
}
input CreateUserInput {
Expand Down
36 changes: 24 additions & 12 deletions src/resolvers/Mutation/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const profileMutation = {

/**
* @param {*} parent
* @param {{data: {skillId: string, userId: string}}} args
* @param {{data: {skillIds: string[], userId: string}}} args
* @param {*} info
* @returns
*/
addSkill: async (parent, args, info) => {
const { skillId, userId } = args.data;
const { skillIds, userId } = args.data;

const user = await prisma.user.findUnique({
where: {
Expand All @@ -42,29 +42,41 @@ const profileMutation = {
}
const userSkillIds = user.user_to_endorsement.map((each) => each.skillId);

if (userSkillIds.includes(skillId)) {
throw Error('User has already added this skill');
}
skillIds.forEach((id) => {
if (userSkillIds.includes(id)) {
throw Error('User has already added this skill');
}
});

return await prisma.user.update({
where: {
id: userId,
},
data: {
user_to_endorsement: {
create: {
skill: {
connect: {
id: skillId,
// create: {
// skill: {
// connect: {
// id: skillId,
// },
// },
// },
create: skillIds.map((id) => {
return {
skill: {
connect: {
id: id,
},
},
},
},
};
}),
},
},
});
},

/**
/**.map
*
* @param {*} parent
* @param {{data: {endorsementId: string, endorserUserId: string}}} args
* @param {*} info
Expand Down

0 comments on commit 0f93e62

Please sign in to comment.