fix(user): check if user account with email already exist on invite create (#9243)

**What**
- when creating an invite, validate that provided email is not already used for existing user account

---

FIXES CC-513
This commit is contained in:
Frane Polić
2024-09-23 10:53:53 +02:00
committed by GitHub
parent 4a68bc1334
commit 39034e2249
2 changed files with 36 additions and 0 deletions

View File

@@ -298,6 +298,19 @@ export default class UserModuleService
data: UserTypes.CreateInviteDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<Invite[]> {
const alreadyExistingUsers = await this.listUsers({
email: data.map((d) => d.email),
})
if (alreadyExistingUsers.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`User account for following email(s) already exist: ${alreadyExistingUsers
.map((u) => u.email)
.join(", ")}`
)
}
const toCreate = data.map((invite) => {
return {
...invite,