You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not able to implement timestamps properly when extending your service class.
After updating an entity the createdAt field is null. Looks like this can only be changed from
within the service itself or completely overwriting your update method.
const { Service } = require('feathers-objection');
const uuid = require('uuidv4');
module.exports = class BaseService extends Service {
create(data, params) {
if(!Array.isArray(data)) data = [data];
for(let i = 0; i < data.length; i++) {
data[i].id = uuid();
data[i].createdAt = new Date().toISOString();
delete data[i].updatedAt;
}
if(data.length === 1) data = data[0];
return super.create(data, params);
}
update(id, data, params) {
data.updatedAt = new Date().toISOString();
delete data.createdAt;
return super.update(id, data, params);
}
patch(id, data, params) {
data.updatedAt = new Date().toISOString();
delete data.createdAt;
return super.patch(id, data, params);
}
}
The text was updated successfully, but these errors were encountered:
This is working for me. Now the createdAt timestamp is consistent.
update(id, data, params) {
data.updatedAt = new Date().toISOString();
delete data.createdAt;
if (Array.isArray(data)) {
return Promise.reject(new Error('Not replacing multiple records. Did you mean `patch`?'));
}
return this._get(id, params).then(oldData => {
let newObject = { ...oldData, ...data };
// NOTE (EK): Delete id field so we don't update it
delete newObject[this.id];
return this._createQuery(params).where(this.id, id).update(newObject).then(() => {
// NOTE (EK): Restore the id field so we can return it to the client
return { id, ...newObject};
});
}).catch(function(err) { throw Error(err) });
}
Hi
I'm not able to implement timestamps properly when extending your service class.
After updating an entity the createdAt field is null. Looks like this can only be changed from
within the service itself or completely overwriting your update method.
The text was updated successfully, but these errors were encountered: