0
0
Expressframework~10 mins

DTO pattern for data transfer in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a simple DTO class in Express.

Express
class UserDTO {
  constructor(user) {
    this.id = user.[1];
  }
}
Drag options to blanks, or click blank then click option'
Apassword
Bname
Cid
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing sensitive data like password
Using full user object instead of selected fields
2fill in blank
medium

Complete the code to create a DTO instance from a user object.

Express
const userDTO = new UserDTO({ id: 1, name: 'Alice', email: 'alice@example.com' });
console.log(userDTO.[1]);
Drag options to blanks, or click blank then click option'
Aid
Bpassword
Cemail
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access properties not defined in the DTO
Using full user object properties
3fill in blank
hard

Fix the error in the DTO class to correctly assign the email property.

Express
class UserDTO {
  constructor(user) {
    this.email = user.[1];
  }
}
Drag options to blanks, or click blank then click option'
AemailAddress
Bemail
Cmail
DuserEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names
Assuming different naming conventions
4fill in blank
hard

Fill both blanks to create a DTO that includes id and email from the user object.

Express
class UserDTO {
  constructor(user) {
    this.[1] = user.id;
    this.[2] = user.email;
  }
}
Drag options to blanks, or click blank then click option'
Aid
Bemail
Cname
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Including sensitive data like password
Mixing property names
5fill in blank
hard

Fill all three blanks to create a DTO that includes id, name, and email from the user object.

Express
class UserDTO {
  constructor(user) {
    this.[1] = user.id;
    this.[2] = user.name;
    this.[3] = user.email;
  }
}
Drag options to blanks, or click blank then click option'
Aid
Bname
Cemail
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Including password
Mixing property names or order