fix(SPG-671) Item Bundling - validasi / warning jika item dalam bundling diinactivekan sedangkan masih berelasi, bundling harus di inactivekan dulu atau didelete
parent
b3f0752ca0
commit
b91d9f7da8
|
@ -7,11 +7,8 @@ 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 {
|
import { Injectable } from '@nestjs/common';
|
||||||
HttpStatus,
|
import { validateRelation } from './helpers/validasi-relation.helper';
|
||||||
Injectable,
|
|
||||||
UnprocessableEntityException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
export class BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
||||||
|
@ -20,21 +17,7 @@ export class BatchDeleteItemManager extends BaseBatchDeleteManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateData(data: ItemEntity): Promise<void> {
|
async validateData(data: ItemEntity): Promise<void> {
|
||||||
const haveRelation = await this.dataService.getOneByOptions({
|
await validateRelation(this.dataService, data.id);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,12 @@ import { ItemModel } from '../../../data/models/item.model';
|
||||||
import { ItemChangeStatusEvent } from '../../entities/event/item-change-status.event';
|
import { ItemChangeStatusEvent } from '../../entities/event/item-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 { Injectable } from '@nestjs/common';
|
||||||
|
import { validateRelation } from './helpers/validasi-relation.helper';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BatchInactiveItemManager extends BaseBatchUpdateStatusManager<ItemEntity> {
|
export class BatchInactiveItemManager extends BaseBatchUpdateStatusManager<ItemEntity> {
|
||||||
validateData(data: ItemEntity): Promise<void> {
|
async validateData(data: ItemEntity): Promise<void> {
|
||||||
|
await validateRelation(this.dataService, data.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
import {
|
import { Injectable } from '@nestjs/common';
|
||||||
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 {
|
||||||
|
@ -11,6 +7,7 @@ import {
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
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 { validateRelation } from './helpers/validasi-relation.helper';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeleteItemManager extends BaseDeleteManager<ItemEntity> {
|
export class DeleteItemManager extends BaseDeleteManager<ItemEntity> {
|
||||||
|
@ -19,21 +16,7 @@ export class DeleteItemManager extends BaseDeleteManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
async validateProcess(): Promise<void> {
|
||||||
const haveRelation = await this.dataService.getOneByOptions({
|
await validateRelation(this.dataService, this.dataId);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { HttpStatus, UnprocessableEntityException } from '@nestjs/common';
|
||||||
|
|
||||||
|
export async function validateRelation(dataService, id) {
|
||||||
|
const haveRelation = await dataService.getOneByOptions({
|
||||||
|
where: {
|
||||||
|
bundling_items: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (haveRelation) {
|
||||||
|
throw new UnprocessableEntityException({
|
||||||
|
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
|
message: `Failed! this data already connected to bunding item`,
|
||||||
|
error: 'Unprocessable Entity',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import {
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
import { ItemModel } from '../../../data/models/item.model';
|
import { ItemModel } from '../../../data/models/item.model';
|
||||||
import { ItemChangeStatusEvent } from '../../entities/event/item-change-status.event';
|
import { ItemChangeStatusEvent } from '../../entities/event/item-change-status.event';
|
||||||
|
import { validateRelation } from './helpers/validasi-relation.helper';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InactiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
|
export class InactiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
|
||||||
|
@ -15,6 +16,7 @@ export class InactiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
async validateProcess(): Promise<void> {
|
||||||
|
await validateRelation(this.dataService, this.dataId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue