Closed simonmumenthaler closed 4 years ago
We've just ran into https://github.com/shiftcode/dynamo-easy/issues/244 (we wanted to store a 'lastUpdated' on write to DB) - is this PR still active?
@benheymink this PR is still active - but it does not yet satisfy the lastUpdated
feature but a defaultValueProvider
which is only applied on PUT.
We made the prerelease 6.0.0-pr91.1 with this defaultValueProvider
feature.
hey just wanted to say thanks for the hard work We are also waiting for this PR (will start to use the prerelease for now).
We managed to get lastUpdated
like this:
@Property({
mapper: {
fromDb: dateToStringMapper.fromDb,
toDb: (existingUpdateAt) => {
// When creating an entity, defaultValueProvider will be called, and then toDb will also be called,
// so the returned instance and the saved one will have a millisecond difference in 'updatedAt'
// This is a big mess in the tests (returned and created objects are not equal)
// so on isFirstSave we will not use a new date value
const dateToSave = existingUpdateAt.isFirstSave ? existingUpdateAt : new Date();
existingUpdateAt.isFirstSave = false;
return dateToStringMapper.toDb(dateToSave);
}
},
defaultValueProvider: () => {
const now = new Date();
now.isFirstSave = true;
return now;
}
})
updatedAt?: Date;
:tada: This PR is included in version 7.0.0-next.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This PR is included in version 7.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
solves #244 enables '#91 auto generate timestamps' on put (not on update)