diff --git a/packages/medusa/src/api/routes/admin/orders/create-claim.js b/packages/medusa/src/api/routes/admin/orders/create-claim.js index ce77c090a4..5e0e207f58 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-claim.js +++ b/packages/medusa/src/api/routes/admin/orders/create-claim.js @@ -91,6 +91,9 @@ import { defaultRelations, defaultFields } from "./" * refund_amount: * description: The amount to refund the Customer when the Claim type is `refund`. * type: integer + * no_notification: + * description: If set to true no notification will be send related to this Claim. + * type: boolean * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object @@ -155,6 +158,7 @@ export default async (req, res) => { .integer() .optional(), shipping_address: Validator.object().optional(), + no_notification: Validator.boolean().optional(), metadata: Validator.object().optional(), }) @@ -212,6 +216,7 @@ export default async (req, res) => { return_shipping: value.return_shipping, additional_items: value.additional_items, shipping_methods: value.shipping_methods, + no_notification: value.no_notification, metadata: value.metadata, }) diff --git a/packages/medusa/src/api/routes/admin/orders/create-swap.js b/packages/medusa/src/api/routes/admin/orders/create-swap.js index f81c02b35f..648aed1aab 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-swap.js +++ b/packages/medusa/src/api/routes/admin/orders/create-swap.js @@ -46,7 +46,7 @@ import { defaultFields, defaultRelations } from "./" * description: The quantity of the Product Variant to ship. * type: integer * no_notification: - * description: If set to true no notification will be send. + * description: If set to true no notification will be send related to this Swap. * type: boolean * tags: * - Order @@ -138,7 +138,7 @@ export default async (req, res) => { value.return_items, value.additional_items, value.return_shipping, - no_notification, + value.no_notification, { idempotency_key: idempotencyKey.idempotency_key } ) diff --git a/packages/medusa/src/api/routes/admin/orders/index.js b/packages/medusa/src/api/routes/admin/orders/index.js index 98e72e599c..29ce86e109 100644 --- a/packages/medusa/src/api/routes/admin/orders/index.js +++ b/packages/medusa/src/api/routes/admin/orders/index.js @@ -237,6 +237,7 @@ export const defaultFields = [ "total", "paid_total", "refundable_amount", + "no_notification", ] export const allowedFields = [ @@ -265,6 +266,7 @@ export const allowedFields = [ "total", "paid_total", "refundable_amount", + "no_notification", ] export const allowedRelations = [ diff --git a/packages/medusa/src/api/routes/admin/orders/update-claim.js b/packages/medusa/src/api/routes/admin/orders/update-claim.js index ffbd4eae46..90346be45c 100644 --- a/packages/medusa/src/api/routes/admin/orders/update-claim.js +++ b/packages/medusa/src/api/routes/admin/orders/update-claim.js @@ -62,6 +62,9 @@ import { defaultRelations, defaultFields } from "./" * price: * description: The price to charge for the Shipping Method * type: integer + * no_notification: + * description: If set to true no notification will be send related to this Swap. + * type: boolean * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object @@ -106,6 +109,7 @@ export default async (req, res) => { .optional(), }) .optional(), + no_notification: Validator.boolean().optional(), metadata: Validator.object().optional(), }) diff --git a/packages/medusa/src/api/routes/admin/orders/update-order.js b/packages/medusa/src/api/routes/admin/orders/update-order.js index 37e321024b..ba1ed0bf8c 100644 --- a/packages/medusa/src/api/routes/admin/orders/update-order.js +++ b/packages/medusa/src/api/routes/admin/orders/update-order.js @@ -22,7 +22,7 @@ export default async (req, res) => { price: Validator.number(), data: Validator.object(), items: Validator.array(), - }), + }) }) const { value, error } = schema.validate(req.body) diff --git a/packages/medusa/src/migrations/1623164855464-no_notifications.ts b/packages/medusa/src/migrations/1623164855464-no_notifications.ts new file mode 100644 index 0000000000..e24bbbff9a --- /dev/null +++ b/packages/medusa/src/migrations/1623164855464-no_notifications.ts @@ -0,0 +1,134 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class noNotifications1623164855464 implements MigrationInterface { + name = 'noNotifications1623164855464' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "draft_order" DROP CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6"`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" DROP CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0"`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" DROP CONSTRAINT "FK_8aaa78ba90d3802edac317df869"`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" DROP CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf"`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" DROP CONSTRAINT "FK_c556e14eff4d6f03db593df955e"`); + await queryRunner.query(`ALTER TABLE "product_images" DROP CONSTRAINT "FK_2212515ba306c79f42c46a99db7"`); + await queryRunner.query(`ALTER TABLE "product_images" DROP CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068"`); + await queryRunner.query(`ALTER TABLE "product_tags" DROP CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4"`); + await queryRunner.query(`ALTER TABLE "product_tags" DROP CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e"`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" DROP CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b"`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" DROP CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5"`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" DROP CONSTRAINT "FK_be66106a673b88a81c603abe7eb"`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" DROP CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a"`); + await queryRunner.query(`ALTER TABLE "discount_regions" DROP CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec"`); + await queryRunner.query(`ALTER TABLE "discount_regions" DROP CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff"`); + await queryRunner.query(`ALTER TABLE "cart_discounts" DROP CONSTRAINT "FK_8df75ef4f35f217768dc1135458"`); + await queryRunner.query(`ALTER TABLE "cart_discounts" DROP CONSTRAINT "FK_6680319ebe1f46d18f106191d59"`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" DROP CONSTRAINT "FK_0fb38b6d167793192bc126d835e"`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" DROP CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea"`); + await queryRunner.query(`ALTER TABLE "order_discounts" DROP CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16"`); + await queryRunner.query(`ALTER TABLE "order_discounts" DROP CONSTRAINT "FK_e7b488cebe333f449398769b2cc"`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" DROP CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3"`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" DROP CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2"`); + await queryRunner.query(`ALTER TABLE "store_currencies" DROP CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60"`); + await queryRunner.query(`ALTER TABLE "store_currencies" DROP CONSTRAINT "FK_b4f4b63d1736689b7008980394c"`); + await queryRunner.query(`ALTER TABLE "return" ADD "no_notification" boolean NOT NULL`); + await queryRunner.query(`ALTER TABLE "claim_order" ADD "no_notification" boolean NOT NULL`); + await queryRunner.query(`ALTER TABLE "swap" ADD "no_notification" boolean NOT NULL`); + await queryRunner.query(`ALTER TABLE "order" ADD "no_notification" boolean NOT NULL`); + await queryRunner.query(`ALTER TABLE "product_option" DROP CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6"`); + await queryRunner.query(`ALTER TABLE "product_option" ALTER COLUMN "product_id" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "discount" ALTER COLUMN "starts_at" SET DEFAULT now()`); + await queryRunner.query(`ALTER TABLE "fulfillment" DROP CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44"`); + await queryRunner.query(`ALTER TABLE "fulfillment" ALTER COLUMN "provider_id" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "product_option" ADD CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "fulfillment" ADD CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "draft_order" ADD CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" ADD CONSTRAINT "FK_8aaa78ba90d3802edac317df869" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" ADD CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0" FOREIGN KEY ("provider_id") REFERENCES "payment_provider"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" ADD CONSTRAINT "FK_c556e14eff4d6f03db593df955e" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" ADD CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "product_images" ADD CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "product_images" ADD CONSTRAINT "FK_2212515ba306c79f42c46a99db7" FOREIGN KEY ("image_id") REFERENCES "image"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "product_tags" ADD CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "product_tags" ADD CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4" FOREIGN KEY ("product_tag_id") REFERENCES "product_tag"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" ADD CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5" FOREIGN KEY ("item_id") REFERENCES "claim_item"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" ADD CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b" FOREIGN KEY ("tag_id") REFERENCES "claim_tag"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" ADD CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a" FOREIGN KEY ("discount_rule_id") REFERENCES "discount_rule"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" ADD CONSTRAINT "FK_be66106a673b88a81c603abe7eb" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "discount_regions" ADD CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "discount_regions" ADD CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "cart_discounts" ADD CONSTRAINT "FK_6680319ebe1f46d18f106191d59" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "cart_discounts" ADD CONSTRAINT "FK_8df75ef4f35f217768dc1135458" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" ADD CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" ADD CONSTRAINT "FK_0fb38b6d167793192bc126d835e" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "order_discounts" ADD CONSTRAINT "FK_e7b488cebe333f449398769b2cc" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "order_discounts" ADD CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" ADD CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" ADD CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "store_currencies" ADD CONSTRAINT "FK_b4f4b63d1736689b7008980394c" FOREIGN KEY ("store_id") REFERENCES "store"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "store_currencies" ADD CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE CASCADE ON UPDATE CASCADE`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "store_currencies" DROP CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60"`); + await queryRunner.query(`ALTER TABLE "store_currencies" DROP CONSTRAINT "FK_b4f4b63d1736689b7008980394c"`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" DROP CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3"`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" DROP CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2"`); + await queryRunner.query(`ALTER TABLE "order_discounts" DROP CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16"`); + await queryRunner.query(`ALTER TABLE "order_discounts" DROP CONSTRAINT "FK_e7b488cebe333f449398769b2cc"`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" DROP CONSTRAINT "FK_0fb38b6d167793192bc126d835e"`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" DROP CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea"`); + await queryRunner.query(`ALTER TABLE "cart_discounts" DROP CONSTRAINT "FK_8df75ef4f35f217768dc1135458"`); + await queryRunner.query(`ALTER TABLE "cart_discounts" DROP CONSTRAINT "FK_6680319ebe1f46d18f106191d59"`); + await queryRunner.query(`ALTER TABLE "discount_regions" DROP CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec"`); + await queryRunner.query(`ALTER TABLE "discount_regions" DROP CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff"`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" DROP CONSTRAINT "FK_be66106a673b88a81c603abe7eb"`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" DROP CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a"`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" DROP CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b"`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" DROP CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5"`); + await queryRunner.query(`ALTER TABLE "product_tags" DROP CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4"`); + await queryRunner.query(`ALTER TABLE "product_tags" DROP CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e"`); + await queryRunner.query(`ALTER TABLE "product_images" DROP CONSTRAINT "FK_2212515ba306c79f42c46a99db7"`); + await queryRunner.query(`ALTER TABLE "product_images" DROP CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068"`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" DROP CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf"`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" DROP CONSTRAINT "FK_c556e14eff4d6f03db593df955e"`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" DROP CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0"`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" DROP CONSTRAINT "FK_8aaa78ba90d3802edac317df869"`); + await queryRunner.query(`ALTER TABLE "draft_order" DROP CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6"`); + await queryRunner.query(`ALTER TABLE "fulfillment" DROP CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44"`); + await queryRunner.query(`ALTER TABLE "product_option" DROP CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6"`); + await queryRunner.query(`ALTER TABLE "fulfillment" ALTER COLUMN "provider_id" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "fulfillment" ADD CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "discount" ALTER COLUMN "starts_at" SET DEFAULT CURRENT_TIMESTAMP`); + await queryRunner.query(`ALTER TABLE "product_option" ALTER COLUMN "product_id" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "product_option" ADD CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "order" DROP COLUMN "no_notification"`); + await queryRunner.query(`ALTER TABLE "swap" DROP COLUMN "no_notification"`); + await queryRunner.query(`ALTER TABLE "claim_order" DROP COLUMN "no_notification"`); + await queryRunner.query(`ALTER TABLE "return" DROP COLUMN "no_notification"`); + await queryRunner.query(`ALTER TABLE "store_currencies" ADD CONSTRAINT "FK_b4f4b63d1736689b7008980394c" FOREIGN KEY ("store_id") REFERENCES "store"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "store_currencies" ADD CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" ADD CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "order_gift_cards" ADD CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "order_discounts" ADD CONSTRAINT "FK_e7b488cebe333f449398769b2cc" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "order_discounts" ADD CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" ADD CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "cart_gift_cards" ADD CONSTRAINT "FK_0fb38b6d167793192bc126d835e" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "cart_discounts" ADD CONSTRAINT "FK_6680319ebe1f46d18f106191d59" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "cart_discounts" ADD CONSTRAINT "FK_8df75ef4f35f217768dc1135458" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "discount_regions" ADD CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "discount_regions" ADD CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" ADD CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a" FOREIGN KEY ("discount_rule_id") REFERENCES "discount_rule"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "discount_rule_products" ADD CONSTRAINT "FK_be66106a673b88a81c603abe7eb" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" ADD CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5" FOREIGN KEY ("item_id") REFERENCES "claim_item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "claim_item_tags" ADD CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b" FOREIGN KEY ("tag_id") REFERENCES "claim_tag"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "product_tags" ADD CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "product_tags" ADD CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4" FOREIGN KEY ("product_tag_id") REFERENCES "product_tag"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "product_images" ADD CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "product_images" ADD CONSTRAINT "FK_2212515ba306c79f42c46a99db7" FOREIGN KEY ("image_id") REFERENCES "image"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" ADD CONSTRAINT "FK_c556e14eff4d6f03db593df955e" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" ADD CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" ADD CONSTRAINT "FK_8aaa78ba90d3802edac317df869" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "region_payment_providers" ADD CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0" FOREIGN KEY ("provider_id") REFERENCES "payment_provider"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "draft_order" ADD CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +} diff --git a/packages/medusa/src/models/claim-order.ts b/packages/medusa/src/models/claim-order.ts index dea06419f1..91ab66b450 100644 --- a/packages/medusa/src/models/claim-order.ts +++ b/packages/medusa/src/models/claim-order.ts @@ -134,7 +134,7 @@ export class ClaimOrder { @DeleteDateColumn({ type: "timestamptz" }) deleted_at: Date - @Column({ type: "boolean"}) + @Column({ type: "boolean", nullable: true}) no_notification: Boolean @Column({ type: "jsonb", nullable: true }) diff --git a/packages/medusa/src/models/order.ts b/packages/medusa/src/models/order.ts index 95aad02d1d..10258270d9 100644 --- a/packages/medusa/src/models/order.ts +++ b/packages/medusa/src/models/order.ts @@ -245,7 +245,7 @@ export class Order { @Column({ type: "jsonb", nullable: true }) metadata: any - @Column({ type: "boolean"}) + @Column({ type: "boolean", nullable: true}) no_notification: Boolean @Column({ nullable: true }) diff --git a/packages/medusa/src/models/return.ts b/packages/medusa/src/models/return.ts index b3bdc6b8bf..98a52122b9 100644 --- a/packages/medusa/src/models/return.ts +++ b/packages/medusa/src/models/return.ts @@ -99,7 +99,7 @@ export class Return { @UpdateDateColumn({ type: "timestamptz" }) updated_at: Date - @Column({ type: "boolean"}) + @Column({ type: "boolean", nullable: true}) no_notification: Boolean @Column({ type: "jsonb", nullable: true }) diff --git a/packages/medusa/src/models/swap.ts b/packages/medusa/src/models/swap.ts index 37708b6b94..e0c173c1ba 100644 --- a/packages/medusa/src/models/swap.ts +++ b/packages/medusa/src/models/swap.ts @@ -130,7 +130,7 @@ export class Swap { @DeleteDateColumn({ type: "timestamptz" }) deleted_at: Date - @Column({ type: "boolean"}) + @Column({ type: "boolean", nullable: true}) no_notification: Boolean @Column({ type: "jsonb", nullable: true }) diff --git a/packages/medusa/src/services/claim.js b/packages/medusa/src/services/claim.js index 758586815b..18ed345134 100644 --- a/packages/medusa/src/services/claim.js +++ b/packages/medusa/src/services/claim.js @@ -149,6 +149,7 @@ class ClaimService extends BaseService { .withTransaction(manager) .emit(ClaimService.Events.UPDATED, { id: claim.id, + no_notification: claim.no_notification }) return claim @@ -174,6 +175,7 @@ class ClaimService extends BaseService { refund_amount, shipping_address, shipping_address_id, + no_notification, ...rest } = data @@ -233,6 +235,8 @@ class ClaimService extends BaseService { ) ) + const evaluatedNoNotification = noNotification ? noNotification : order.no_notification + const created = claimRepo.create({ shipping_address_id: addressId, payment_status: type === "refund" ? "not_refunded" : "na", @@ -241,6 +245,7 @@ class ClaimService extends BaseService { type, additional_items: newItems, order_id: order.id, + no_notification: evaluatedNoNotification }) const result = await claimRepo.save(created) @@ -288,6 +293,7 @@ class ClaimService extends BaseService { .withTransaction(manager) .emit(ClaimService.Events.CREATED, { id: result.id, + no_notification: claim.no_notification }) return result @@ -395,6 +401,7 @@ class ClaimService extends BaseService { .emit(ClaimService.Events.FULFILLMENT_CREATED, { id: id, fulfillment_id: fulfillment.id, + no_notification: claim.no_notification }) } @@ -430,6 +437,7 @@ class ClaimService extends BaseService { .withTransaction(manager) .emit(ClaimService.Events.REFUND_PROCESSED, { id, + no_notification: claim.no_notification }) return result @@ -474,6 +482,7 @@ class ClaimService extends BaseService { .emit(ClaimService.Events.SHIPMENT_CREATED, { id, fulfillment_id: shipment.id, + no_notification: claim.no_notification }) return result @@ -524,6 +533,7 @@ class ClaimService extends BaseService { .withTransaction(manager) .emit(ClaimService.Events.CANCELED, { id: result.id, + no_notification: claim.no_notification }) return result diff --git a/packages/medusa/src/services/order.js b/packages/medusa/src/services/order.js index 6444a444ff..5fe6fea0ac 100644 --- a/packages/medusa/src/services/order.js +++ b/packages/medusa/src/services/order.js @@ -405,6 +405,7 @@ class OrderService extends BaseService { OrderService.Events.COMPLETED, { id: orderId, + no_notification: order.no_notification } ) @@ -549,7 +550,7 @@ class OrderService extends BaseService { await this.eventBus_ .withTransaction(manager) .emit(OrderService.Events.PLACED, { - id: result.id, + id: result.id }) return result @@ -611,6 +612,7 @@ class OrderService extends BaseService { .emit(OrderService.Events.SHIPMENT_CREATED, { id: orderId, fulfillment_id: shipmentRes.id, + no_notification: order.no_notification }) return result @@ -631,6 +633,7 @@ class OrderService extends BaseService { .withTransaction(manager) .emit(OrderService.Events.PLACED, { id: result.id, + no_notification: order.no_notification }) return result }) @@ -818,6 +821,7 @@ class OrderService extends BaseService { .withTransaction(manager) .emit(OrderService.Events.UPDATED, { id: orderId, + no_notification: order.no_notification }) return result }) @@ -868,6 +872,7 @@ class OrderService extends BaseService { .withTransaction(manager) .emit(OrderService.Events.CANCELED, { id: order.id, + no_notification: order.no_notification }) return result }) @@ -895,7 +900,7 @@ class OrderService extends BaseService { .emit(OrderService.Events.PAYMENT_CAPTURE_FAILED, { id: orderId, payment_id: p.id, - error: err, + error: err }) }) @@ -921,6 +926,7 @@ class OrderService extends BaseService { .withTransaction(manager) .emit(OrderService.Events.PAYMENT_CAPTURED, { id: result.id, + no_notification: order.no_notification }) } @@ -977,6 +983,7 @@ class OrderService extends BaseService { "tax_total", "gift_card_total", "total", + "no_notification" ], relations: [ "discounts", @@ -1049,6 +1056,7 @@ class OrderService extends BaseService { .emit(OrderService.Events.FULFILLMENT_CREATED, { id: orderId, fulfillment_id: fulfillment.id, + no_notification: order.no_notification }) } @@ -1107,7 +1115,7 @@ class OrderService extends BaseService { async createRefund(orderId, refundAmount, reason, note) { return this.atomicPhase_(async manager => { const order = await this.retrieve(orderId, { - select: ["refundable_amount", "total", "refunded_total"], + select: ["refundable_amount", "total", "refunded_total", "no_notification"], relations: ["payments"], }) @@ -1126,6 +1134,7 @@ class OrderService extends BaseService { this.eventBus_.emit(OrderService.Events.REFUND_CREATED, { id: result.id, refund_id: refund.id, + no_notification: order.no_notification }) return result }) @@ -1206,7 +1215,7 @@ class OrderService extends BaseService { async registerReturnReceived(orderId, receivedReturn, customRefundAmount) { return this.atomicPhase_(async manager => { const order = await this.retrieve(orderId, { - select: ["total", "refunded_total", "refundable_amount"], + select: ["total", "refunded_total", "refundable_amount", "no_notification"], relations: ["items", "returns", "payments"], }) @@ -1229,6 +1238,7 @@ class OrderService extends BaseService { .emit(OrderService.Events.RETURN_ACTION_REQUIRED, { id: result.id, return_id: receivedReturn.id, + no_notification: order.no_notification }) return result } @@ -1260,6 +1270,7 @@ class OrderService extends BaseService { .emit(OrderService.Events.ITEMS_RETURNED, { id: order.id, return_id: receivedReturn.id, + no_notification: order.no_notification }) return result }) diff --git a/packages/medusa/src/services/swap.js b/packages/medusa/src/services/swap.js index 6c7ca61ec2..07d017ee06 100644 --- a/packages/medusa/src/services/swap.js +++ b/packages/medusa/src/services/swap.js @@ -204,7 +204,9 @@ class SwapService extends BaseService { * the customer. * @param {ReturnShipping?} returnShipping - an optional shipping method for * returning the returnItems. - * @param {boolean?} noNotification - an optional flag to disable sending notification when creating swap + * @param {boolean?} noNotification - an optional flag to disable sending + * notification when creating swap. If set, it overrules the attribute inherited + * from the order. * @returns {Promise} the newly created swap. */ async create( @@ -236,6 +238,8 @@ class SwapService extends BaseService { }) ) + const evaluatedNoNotification = noNotification ? noNotification : order.noNotification + const swapRepo = manager.getCustomRepository(this.swapRepository_) const created = swapRepo.create({ ...custom, @@ -243,6 +247,7 @@ class SwapService extends BaseService { payment_status: "not_paid", order_id: order.id, additional_items: newItems, + no_notification: evaluatedNoNotification }) const result = await swapRepo.save(created) @@ -258,7 +263,7 @@ class SwapService extends BaseService { .withTransaction(manager) .emit(SwapService.Events.CREATED, { id: result.id, - no_notification: noNotification, + no_notification: evaluatedNoNotification, }) return result @@ -559,6 +564,7 @@ class SwapService extends BaseService { .withTransaction(manager) .emit(SwapService.Events.PAYMENT_COMPLETED, { id: swap.id, + no_notification: swap.no_notification }) return result @@ -750,6 +756,7 @@ class SwapService extends BaseService { .emit(SwapService.Events.SHIPMENT_CREATED, { id: swapId, fulfillment_id: shipment.id, + no_notification: swap.no_notification }) return result }) @@ -806,6 +813,7 @@ class SwapService extends BaseService { .emit(SwapService.Events.RECEIVED, { id: id, order_id: result.order_id, + no_notification: swap.no_notification }) return result