3f70cc08b7
refs https://github.com/TryGhost/Product/issues/4196 The offers API basically returns the data you pass to it, rather than the created database record. It looks like this is how it was intended to work in the first place; the `setMilliseconds` is because the test helper expects `.000Z`, which I assume is because MySQL will strip off the milliseconds when it's saved.
31 lines
881 B
JavaScript
31 lines
881 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) {
|
|
const now = new Date();
|
|
now.setMilliseconds(0);
|
|
return now.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;
|