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

This commit is contained in:
--list
2021-06-15 17:29:42 +02:00
parent 6a0da1a423
commit 24a8b242b2
9 changed files with 31 additions and 4 deletions
@@ -31,6 +31,11 @@ class ManualFulfillmentService extends FulfillmentService {
throw Error("Manual Fulfillment service cannot calculatePrice")
}
createReturn() {
// No data is being sent anywhere
return Promise.resolve({})
}
createOrder() {
// No data is being sent anywhere
return Promise.resolve({})
@@ -59,6 +59,9 @@ import { defaultFields, defaultRelations } from "."
* customer_id:
* description: The id of the customer to add on the draft order
* type: string
* no_notification_order:
* description: An optional flag passed to the resulting order to determine use of notifications.
* type: boolean
* shipping_methods:
* description: The shipping methods for the draft order
* type: array
@@ -119,6 +122,7 @@ export default async (req, res) => {
})
.optional(),
customer_id: Validator.string().optional(),
no_notification_order: Validator.boolean().optional(),
shipping_methods: Validator.array()
.items({
option_id: Validator.string().required(),
@@ -35,6 +35,9 @@ import { defaultCartFields, defaultCartRelations, defaultFields } from "."
* code:
* description: "The code that a Discount is identifed by."
* type: string
* no_notification_order:
* description: "An optional flag passed to the resulting order to determine use of notifications.""
* type: boolean
* customer_id:
* description: "The id of the Customer to associate the Draft Order with."
* type: string
@@ -68,6 +71,7 @@ export default async (req, res) => {
})
.optional(),
customer_id: Validator.string().optional(),
no_notification_order: Validator.boolean().optional(),
})
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)
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 "swap" 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> {
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 "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"`);
}
}
+1 -1
View File
@@ -246,7 +246,7 @@ export class Cart {
@Column({ type: "jsonb", nullable: true })
context: any
// Total fields
shipping_total: number
discount_total: number
@@ -61,6 +61,9 @@ export class DraftOrder {
@Column({ type: "timestamptz", nullable: true })
completed_at: Date
@Column({ nullable: true})
no_notification_order: boolean
@Column({ type: "jsonb", nullable: true })
metadata: any
@@ -115,6 +118,8 @@ export class DraftOrder {
* completed_at:
* type: string
* format: date-time
* no_notification_order:
* type: boolean
* metadata:
* type: object
* 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) {
for (const { code } of discounts) {
@@ -263,7 +264,7 @@ class DraftOrderService extends BaseService {
.withTransaction(manager)
.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)
await this.eventBus_
+3 -1
View File
@@ -507,6 +507,7 @@ class OrderService extends BaseService {
.retrieveByCartId(cart.id)
toCreate.draft_order_id = draft.id
toCreate.no_notification = draft.no_notification_order
}
const o = await orderRepo.create(toCreate)
@@ -552,7 +553,8 @@ class OrderService extends BaseService {
await this.eventBus_
.withTransaction(manager)
.emit(OrderService.Events.PLACED, {
id: result.id
id: result.id,
no_notification: result.no_notification
})
return result