feat(SPG-837): validate delete and in active when data session type has relation
parent
1dae9ec356
commit
990d73bdb1
|
@ -7,7 +7,11 @@ import {
|
|||
import { SeasonTypeModel } from '../../../data/models/season-type.model';
|
||||
import { SeasonTypeDeletedEvent } from '../../entities/event/season-type-deleted.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchDeleteSeasonTypeManager extends BaseBatchDeleteManager<SeasonTypeEntity> {
|
||||
|
@ -16,6 +20,19 @@ export class BatchDeleteSeasonTypeManager extends BaseBatchDeleteManager<SeasonT
|
|||
}
|
||||
|
||||
async validateData(data: SeasonTypeEntity): Promise<void> {
|
||||
const relationData = await this.dataServiceFirstOpt.getOneByOptions({
|
||||
where: {
|
||||
season_type_id: data.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (relationData) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagagl! data sudah berelasi dengen season period.`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,28 @@ import {
|
|||
import { SeasonTypeModel } from '../../../data/models/season-type.model';
|
||||
import { SeasonTypeChangeStatusEvent } from '../../entities/event/season-type-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchInactiveSeasonTypeManager extends BaseBatchUpdateStatusManager<SeasonTypeEntity> {
|
||||
validateData(data: SeasonTypeEntity): Promise<void> {
|
||||
async validateData(data: SeasonTypeEntity): Promise<void> {
|
||||
const relationData = await this.dataServiceFirstOpt.getOneByOptions({
|
||||
where: {
|
||||
season_type_id: data.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (relationData) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagagl! data sudah berelasi dengen season period.`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||
import { SeasonTypeEntity } from '../../entities/season-type.entity';
|
||||
import {
|
||||
|
@ -15,6 +19,19 @@ export class DeleteSeasonTypeManager extends BaseDeleteManager<SeasonTypeEntity>
|
|||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
const relationData = await this.dataServiceFirstOpt.getOneByOptions({
|
||||
where: {
|
||||
season_type_id: this.dataId,
|
||||
},
|
||||
});
|
||||
|
||||
if (relationData) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagagl! data sudah berelasi dengen season period.`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { SeasonTypeEntity } from '../../entities/season-type.entity';
|
||||
import {
|
||||
|
@ -15,6 +19,20 @@ export class InactiveSeasonTypeManager extends BaseUpdateStatusManager<SeasonTyp
|
|||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
const relationData = await this.dataServiceFirstOpt.getOneByOptions({
|
||||
where: {
|
||||
season_type_id: this.dataId,
|
||||
},
|
||||
});
|
||||
|
||||
if (relationData) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagagl! data sudah berelasi dengen season period.`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import { BatchInactiveSeasonTypeManager } from './managers/batch-inactive-season
|
|||
import { BatchActiveSeasonTypeManager } from './managers/batch-active-season-type.manager';
|
||||
import { BatchDeleteSeasonTypeManager } from './managers/batch-delete-season-type.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<SeasonTypeEntity> {
|
||||
|
@ -30,6 +31,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
|||
private batchConfirmManager: BatchConfirmSeasonTypeManager,
|
||||
private batchInactiveManager: BatchInactiveSeasonTypeManager,
|
||||
private serviceData: SeasonTypeDataService,
|
||||
private servicePeriodData: SeasonPeriodDataService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@ -50,7 +52,11 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
|||
|
||||
async delete(dataId): Promise<string> {
|
||||
this.deleteManager.setData(dataId);
|
||||
this.deleteManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE);
|
||||
this.deleteManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.SEASON_TYPE,
|
||||
this.servicePeriodData,
|
||||
);
|
||||
await this.deleteManager.execute();
|
||||
return this.deleteManager.getResult();
|
||||
}
|
||||
|
@ -60,6 +66,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
|||
this.batchDeleteManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.SEASON_TYPE,
|
||||
this.servicePeriodData,
|
||||
);
|
||||
await this.batchDeleteManager.execute();
|
||||
return this.batchDeleteManager.getResult();
|
||||
|
@ -101,7 +108,11 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
|||
|
||||
async inactive(dataId): Promise<string> {
|
||||
this.inactiveManager.setData(dataId, STATUS.INACTIVE);
|
||||
this.inactiveManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE);
|
||||
this.inactiveManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.SEASON_TYPE,
|
||||
this.servicePeriodData,
|
||||
);
|
||||
await this.inactiveManager.execute();
|
||||
return this.inactiveManager.getResult();
|
||||
}
|
||||
|
@ -111,6 +122,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
|||
this.batchInactiveManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.SEASON_TYPE,
|
||||
this.servicePeriodData,
|
||||
);
|
||||
await this.batchInactiveManager.execute();
|
||||
return this.batchInactiveManager.getResult();
|
||||
|
|
|
@ -22,11 +22,16 @@ import { BatchActiveSeasonTypeManager } from './domain/usecases/managers/batch-a
|
|||
import { BatchConfirmSeasonTypeManager } from './domain/usecases/managers/batch-confirm-season-type.manager';
|
||||
import { BatchInactiveSeasonTypeManager } from './domain/usecases/managers/batch-inactive-season-type.manager';
|
||||
import { SeasonTypeModel } from './data/models/season-type.model';
|
||||
import { SeasonPeriodDataService } from '../season-period/data/services/season-period-data.service';
|
||||
import { SeasonPeriodModel } from '../season-period/data/models/season-period.model';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature([SeasonTypeModel], CONNECTION_NAME.DEFAULT),
|
||||
TypeOrmModule.forFeature(
|
||||
[SeasonTypeModel, SeasonPeriodModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
],
|
||||
controllers: [SeasonTypeDataController, SeasonTypeReadController],
|
||||
|
@ -49,6 +54,7 @@ import { SeasonTypeModel } from './data/models/season-type.model';
|
|||
|
||||
SeasonTypeDataOrchestrator,
|
||||
SeasonTypeReadOrchestrator,
|
||||
SeasonPeriodDataService,
|
||||
],
|
||||
})
|
||||
export class SeasonTypeModule {}
|
||||
|
|
Loading…
Reference in New Issue