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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user