added draft-cart no_notification element to allow passing this to orders as admin

This commit is contained in:
--list committed 2021-06-15 17:29:42 +02:00
1 parent 6a0da1a423
commit 24a8b242b2
8 files changed
+30 -3

No files matched your search

@@ -31,6 +31,11 @@ class ManualFulfillmentService extends FulfillmentService {
throw Error("Manual Fulfillment service cannot calculatePrice") throw Error("Manual Fulfillment service cannot calculatePrice")
} }
createReturn() {
// No data is being sent anywhere
return Promise.resolve({})
}
createOrder() { createOrder() {
// No data is being sent anywhere // No data is being sent anywhere
return Promise.resolve({}) return Promise.resolve({})
@@ -59,6 +59,9 @@ import { defaultFields, defaultRelations } from "."
* customer_id: * customer_id:
* description: The id of the customer to add on the draft order * description: The id of the customer to add on the draft order
* type: string * type: string
* no_notification_order:
* description: An optional flag passed to the resulting order to determine use of notifications.
* type: boolean
* shipping_methods: * shipping_methods:
* description: The shipping methods for the draft order * description: The shipping methods for the draft order
* type: array * type: array
@@ -119,6 +122,7 @@ export default async (req, res) => {
}) })
.optional(), .optional(),
customer_id: Validator.string().optional(), customer_id: Validator.string().optional(),
no_notification_order: Validator.boolean().optional(),
shipping_methods: Validator.array() shipping_methods: Validator.array()
.items({ .items({
option_id: Validator.string().required(), option_id: Validator.string().required(),
@@ -35,6 +35,9 @@ import { defaultCartFields, defaultCartRelations, defaultFields } from "."
* code: * code:
* description: "The code that a Discount is identifed by." * description: "The code that a Discount is identifed by."
* type: string * type: string
* no_notification_order:
* description: "An optional flag passed to the resulting order to determine use of notifications.""
* type: boolean
* customer_id: * customer_id:
* description: "The id of the Customer to associate the Draft Order with." * description: "The id of the Customer to associate the Draft Order with."
* type: string * type: string
@@ -68,6 +71,7 @@ export default async (req, res) => {
}) })
.optional(), .optional(),
customer_id: Validator.string().optional(), customer_id: Validator.string().optional(),
no_notification_order: Validator.boolean().optional(),
}) })
const { value, error } = schema.validate(req.body) const { value, error } = schema.validate(req.body)
@@ -88,6 +92,8 @@ export default async (req, res) => {
) )
} }
await draftOrderService.update(draftOrder.id, value)
await cartService.update(draftOrder.cart_id, value) await cartService.update(draftOrder.cart_id, value)
draftOrder.cart = await cartService.retrieve(draftOrder.cart_id, { draftOrder.cart = await cartService.retrieve(draftOrder.cart_id, {
@@ -8,13 +8,16 @@ export class noNotification1623231564533 implements MigrationInterface {
await queryRunner.query(`ALTER TABLE "claim_order" ADD "no_notification" boolean`); await queryRunner.query(`ALTER TABLE "claim_order" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "swap" ADD "no_notification" boolean`); await queryRunner.query(`ALTER TABLE "swap" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "order" ADD "no_notification" boolean`); await queryRunner.query(`ALTER TABLE "order" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "draft_order" ADD "no_notification_order" boolean`);
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "draft_order" DROP COLUMN "no_notification_order"`);
await queryRunner.query(`ALTER TABLE "order" DROP COLUMN "no_notification"`); 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 "swap" DROP COLUMN "no_notification"`);
await queryRunner.query(`ALTER TABLE "claim_order" 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 "return" DROP COLUMN "no_notification"`);
} }
} }
@@ -61,6 +61,9 @@ export class DraftOrder {
@Column({ type: "timestamptz", nullable: true }) @Column({ type: "timestamptz", nullable: true })
completed_at: Date completed_at: Date
@Column({ nullable: true})
no_notification_order: boolean
@Column({ type: "jsonb", nullable: true }) @Column({ type: "jsonb", nullable: true })
metadata: any metadata: any
@@ -115,6 +118,8 @@ export class DraftOrder {
* completed_at: * completed_at:
* type: string * type: string
* format: date-time * format: date-time
* no_notification_order:
* type: boolean
* metadata: * metadata:
* type: object * type: object
* idempotency_key: * idempotency_key:
@@ -205,4 +205,5 @@ describe("DraftOrderService", () => {
} }
}) })
}) })
}) })
+3 -2
View File
@@ -248,7 +248,8 @@ class DraftOrderService extends BaseService {
) )
} }
const { items, shipping_methods, discounts, ...rest } = data const { items, shipping_methods, discounts, no_notification_order=undefined, ...rest } = data
if (discounts) { if (discounts) {
for (const { code } of discounts) { for (const { code } of discounts) {
@@ -263,7 +264,7 @@ class DraftOrderService extends BaseService {
.withTransaction(manager) .withTransaction(manager)
.create({ type: "draft_order", ...rest }) .create({ type: "draft_order", ...rest })
const draftOrder = draftOrderRepo.create({ cart_id: createdCart.id }) const draftOrder = draftOrderRepo.create({ cart_id: createdCart.id, no_notification_order})
const result = await draftOrderRepo.save(draftOrder) const result = await draftOrderRepo.save(draftOrder)
await this.eventBus_ await this.eventBus_
+3 -1
View File
@@ -507,6 +507,7 @@ class OrderService extends BaseService {
.retrieveByCartId(cart.id) .retrieveByCartId(cart.id)
toCreate.draft_order_id = draft.id toCreate.draft_order_id = draft.id
toCreate.no_notification = draft.no_notification_order
} }
const o = await orderRepo.create(toCreate) const o = await orderRepo.create(toCreate)
@@ -552,7 +553,8 @@ class OrderService extends BaseService {
await this.eventBus_ await this.eventBus_
.withTransaction(manager) .withTransaction(manager)
.emit(OrderService.Events.PLACED, { .emit(OrderService.Events.PLACED, {
id: result.id id: result.id,
no_notification: result.no_notification
}) })
return result return result