fix(SPG-652) Item Tipe Bundling - Item yang sudah berrelasi atau dipakai pada bundling tidak dapat di delete atau di inactivekan sampai di lepas dari bundling nya
parent
a63eaf0110
commit
e68524380a
|
@ -97,7 +97,7 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
|
||||||
|
|
||||||
this.eventBus.publishAll([
|
this.eventBus.publishAll([
|
||||||
new topic.topic({
|
new topic.topic({
|
||||||
id: data?.['id'] ?? topic?.data?.['id'],
|
id: this.result['id'],
|
||||||
old: null,
|
old: null,
|
||||||
data: data ?? topic.data,
|
data: data ?? topic.data,
|
||||||
user: this.user,
|
user: this.user,
|
||||||
|
|
|
@ -7,7 +7,11 @@ import {
|
||||||
import { ItemModel } from '../../../data/models/item.model';
|
import { ItemModel } from '../../../data/models/item.model';
|
||||||
import { ItemDeletedEvent } from '../../entities/event/item-deleted.event';
|
import { ItemDeletedEvent } from '../../entities/event/item-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 BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
export class BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
||||||
|
@ -16,6 +20,21 @@ export class BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateData(data: ItemEntity): Promise<void> {
|
async validateData(data: ItemEntity): Promise<void> {
|
||||||
|
const haveRelation = await this.dataService.getOneByOptions({
|
||||||
|
where: {
|
||||||
|
bundling_items: {
|
||||||
|
id: data.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (haveRelation) {
|
||||||
|
throw new UnprocessableEntityException({
|
||||||
|
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
|
message: `Failed! this data already connected to bunding item`,
|
||||||
|
error: 'Unprocessable Entity',
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +43,7 @@ export class BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
get validateRelations(): validateRelations[] {
|
||||||
return [{ relation: 'bundling_items' }];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get entityTarget(): any {
|
get entityTarget(): any {
|
||||||
|
|
|
@ -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 { ItemEntity } from '../../entities/item.entity';
|
import { ItemEntity } from '../../entities/item.entity';
|
||||||
import {
|
import {
|
||||||
|
@ -15,6 +19,21 @@ export class DeleteItemManager extends BaseDeleteManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
async validateProcess(): Promise<void> {
|
||||||
|
const haveRelation = await this.dataService.getOneByOptions({
|
||||||
|
where: {
|
||||||
|
bundling_items: {
|
||||||
|
id: this.dataId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (haveRelation) {
|
||||||
|
throw new UnprocessableEntityException({
|
||||||
|
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
|
message: `Failed! this data already connected to bunding item`,
|
||||||
|
error: 'Unprocessable Entity',
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +46,7 @@ export class DeleteItemManager extends BaseDeleteManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
get validateRelations(): validateRelations[] {
|
||||||
return [{ relation: 'bundling_items' }];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get entityTarget(): any {
|
get entityTarget(): any {
|
||||||
|
|
Loading…
Reference in New Issue