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 { SeasonTypeModel } from '../../../data/models/season-type.model';
|
||||||
import { SeasonTypeDeletedEvent } from '../../entities/event/season-type-deleted.event';
|
import { SeasonTypeDeletedEvent } from '../../entities/event/season-type-deleted.event';
|
||||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { Injectable } from '@nestjs/common';
|
import {
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
UnprocessableEntityException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BatchDeleteSeasonTypeManager extends BaseBatchDeleteManager<SeasonTypeEntity> {
|
export class BatchDeleteSeasonTypeManager extends BaseBatchDeleteManager<SeasonTypeEntity> {
|
||||||
|
@ -16,6 +20,19 @@ export class BatchDeleteSeasonTypeManager extends BaseBatchDeleteManager<SeasonT
|
||||||
}
|
}
|
||||||
|
|
||||||
async 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,28 @@ import {
|
||||||
import { SeasonTypeModel } from '../../../data/models/season-type.model';
|
import { SeasonTypeModel } from '../../../data/models/season-type.model';
|
||||||
import { SeasonTypeChangeStatusEvent } from '../../entities/event/season-type-change-status.event';
|
import { SeasonTypeChangeStatusEvent } from '../../entities/event/season-type-change-status.event';
|
||||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { Injectable } from '@nestjs/common';
|
import {
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
UnprocessableEntityException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BatchInactiveSeasonTypeManager extends BaseBatchUpdateStatusManager<SeasonTypeEntity> {
|
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;
|
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 { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||||
import { SeasonTypeEntity } from '../../entities/season-type.entity';
|
import { SeasonTypeEntity } from '../../entities/season-type.entity';
|
||||||
import {
|
import {
|
||||||
|
@ -15,6 +19,19 @@ export class DeleteSeasonTypeManager extends BaseDeleteManager<SeasonTypeEntity>
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
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;
|
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 { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||||
import { SeasonTypeEntity } from '../../entities/season-type.entity';
|
import { SeasonTypeEntity } from '../../entities/season-type.entity';
|
||||||
import {
|
import {
|
||||||
|
@ -15,6 +19,20 @@ export class InactiveSeasonTypeManager extends BaseUpdateStatusManager<SeasonTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { BatchInactiveSeasonTypeManager } from './managers/batch-inactive-season
|
||||||
import { BatchActiveSeasonTypeManager } from './managers/batch-active-season-type.manager';
|
import { BatchActiveSeasonTypeManager } from './managers/batch-active-season-type.manager';
|
||||||
import { BatchDeleteSeasonTypeManager } from './managers/batch-delete-season-type.manager';
|
import { BatchDeleteSeasonTypeManager } from './managers/batch-delete-season-type.manager';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
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()
|
@Injectable()
|
||||||
export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<SeasonTypeEntity> {
|
export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<SeasonTypeEntity> {
|
||||||
|
@ -30,6 +31,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
||||||
private batchConfirmManager: BatchConfirmSeasonTypeManager,
|
private batchConfirmManager: BatchConfirmSeasonTypeManager,
|
||||||
private batchInactiveManager: BatchInactiveSeasonTypeManager,
|
private batchInactiveManager: BatchInactiveSeasonTypeManager,
|
||||||
private serviceData: SeasonTypeDataService,
|
private serviceData: SeasonTypeDataService,
|
||||||
|
private servicePeriodData: SeasonPeriodDataService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,11 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
||||||
|
|
||||||
async delete(dataId): Promise<string> {
|
async delete(dataId): Promise<string> {
|
||||||
this.deleteManager.setData(dataId);
|
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();
|
await this.deleteManager.execute();
|
||||||
return this.deleteManager.getResult();
|
return this.deleteManager.getResult();
|
||||||
}
|
}
|
||||||
|
@ -60,6 +66,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
||||||
this.batchDeleteManager.setService(
|
this.batchDeleteManager.setService(
|
||||||
this.serviceData,
|
this.serviceData,
|
||||||
TABLE_NAME.SEASON_TYPE,
|
TABLE_NAME.SEASON_TYPE,
|
||||||
|
this.servicePeriodData,
|
||||||
);
|
);
|
||||||
await this.batchDeleteManager.execute();
|
await this.batchDeleteManager.execute();
|
||||||
return this.batchDeleteManager.getResult();
|
return this.batchDeleteManager.getResult();
|
||||||
|
@ -101,7 +108,11 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
||||||
|
|
||||||
async inactive(dataId): Promise<string> {
|
async inactive(dataId): Promise<string> {
|
||||||
this.inactiveManager.setData(dataId, STATUS.INACTIVE);
|
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();
|
await this.inactiveManager.execute();
|
||||||
return this.inactiveManager.getResult();
|
return this.inactiveManager.getResult();
|
||||||
}
|
}
|
||||||
|
@ -111,6 +122,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
|
||||||
this.batchInactiveManager.setService(
|
this.batchInactiveManager.setService(
|
||||||
this.serviceData,
|
this.serviceData,
|
||||||
TABLE_NAME.SEASON_TYPE,
|
TABLE_NAME.SEASON_TYPE,
|
||||||
|
this.servicePeriodData,
|
||||||
);
|
);
|
||||||
await this.batchInactiveManager.execute();
|
await this.batchInactiveManager.execute();
|
||||||
return this.batchInactiveManager.getResult();
|
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 { BatchConfirmSeasonTypeManager } from './domain/usecases/managers/batch-confirm-season-type.manager';
|
||||||
import { BatchInactiveSeasonTypeManager } from './domain/usecases/managers/batch-inactive-season-type.manager';
|
import { BatchInactiveSeasonTypeManager } from './domain/usecases/managers/batch-inactive-season-type.manager';
|
||||||
import { SeasonTypeModel } from './data/models/season-type.model';
|
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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature([SeasonTypeModel], CONNECTION_NAME.DEFAULT),
|
TypeOrmModule.forFeature(
|
||||||
|
[SeasonTypeModel, SeasonPeriodModel],
|
||||||
|
CONNECTION_NAME.DEFAULT,
|
||||||
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [SeasonTypeDataController, SeasonTypeReadController],
|
controllers: [SeasonTypeDataController, SeasonTypeReadController],
|
||||||
|
@ -49,6 +54,7 @@ import { SeasonTypeModel } from './data/models/season-type.model';
|
||||||
|
|
||||||
SeasonTypeDataOrchestrator,
|
SeasonTypeDataOrchestrator,
|
||||||
SeasonTypeReadOrchestrator,
|
SeasonTypeReadOrchestrator,
|
||||||
|
SeasonPeriodDataService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class SeasonTypeModule {}
|
export class SeasonTypeModule {}
|
||||||
|
|
Loading…
Reference in New Issue