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:
1 parent
046b0dcfa5
commit
470379e631
4 files changed
+42
-19
No files matched your search
@@ -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 notification = useNotification()
|
||||||
const { mutate, isLoading } = useAdminCreateReturnReason()
|
const { mutateAsync, isLoading } = useAdminCreateReturnReason()
|
||||||
|
|
||||||
const onCreate = (data: CreateReturnReasonFormData) => {
|
const onCreate = async (data: CreateReturnReasonFormData) => {
|
||||||
mutate(
|
try {
|
||||||
{
|
await mutateAsync({
|
||||||
...data,
|
...data,
|
||||||
description: data.description || undefined,
|
description: data.description || undefined,
|
||||||
},
|
})
|
||||||
{
|
notification("Success", "Created a new return reason", "success")
|
||||||
onSuccess: () => {
|
} catch {
|
||||||
notification("Success", "Created a new return reason", "success")
|
notification(
|
||||||
},
|
"Error",
|
||||||
onError: () => {
|
"Cannot create a return reason with an existing value",
|
||||||
notification(
|
"error"
|
||||||
"Error",
|
)
|
||||||
"Cant create a Return reason with an existing code",
|
}
|
||||||
"error"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
handleClose()
|
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()
|
@Entity()
|
||||||
export class ReturnReason extends SoftDeletableEntity {
|
export class ReturnReason extends SoftDeletableEntity {
|
||||||
@Index({ unique: true })
|
@Index({ unique: true, where: "deleted_at IS NULL" })
|
||||||
@Column()
|
@Column()
|
||||||
value: string
|
value: string
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user