From ced08bebd38e163dc1cfe3b4b51f2afcce887a86 Mon Sep 17 00:00:00 2001 From: Aswin Ashar Abdullah <98192542+Asharaswin@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:54:20 +0700 Subject: [PATCH] fix(SPG-572) Validasi "Belum memiliki periode season" jika menambahkan harga/item rate pada season yang belum memiliki periode season --- .../update-season-period-price.manager.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/modules/season-related/season-period/domain/usecases/managers/update-season-period-price.manager.ts b/src/modules/season-related/season-period/domain/usecases/managers/update-season-period-price.manager.ts index df723ce..878c636 100644 --- a/src/modules/season-related/season-period/domain/usecases/managers/update-season-period-price.manager.ts +++ b/src/modules/season-related/season-period/domain/usecases/managers/update-season-period-price.manager.ts @@ -1,9 +1,8 @@ -import { Injectable } from "@nestjs/common"; +import { HttpStatus, Injectable, UnprocessableEntityException } from "@nestjs/common"; import { BaseCustomManager } from "src/core/modules/domain/usecase/managers/base-custom.manager"; import { SeasonPeriodEntity } from "../../entities/season-period.entity"; import { EventTopics } from "src/core/strings/constants/interface.constants"; import { SeasonPeriodModel } from "../../../data/models/season-period.model"; -import { SeasonPeriodPriceUpdatedHandler } from "../handlers/season-period-price-updated.handler"; import { SeasonPeriodPriceUpdatedEvent } from "../../entities/event/season-period-price-updated.event"; import { OPERATION } from "src/core/strings/constants/base.constants"; @@ -11,6 +10,18 @@ import { OPERATION } from "src/core/strings/constants/base.constants"; export class UpdateSeasonPeriodPriceManager extends BaseCustomManager { async validateProcess(): Promise { + const existSeason = await this.dataService.getOneByOptions({ + where: { + season_type_id: this.data.season_period.id + } + }) + if (!existSeason) { + throw new UnprocessableEntityException({ + statusCode: HttpStatus.UNPROCESSABLE_ENTITY, + message: `Failed! There is no season type ${ this.data.season_period.name }`, + error: 'Unprocessable Entity', + }); + } return; } @@ -19,8 +30,6 @@ export class UpdateSeasonPeriodPriceManager extends BaseCustomManager { - // this.publishEvents(); - this.eventBus.publish( new SeasonPeriodPriceUpdatedEvent({ id: '', @@ -48,12 +57,7 @@ export class UpdateSeasonPeriodPriceManager extends BaseCustomManager