Skip to content

Commit

Permalink
path: addToUser
Browse files Browse the repository at this point in the history
  • Loading branch information
Celesca committed Nov 24, 2024
1 parent 2721186 commit e9f22e7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/controllers/personalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,42 @@ export const personalController = new Elysia({ prefix: "/personal" })
personalType: t.String(),
personalTypeDetail: t.String(),
}),
})

// Add the personal type to the user
.post('/addToUser', async ({ body, error }) => {
const { userID, personalTypeID } = body;

// Check if the user exists
const user = await prisma.user.findUnique({
where: { UserID: userID },
});

if (!user) {
return error(404, "User not found");
}

// Check if the personal type exists
const personalType = await prisma.personalType.findUnique({
where: { PersonalTypeID: personalTypeID },
});

if (!personalType) {
return error(404, "Personal type not found");
}

// Add the personal type to the user
const newPersonal = await prisma.user.update({
where: { UserID: userID },
data: {
PersonalTypeID: personalTypeID,
},
});

return newPersonal;
}, {
body: t.Object({
userID: t.String(),
personalTypeID: t.Number(),
}),
})

0 comments on commit e9f22e7

Please sign in to comment.