fix(SPG-573) Validasi season period tipe specific days - sekalipun harinya berbeda masih terkena validasi, seharusnya bisa disimpan

pull/6/head^2
Aswin Ashar Abdullah 2024-06-30 23:55:56 +07:00
parent 3bb6ed1082
commit 4b31dd40b5
1 changed files with 19 additions and 8 deletions

View File

@ -31,7 +31,7 @@ export async function ValidateSeasonPeriodHelper(dataService, data) {
query.andWhere('data.id != :dataId', { dataId: data.id })
}
const datas = await query
let datas = await query
.andWhere('data.priority = :priority', { priority: priority })
.andWhere(
new Brackets(query => {
@ -54,14 +54,25 @@ export async function ValidateSeasonPeriodHelper(dataService, data) {
return query;
})
)
.getCount();
.getMany();
if (datas > 0) {
throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Failed! there is another season period in same range date`,
error: 'Unprocessable Entity',
});
if (priority == 2) {
datas = datas?.filter(item => {
const sameDate = item.days.filter((day) => {
return data.days.some((day2) => {
return day == day2;
});
});
return sameDate.length > 0
})
}
if (datas.length > 0) {
throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Failed! there is another season period in same range date`,
error: 'Unprocessable Entity',
});
}
return priority;