Код: Выделить всё
@Column({nullable: true, type: 'date', transformer: new DateTransformer()})
start: Date | string;
@Column({nullable: true, type: 'date', transformer: new DateTransformer()})
end: Date | string;
Код: Выделить всё
export class DateTransformer implements ValueTransformer {
constructor(nullable: boolean = true) {
this.nullable = nullable;
}
protected nullable: boolean;
to(value: Date | string): string {
return value ? moment.utc(value).format('YYYY-MM-DD') : this.nullable ? null : moment.utc().format('YYYY-MM-DD');
}
from(value: string): string {
return value ? moment.utc(value).tz('Europe/London').format('YYYY-MM-DD') : null;
}
}
Код: Выделить всё
MyEntity.find({
where: {
start: LessThanOrEqual(today),
end: Or(MoreThanOrEqual(today), IsNull())
}
});
Код: Выделить всё
SELECT *
FROM my_entity
WHERE start = '2025-06-13' OR end IS NULL);
Подробнее здесь: https://stackoverflow.com/questions/796 ... ate-transf