pr review fixes
This commit is contained in:
@@ -67,9 +67,6 @@ export default async (req, res) => {
|
||||
usage_limit: Validator.number()
|
||||
.positive()
|
||||
.optional(),
|
||||
usage_count: Validator.number()
|
||||
.positive()
|
||||
.optional(),
|
||||
})
|
||||
.required(),
|
||||
is_disabled: Validator.boolean().default(false),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class discountUsageCount1615912118791 implements MigrationInterface {
|
||||
name = "discountUsageCount1615912118791"
|
||||
export class discountUsageCount1615970124120 implements MigrationInterface {
|
||||
name = "discountUsageCount1615970124120"
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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 })
|
||||
usage_limit: number
|
||||
|
||||
@Column({ nullable: true })
|
||||
@Column({ default: 0 })
|
||||
usage_count: number
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
|
||||
@@ -85,10 +85,21 @@ class DiscountService extends BaseService {
|
||||
valid_for: Validator.array().optional(),
|
||||
usage_limit: Validator.number()
|
||||
.positive()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
usage_count: Validator.number()
|
||||
.positive()
|
||||
.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)
|
||||
|
||||
@@ -48,7 +48,7 @@ class OrderSubscriber {
|
||||
|
||||
await Promise.all(
|
||||
order.discounts.map(async d => {
|
||||
const usageCount = d?.usage_count || 0
|
||||
const usageCount = d.rule?.usage_count || 0
|
||||
return this.discountService_.update(d.id, {
|
||||
rule: {
|
||||
...d.rule,
|
||||
|
||||
Reference in New Issue
Block a user