fix(customer): Unique constraint on customer email (#7439)
**What** Prevent creating multiple customers with the same email
This commit is contained in:
committed by
GitHub
parent
066fd3c3d2
commit
77d72c5791
@@ -7,6 +7,17 @@ import {
|
||||
} from "@mikro-orm/core"
|
||||
import { MedusaError, upperCaseFirst } from "../../common"
|
||||
|
||||
function parseValue(value: string) {
|
||||
switch (value) {
|
||||
case "t":
|
||||
return "true"
|
||||
case "f":
|
||||
return "false"
|
||||
default:
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
export const dbErrorMapper = (err: Error) => {
|
||||
if (err instanceof NotFoundError) {
|
||||
throw new MedusaError(MedusaError.Types.NOT_FOUND, err.message)
|
||||
@@ -24,8 +35,8 @@ export const dbErrorMapper = (err: Error) => {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`${upperCaseFirst(info.table.split("_").join(" "))} with ${info.keys
|
||||
.map((key, i) => `${key}: ${info.values[i]}`)
|
||||
.join(", ")} already exists.`
|
||||
.map((key, i) => `${key}: ${parseValue(info.values[i])}`)
|
||||
.join(", ")}, already exists.`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -864,7 +864,7 @@ describe("mikroOrmRepository", () => {
|
||||
.upsertWithReplace([entity3])
|
||||
.catch((e) => e.message)
|
||||
|
||||
expect(err).toEqual("Entity3 with title: en3 already exists.")
|
||||
expect(err).toEqual("Entity3 with title: en3, already exists.")
|
||||
})
|
||||
|
||||
it("should map NotNullConstraintViolationException MedusaError on upsertWithReplace", async () => {
|
||||
|
||||
Reference in New Issue
Block a user