fix(medusa): Resolve issue with soft-delete and unique indexes in DB (#296)
This commit is contained in:
@@ -104,6 +104,82 @@ describe("/admin/discounts", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("testing for soft-deletion + uniqueness on discount codes", () => {
|
||||
const manager = dbConnection.manager;
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
await manager.insert(DiscountRule, {
|
||||
id: "test-discount-rule",
|
||||
description: "Test discount rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
});
|
||||
await manager.insert(Discount, {
|
||||
id: "test-discount",
|
||||
code: "TESTING",
|
||||
rule_id: "test-discount-rule",
|
||||
});
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("successfully creates discount with soft-deleted discount code", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the discount
|
||||
await api
|
||||
.delete("/admin/discounts/test-discount", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
// Lets try to create a discount with same code as deleted one
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts",
|
||||
{
|
||||
code: "TESTING",
|
||||
rule: {
|
||||
description: "test",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
usage_limit: 10,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
usage_limit: 10,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /admin/discounts/:discount_id/dynamic-codes", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
|
||||
@@ -224,4 +224,208 @@ describe("/admin/products", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection);
|
||||
await adminSeeder(dbConnection);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "product_option_value"`);
|
||||
await manager.query(`DELETE FROM "product_option"`);
|
||||
await manager.query(`DELETE FROM "image"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "product_collection"`);
|
||||
await manager.query(`DELETE FROM "product_tag"`);
|
||||
await manager.query(`DELETE FROM "product_type"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("successfully deletes a product", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "test-product",
|
||||
deleted: true,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("successfully creates product with soft-deleted product handle", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the product
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.id).toEqual("test-product");
|
||||
|
||||
// Lets try to create a product with same handle as deleted one
|
||||
const payload = {
|
||||
title: "Test product",
|
||||
handle: "test-product",
|
||||
description: "test-product-description",
|
||||
type: { value: "test-type" },
|
||||
images: ["test-image.png", "test-image-2.png"],
|
||||
collection_id: "test-collection",
|
||||
tags: [{ value: "123" }, { value: "456" }],
|
||||
options: [{ title: "size" }, { title: "color" }],
|
||||
variants: [
|
||||
{
|
||||
title: "Test variant",
|
||||
inventory_quantity: 10,
|
||||
prices: [{ currency_code: "usd", amount: 100 }],
|
||||
options: [{ value: "large" }, { value: "green" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const res = await api.post("/admin/products", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.data.product.handle).toEqual("test-product");
|
||||
});
|
||||
|
||||
it("successfully deletes product collection", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the product collection
|
||||
const response = await api
|
||||
.delete("/admin/collections/test-collection", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.id).toEqual("test-collection");
|
||||
});
|
||||
|
||||
it("successfully creates soft-deleted product collection", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/collections/test-collection", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.id).toEqual("test-collection");
|
||||
|
||||
// Lets try to create a product collection with same handle as deleted one
|
||||
const payload = {
|
||||
title: "Another test collection",
|
||||
handle: "test-collection",
|
||||
};
|
||||
|
||||
const res = await api.post("/admin/collections", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.data.collection.handle).toEqual("test-collection");
|
||||
});
|
||||
|
||||
it("successfully creates soft-deleted product variant", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product/variants/test-variant", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.variant_id).toEqual("test-variant");
|
||||
|
||||
// Lets try to create a product collection with same handle as deleted one
|
||||
const payload = {
|
||||
title: "Second variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const res = await api.post(
|
||||
"/admin/products/test-product/variants",
|
||||
payload,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.data.product.variants).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
title: "Second variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ module.exports = async (connection, data = {}) => {
|
||||
|
||||
const coll = manager.create(ProductCollection, {
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
});
|
||||
|
||||
@@ -53,6 +54,7 @@ module.exports = async (connection, data = {}) => {
|
||||
|
||||
const p = manager.create(Product, {
|
||||
id: "test-product",
|
||||
handle: "test-product",
|
||||
title: "Test product",
|
||||
profile_id: defaultProfile.id,
|
||||
description: "test-product-description",
|
||||
@@ -73,6 +75,10 @@ module.exports = async (connection, data = {}) => {
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
title: "Test variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
product_id: "test-product",
|
||||
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
|
||||
options: [{ id: "test-variant-option", value: "Default variant" }],
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.28-dev-1624965921528",
|
||||
"medusa-interfaces": "1.1.16-dev-1624965921528",
|
||||
"@medusajs/medusa": "1.1.28-dev-1624556551881",
|
||||
"medusa-interfaces": "1.1.16-dev-1624556551881",
|
||||
"typeorm": "^0.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "1.1.9-dev-1624965921528",
|
||||
"babel-preset-medusa-package": "1.1.9-dev-1624556551881",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1215,10 +1215,10 @@
|
||||
"@types/yargs" "^15.0.0"
|
||||
chalk "^4.0.0"
|
||||
|
||||
"@medusajs/medusa@1.1.28-dev-1624965921528":
|
||||
version "1.1.28-dev-1624965921528"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.28-dev-1624965921528.tgz#f01db1e56c0dc98e02b64d197ca7df7f8041e5a1"
|
||||
integrity sha512-SBD+fe1neJSJ0EF1oZGsnspB1aU59+qhqxjMAnWung2VJ0VIcraT0cQLkKgsED2XCTkqJQwOYK7X1AW+fZYecg==
|
||||
"@medusajs/medusa@1.1.28-dev-1624556551881":
|
||||
version "1.1.28-dev-1624556551881"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.28-dev-1624556551881.tgz#263dac3aae36b656899dde61910e170e20647a1d"
|
||||
integrity sha512-v6Rry8J7/z99dhn7uIWSt/IeFQ3o+O3zmdN1aYejLz2q0NWXdT9eSlicEEoznHFd/4EEZa1BYYqR4U1FqmGgUw==
|
||||
dependencies:
|
||||
"@hapi/joi" "^16.1.8"
|
||||
"@types/lodash" "^4.14.168"
|
||||
@@ -1239,8 +1239,8 @@
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
jsonwebtoken "^8.5.1"
|
||||
medusa-core-utils "1.1.15-dev-1624965921528"
|
||||
medusa-test-utils "1.1.18-dev-1624965921528"
|
||||
medusa-core-utils "1.1.15-dev-1624556551881"
|
||||
medusa-test-utils "1.1.18-dev-1624556551881"
|
||||
morgan "^1.9.1"
|
||||
multer "^1.4.2"
|
||||
passport "^0.4.0"
|
||||
@@ -1696,10 +1696,10 @@ babel-preset-jest@^26.6.2:
|
||||
babel-plugin-jest-hoist "^26.6.2"
|
||||
babel-preset-current-node-syntax "^1.0.0"
|
||||
|
||||
babel-preset-medusa-package@1.1.9-dev-1624965921528:
|
||||
version "1.1.9-dev-1624965921528"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.9-dev-1624965921528.tgz#e8aaba99cdf6edd524a0db0346e030782da451e0"
|
||||
integrity sha512-5waz8A/kFh9wNqr48m0pA85rEmModR+/yih4yVRJoP240ZcIoG793XCtDZPHhcy7vIxp6Ab+dv5+TnuhYIDBIQ==
|
||||
babel-preset-medusa-package@1.1.9-dev-1624556551881:
|
||||
version "1.1.9-dev-1624556551881"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.9-dev-1624556551881.tgz#02631e1bc7ae0c6b28b6172d44f144dcc9ec9e0f"
|
||||
integrity sha512-gbenDSqRQm0IoI4vqgwvL9DMsR/b3UgGu2ZzpTXZeM070wH4LsBeckNpXf0k5douOUIpqvhk5xhyIYBprZz5LQ==
|
||||
dependencies:
|
||||
"@babel/plugin-proposal-class-properties" "^7.12.1"
|
||||
"@babel/plugin-proposal-decorators" "^7.12.1"
|
||||
@@ -4150,28 +4150,28 @@ media-typer@0.3.0:
|
||||
resolved "http://localhost:4873/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
||||
|
||||
medusa-core-utils@1.1.15-dev-1624965921528:
|
||||
version "1.1.15-dev-1624965921528"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.15-dev-1624965921528.tgz#7da932df2423e9656ed4e800971fbc00d5124b3c"
|
||||
integrity sha512-2iuVowwgGfygjDGW1NwR2ubtG/TFVVqBiNECn+N7/rNajN2DIIa863bVTd9qZAy6uFX6CrT1gjBqQNdPUsTitA==
|
||||
medusa-core-utils@1.1.15-dev-1624556551881:
|
||||
version "1.1.15-dev-1624556551881"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.15-dev-1624556551881.tgz#3cd5ac7a40ecd870d6cf22873ddbcfe362b84215"
|
||||
integrity sha512-KicW2VFP0nKNozJ/XvBQ7pGcML50cnj0IWThGBiak+S9+6+DBHPKmUVOWMwO4ocQgXUY9VV+ZjUzXYxKUrM0fA==
|
||||
dependencies:
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
|
||||
medusa-interfaces@1.1.16-dev-1624965921528:
|
||||
version "1.1.16-dev-1624965921528"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.16-dev-1624965921528.tgz#4fa2e25bba5ecb1bdcdaa8da788e204435c53e69"
|
||||
integrity sha512-WKSfrCEAbkJ4I1NetiRULRURCmGY59Mue16cT7RZ2yb8U1Wnskui0OsG/EaS5JdV9HZq/iViEgzWIRTALNT1EQ==
|
||||
medusa-interfaces@1.1.16-dev-1624556551881:
|
||||
version "1.1.16-dev-1624556551881"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.16-dev-1624556551881.tgz#4644df88d49dac014a8c1c7170efa5fff45df15e"
|
||||
integrity sha512-oWLD8qDGhByty3mIWnv4cIgdJ0sWDDy1/Yz4rL5fNhENtRhwzH0vvw5rEBvpFAFF5TZuwMap+Co61ldRyN6xBA==
|
||||
dependencies:
|
||||
medusa-core-utils "1.1.15-dev-1624965921528"
|
||||
medusa-core-utils "1.1.15-dev-1624556551881"
|
||||
|
||||
medusa-test-utils@1.1.18-dev-1624965921528:
|
||||
version "1.1.18-dev-1624965921528"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.18-dev-1624965921528.tgz#d94926109b349b62d5deb6329f0d46f5f5e953eb"
|
||||
integrity sha512-P28P5pBV6HBXNiNUQbYgSaOrHcnq7GCNAIFuBmLYqDiZnNL8zfU+IxcWo3+xucXyLfX3flGCirpO4g7h65JGWQ==
|
||||
medusa-test-utils@1.1.18-dev-1624556551881:
|
||||
version "1.1.18-dev-1624556551881"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.18-dev-1624556551881.tgz#fb2b2cd25755251c37545d1cfe725eecb96288af"
|
||||
integrity sha512-lJyEvvSxM5mv+mxePSqt3Fcj/g+mkwSsN+NnURhiEG1vVi9s6t/kZf55mSu+IRqXQhs/FQMHzkgCHzUgmAjMqg==
|
||||
dependencies:
|
||||
"@babel/plugin-transform-classes" "^7.9.5"
|
||||
medusa-core-utils "1.1.15-dev-1624965921528"
|
||||
medusa-core-utils "1.1.15-dev-1624556551881"
|
||||
randomatic "^3.1.1"
|
||||
|
||||
merge-descriptors@1.0.1:
|
||||
|
||||
@@ -4,28 +4,16 @@ export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface {
|
||||
name = "gcRemoveUniqueOrder1624287602631"
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
|
||||
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`)
|
||||
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||
|
||||
export class softDeletingUniqueConstraints1624610325746 implements MigrationInterface {
|
||||
name = 'softDeletingUniqueConstraints1624610325746'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_6910923cb678fd6e99011a21cc"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_db7355f7bd36c547c8a4f539e5"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_087926f6fec32903be3c8eedfa"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_f4dc2c0888b66d547c175f090e"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_9db95c4b71f632fc93ecbc3d8b"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_7124082c8846a06a857cca386c"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_a0a3f124dc5b167622217fee02"`);
|
||||
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e08af711f3493df1e921c4c9ef" ON "product_collection" ("handle") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_77c4073c30ea7793f484750529" ON "product" ("handle") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ae3e22c67d7c7a969a363533c0" ON "discount" ("code") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0683952543d7d3f4fffc427034" ON "product_variant" ("sku") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_410649600ce31c10c4b667ca10" ON "product_variant" ("barcode") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_5248fda27b9f16ef818604bb6f" ON "product_variant" ("ean") WHERE deleted_at IS NOT NULL`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_832f86daf8103491d634a967da" ON "product_variant" ("upc") WHERE deleted_at IS NOT NULL`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_ae3e22c67d7c7a969a363533c0"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_77c4073c30ea7793f484750529"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_e08af711f3493df1e921c4c9ef"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_832f86daf8103491d634a967da"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_5248fda27b9f16ef818604bb6f"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_410649600ce31c10c4b667ca10"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_0683952543d7d3f4fffc427034"`);
|
||||
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_087926f6fec32903be3c8eedfa" ON "discount" ("code") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_db7355f7bd36c547c8a4f539e5" ON "product" ("handle") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_6910923cb678fd6e99011a21cc" ON "product_collection" ("handle") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a0a3f124dc5b167622217fee02" ON "product_variant" ("upc") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_7124082c8846a06a857cca386c" ON "product_variant" ("ean") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_9db95c4b71f632fc93ecbc3d8b" ON "product_variant" ("barcode") `);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f4dc2c0888b66d547c175f090e" ON "product_variant" ("sku") `);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ export class Discount {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
@Column()
|
||||
code: string
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export class ProductCollection {
|
||||
@Column()
|
||||
title: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
@Column({ nullable: true })
|
||||
handle: string
|
||||
|
||||
|
||||
@@ -47,19 +47,19 @@ export class ProductVariant {
|
||||
prices: MoneyAmount[]
|
||||
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
sku: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
barcode: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
ean: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
upc: string
|
||||
|
||||
@Column({ type: "int" })
|
||||
|
||||
@@ -39,7 +39,7 @@ export class Product {
|
||||
@Column({ nullable: true })
|
||||
description: string
|
||||
|
||||
@Index({ unique: true })
|
||||
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
|
||||
@Column({ nullable: true })
|
||||
handle: string
|
||||
|
||||
|
||||
@@ -135,8 +135,8 @@ describe("ProductCollectionService", () => {
|
||||
it("successfully removes a product collection", async () => {
|
||||
await productCollectionService.delete(IdMap.getId("bathrobe"))
|
||||
|
||||
expect(productCollectionRepository.remove).toHaveBeenCalledTimes(1)
|
||||
expect(productCollectionRepository.remove).toHaveBeenCalledWith({
|
||||
expect(productCollectionRepository.softRemove).toHaveBeenCalledTimes(1)
|
||||
expect(productCollectionRepository.softRemove).toHaveBeenCalledWith({
|
||||
id: IdMap.getId("bathrobe"),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -129,7 +129,7 @@ class ProductCollectionService extends BaseService {
|
||||
|
||||
if (!collection) return Promise.resolve()
|
||||
|
||||
await productCollectionRepo.remove(collection)
|
||||
await productCollectionRepo.softRemove(collection)
|
||||
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user