loopback before save 1

loopback before save

module.exports = function (model) {
    model.observe('before save', async function(ctx, next) {
    });
};

Here is what the above code is Doing:
1. It’s listening for the before save event.
2. It’s checking if the instance is new.
3. If it is, it’s setting the createdAt property to the current date.
4. It’s checking if the instance has been modified.
5. If it has, it’s setting the updatedAt property to the current date.
6. It’s calling the next() function to continue the execution.

Now, let’s add the code to the common/models/user.js file:

Similar Posts