Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Create memberships manually
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Sep 3, 2020
1 parent dc67971 commit 4d070cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
27 changes: 10 additions & 17 deletions src/_staart/rest/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,16 @@ export const register = async (
groupId = domainDetails.groupId;
} catch (error) {}
}
const userId = (
await createUser({
...user,
...(groupId
? {
memberships: {
create: {
group: {
connect: { id: groupId },
},
role,
},
},
}
: {}),
})
).id;
const userId = (await createUser(user)).id;
if (groupId) {
await prisma.memberships.create({
data: {
user: { connect: { id: userId } },
group: { connect: { id: groupId } },
role,
},
});
}
let resendToken: string | undefined = undefined;
if (email) {
const newEmail = await createEmail(userId, email, !emailVerified);
Expand Down
7 changes: 0 additions & 7 deletions src/_staart/rest/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,6 @@ export const inviteMemberToGroup = async (
? (await getUserById(userId))?.name ?? "Someone"
: "Someone";
const userDetails = await getUserById(createdUserId);
await prisma.memberships.create({
data: {
user: { connect: { id: createdUserId } },
group: { connect: { id: groupId } },
role,
},
});
mail({
to: newMemberEmail,
template: Templates.INVITED_TO_TEAM,
Expand Down
2 changes: 1 addition & 1 deletion src/_staart/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { sendNewPassword } from "../rest/auth";
*/
export const createUser = async (user: usersCreateInput) => {
user.name = capitalizeFirstAndLastLetter(user.name);
user.password = user.password ? await hash(user.password, 8) : null;
user.password = user.password ? await hash(user.password, 8) : undefined;
user.profilePictureUrl =
user.profilePictureUrl ||
`https://api.adorable.io/avatars/285/${createHash("md5")
Expand Down

0 comments on commit 4d070cf

Please sign in to comment.