Skip to content

Commit

Permalink
[recnet-api] Follow the person who invites the user (#357)
Browse files Browse the repository at this point in the history
## Description

Follow the person who invites the user when creating an account

## Related Issue

- #356

## Notes

<!-- Other thing to say -->
N/A

## Test

1. Run local server
2. Create a user by hitting `POST /users/me`
3. Check if there is a following record that followerId = userId and
followingId = inviterId

## Screenshots (if appropriate):

TBA

## TODO

- [x] Clear `console.log` or `console.error` for debug usage
- [ ] Update the documentation `recnet-docs` if needed
  • Loading branch information
joannechen1223 authored Nov 18, 2024
2 parents 837439e + 75e5bcd commit 08d6bb1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/recnet-api/src/database/repository/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,22 @@ export default class UserRepository {
select: user.select,
});

await prisma.inviteCode.update({
const inviteCode = await prisma.inviteCode.update({
where: { code: createUserInput.inviteCode },
data: {
usedById: userInTransaction.id,
usedAt: new Date(),
},
});

// follow the person who gave the invite code
await prisma.followingRecord.create({
data: {
followedById: userInTransaction.id,
followingId: inviteCode.ownerId,
},
});

return userInTransaction;
});
}
Expand Down

0 comments on commit 08d6bb1

Please sign in to comment.