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