fix(SPG-566) BE - Validasi season periode tipe range date
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
parent
9f471aafbf
commit
1e0766dc50
|
@ -1,4 +1,6 @@
|
|||
import { HttpStatus, UnprocessableEntityException } from "@nestjs/common";
|
||||
import { Brackets } from "typeorm";
|
||||
import * as _ from 'lodash';
|
||||
|
||||
// function ini bergungsi untuk validasi season period yang sama
|
||||
export async function ValidateSeasonPeriodHelper(dataService, data) {
|
||||
|
@ -31,8 +33,28 @@ export async function ValidateSeasonPeriodHelper(dataService, data) {
|
|||
|
||||
const datas = await query
|
||||
.andWhere('data.priority = :priority', { priority: priority })
|
||||
.andWhere('data.start_date BETWEEN :inputStartDate AND :inputEndDate', { inputStartDate: data.start_date, inputEndDate: data.end_date })
|
||||
.andWhere('data.end_date BETWEEN :inputStartDate AND :inputEndDate', { inputStartDate: data.start_date, inputEndDate: data.end_date }).getCount();
|
||||
.andWhere(
|
||||
new Brackets(query => {
|
||||
|
||||
// contoh data tanggal 1 Agustus - 31 Agustus
|
||||
query.orWhere(
|
||||
new Brackets(q => {
|
||||
return q.andWhere('data.start_date <= :inputStartDate ', { inputStartDate: data.start_date })
|
||||
.andWhere('data.end_date >= :inputEndDate', { inputEndDate: data.end_date });
|
||||
})
|
||||
)
|
||||
|
||||
query.orWhere(
|
||||
new Brackets(q => {
|
||||
return q.andWhere('data.start_date >= :inputStartDate ', { inputStartDate: data.start_date })
|
||||
.andWhere('data.end_date <= :inputEndDate', { inputEndDate: data.end_date });
|
||||
})
|
||||
)
|
||||
|
||||
return query;
|
||||
})
|
||||
)
|
||||
.getCount();
|
||||
|
||||
if (datas > 0) {
|
||||
throw new UnprocessableEntityException({
|
||||
|
|
Loading…
Reference in New Issue