2023-11-16 13:33:01 +03:00
|
|
|
const ValueObject = require('./shared/ValueObject');
|
|
|
|
const InvalidOfferCreatedAt = require('../errors').InvalidOfferCreatedAt;
|
|
|
|
|
|
|
|
/** @extends ValueObject<string> */
|
|
|
|
class OfferCreatedAt extends ValueObject {
|
|
|
|
/** @param {Date} createdAt */
|
|
|
|
constructor(createdAt) {
|
|
|
|
super(createdAt.toISOString()); // Convert Date to ISO string
|
|
|
|
}
|
|
|
|
|
|
|
|
static create(createdAt) {
|
|
|
|
if (createdAt === null || createdAt === undefined) {
|
2023-11-28 18:11:35 +03:00
|
|
|
const now = new Date();
|
|
|
|
now.setMilliseconds(0);
|
|
|
|
return now.toISOString();
|
2023-11-16 13:33:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(createdAt instanceof Date)) {
|
|
|
|
throw new InvalidOfferCreatedAt({
|
|
|
|
message: 'Offer `created_at` must be a Date.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return createdAt.toISOString();
|
|
|
|
}
|
|
|
|
|
|
|
|
static InvalidOfferCreatedAt = InvalidOfferCreatedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = OfferCreatedAt;
|