Describe the bug
Can't reinsert the same customer again even after deletion (with same email address)
To Reproduce
1.Run the below mutation:
mutation {
createCustomer(input: {title: "Mr", firstName: "Okjfkgjfg", lastName: "Gdfdfdfj", phoneNumber: "+910086609277", emailAddress: "[email protected]"}, password: "b7a43ae5fd") {
id
}
}
mutation {
deleteCustomer(id: 1) {
result
}
}
Expected behavior
Step 3 should be a success but we get email address already exists error
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
@option-greek @michaelbromley i was looking at the resolver code and it seems that the delete customer applies a soft delete by setting a "deletedAt" data.
The create methods verify if the user exist by searching only by the email address as reported:
`
input.emailAddress = normalizeEmailAddress(input.emailAddress);
const customer = new Customer(input);
const existing = await this.connection.getRepository(Customer).findOne({
where: {
emailAddress: input.emailAddress,
// Should check if deleteAt is setted
},
});
if (existing) {
throw new InternalServerError(`error.email-address-must-be-unique`);
}
`
Since a soft delete is applied maybe is not considered a bug but could be a good point to start thinking how to handle such cases
More discussion is here @Enkosz : https://app.slack.com/client/TKY7HFU04/CKYMF0ZTJ/thread/CKYMF0ZTJ-1586374967.105800
@Enkosz You're right. There was actually a discussion of this in our Slack channel before this issue was created - so I'll fill in a bit of the detail here:
The Customer records are indeed soft-deleted in order to preserve data integrity (foreign key relations on Orders etc) but there is also a DB-level unique constraint on the emailAddress, which is the cause of this bug.
We discussed perhaps removing that DB constraint and implementing the "uniqueness" check in the application code, taking into account whether any duplicates are marked as deleted.