29 lines
816 B
JavaScript
29 lines
816 B
JavaScript
|
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) {
|
||
|
return new Date().toISOString();
|
||
|
}
|
||
|
|
||
|
if (!(createdAt instanceof Date)) {
|
||
|
throw new InvalidOfferCreatedAt({
|
||
|
message: 'Offer `created_at` must be a Date.'
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return createdAt.toISOString();
|
||
|
}
|
||
|
|
||
|
static InvalidOfferCreatedAt = InvalidOfferCreatedAt;
|
||
|
}
|
||
|
|
||
|
module.exports = OfferCreatedAt;
|