Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserModel {
- constructor() {
- this.username = ''
- this.password = ''
- this.firstName = ''
- this.lastName = ''
- this.age = null
- }
- }
- class UserRepository {
- constructor(dbSession) {
- this.dbSession = dbSession
- }
- getAll() {
- const results = this.dbSession.query("SELECT * FROM users;")
- return results.map(result => {
- const model = new UserModel()
- model.firstName = result.get('firstName')
- model.lastName = result.get('lastName')
- model.age = result.get('age')
- model.password = result.get('password')
- model.username = result.get('username')
- return model
- })
- }
- create() {
- // implement
- }
- update() {
- // implement
- }
- delete() {
- // implement
- }
- }
- class UserDTO {
- constructor() {
- this.firstName = ''
- this.lastName = ''
- this.age = null
- }
- static fromUserModel(userModel) {
- const userDTO = new UserDTO()
- userDTO.firstName = userModel.firstName
- userDTO.lastName = userModel.lastName
- userDTO.age = userModel.age
- return userDTO
- }
- }
- class UserService {
- constructor(userRepository) {
- this.userRepository = userRepository
- }
- getAllUsers() {
- const users = this.userRepository.getAll()
- return users.map(userModel => UserDTO.fromModel(userModel))
- }
- }
- class UserController {
- constructor(userService) {
- this.userService = userService
- }
- getAllUsers() {
- this.userService.getAllUsers()
- }
- }
- // main.js
- const dbSession = driver.getSession()
- const userRepostory = new UserRepository(dbSession)
- const userService = new UserService(userRepostory)
- const userController = new UserController(userService)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement