fix(medusa, admin-ui): Add deleted_at to Return Reason unique constraint (#4834)
* Update return reason create to upsert * Create strange-wombats-invite.md * Revert upsert, make value index only apply on non-deleted entities
This commit is contained in:
7
.changeset/strange-wombats-invite.md
Normal file
7
.changeset/strange-wombats-invite.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/admin-ui": patch
|
||||
"@medusajs/admin": patch
|
||||
---
|
||||
|
||||
fix(medusa, admin-ui): Allow soft-deleted return reason restoration
|
||||
@@ -36,27 +36,22 @@ const CreateReturnReasonModal = ({
|
||||
},
|
||||
})
|
||||
const notification = useNotification()
|
||||
const { mutate, isLoading } = useAdminCreateReturnReason()
|
||||
const { mutateAsync, isLoading } = useAdminCreateReturnReason()
|
||||
|
||||
const onCreate = (data: CreateReturnReasonFormData) => {
|
||||
mutate(
|
||||
{
|
||||
const onCreate = async (data: CreateReturnReasonFormData) => {
|
||||
try {
|
||||
await mutateAsync({
|
||||
...data,
|
||||
description: data.description || undefined,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
notification("Success", "Created a new return reason", "success")
|
||||
},
|
||||
onError: () => {
|
||||
notification(
|
||||
"Error",
|
||||
"Cant create a Return reason with an existing code",
|
||||
"error"
|
||||
)
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
notification("Success", "Created a new return reason", "success")
|
||||
} catch {
|
||||
notification(
|
||||
"Error",
|
||||
"Cannot create a return reason with an existing value",
|
||||
"error"
|
||||
)
|
||||
}
|
||||
handleClose()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class UpdateReturnReasonIndex1692870898423
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`DROP INDEX IF EXISTS "IDX_00605f9d662c06b81c1b60ce24";`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_return_reason_value" ON "return_reason" ("value") WHERE deleted_at IS NULL;`
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_return_reason_value";`)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_00605f9d662c06b81c1b60ce24" ON "return_reason" ("value") `
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import { generateEntityId } from "../utils/generate-entity-id"
|
||||
|
||||
@Entity()
|
||||
export class ReturnReason extends SoftDeletableEntity {
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NULL" })
|
||||
@Column()
|
||||
value: string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user