Files
ruflo/examples/user-api/models/User.js
T
2025-06-16 19:09:10 +00:00

33 lines
796 B
JavaScript

const { v4: uuidv4 } = require('uuid');
class User {
constructor(data) {
this.id = data.id || uuidv4();
this.name = data.name;
this.email = data.email;
this.age = data.age;
this.createdAt = data.createdAt || new Date().toISOString();
this.updatedAt = data.updatedAt || new Date().toISOString();
}
toJSON() {
return {
id: this.id,
name: this.name,
email: this.email,
age: this.age,
createdAt: this.createdAt,
updatedAt: this.updatedAt
};
}
update(data) {
if (data.name !== undefined) this.name = data.name;
if (data.email !== undefined) this.email = data.email;
if (data.age !== undefined) this.age = data.age;
this.updatedAt = new Date().toISOString();
return this;
}
}
module.exports = User;