mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-09 05:35:21 +09:00
33 lines
796 B
JavaScript
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; |