pr review fixes
This commit is contained in:
@@ -67,9 +67,6 @@ export default async (req, res) => {
|
|||||||
usage_limit: Validator.number()
|
usage_limit: Validator.number()
|
||||||
.positive()
|
.positive()
|
||||||
.optional(),
|
.optional(),
|
||||||
usage_count: Validator.number()
|
|
||||||
.positive()
|
|
||||||
.optional(),
|
|
||||||
})
|
})
|
||||||
.required(),
|
.required(),
|
||||||
is_disabled: Validator.boolean().default(false),
|
is_disabled: Validator.boolean().default(false),
|
||||||
|
|||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||||
|
|
||||||
export class discountUsageCount1615912118791 implements MigrationInterface {
|
export class discountUsageCount1615970124120 implements MigrationInterface {
|
||||||
name = "discountUsageCount1615912118791"
|
name = "discountUsageCount1615970124120"
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "discount_rule" ADD "usage_count" integer`
|
`ALTER TABLE "discount_rule" ADD "usage_count" integer NOT NULL DEFAULT '0'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ export class DiscountRule {
|
|||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
usage_limit: number
|
usage_limit: number
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ default: 0 })
|
||||||
usage_count: number
|
usage_count: number
|
||||||
|
|
||||||
@CreateDateColumn({ type: "timestamptz" })
|
@CreateDateColumn({ type: "timestamptz" })
|
||||||
|
|||||||
@@ -85,10 +85,21 @@ class DiscountService extends BaseService {
|
|||||||
valid_for: Validator.array().optional(),
|
valid_for: Validator.array().optional(),
|
||||||
usage_limit: Validator.number()
|
usage_limit: Validator.number()
|
||||||
.positive()
|
.positive()
|
||||||
|
.allow(null)
|
||||||
.optional(),
|
.optional(),
|
||||||
usage_count: Validator.number()
|
usage_count: Validator.number()
|
||||||
.positive()
|
.positive()
|
||||||
.optional(),
|
.optional(),
|
||||||
|
created_at: Validator.date().optional(),
|
||||||
|
updated_at: Validator.date()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
deleted_at: Validator.date()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
metadata: Validator.object()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const { value, error } = schema.validate(discountRule)
|
const { value, error } = schema.validate(discountRule)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class OrderSubscriber {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
order.discounts.map(async d => {
|
order.discounts.map(async d => {
|
||||||
const usageCount = d?.usage_count || 0
|
const usageCount = d.rule?.usage_count || 0
|
||||||
return this.discountService_.update(d.id, {
|
return this.discountService_.update(d.id, {
|
||||||
rule: {
|
rule: {
|
||||||
...d.rule,
|
...d.rule,
|
||||||
|
|||||||
Reference in New Issue
Block a user