Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
added UserService and RoleService
  • Loading branch information
saadshams committed Sep 4, 2024
1 parent ce201d7 commit 06605bf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/model/service/RoleService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// RoleService.js
// PureMVC JS Demo - EmployeeAdmin Microservice
//
// Copyright(c) 2023 Saad Shams <[email protected]>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//

export class RoleService {

// See UserService
constructor() {
}

}
45 changes: 45 additions & 0 deletions src/model/service/UserService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// UserService.js
// PureMVC JS Demo - EmployeeAdmin Microservice
//
// Copyright(c) 2023 Saad Shams <[email protected]>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//

import https from "node:https";

export class UserService {

constructor() {}

// Simple Use Case:
// If the data is sourced externally, the Proxy first checks the database (UserData) to see if the data is
// available. If available, it returns the cached data to the Mediator. Otherwise, it contacts the UserService.
// Service classes retrieve data from external sources, manage network requests and parsing, and return data to
// the Proxy, which then caches it in the database for future use before returning it to the Mediator.

// Complex Use Case:
// A Command will come into play if the data retrieval involves multiple proxies and data sources,
// typically if the logic spans different domains.
// The Command encapsulates business logic, manages data retrieval, performs data transformation, and
// enforces business rules before returning the final data to the Mediator and its component.
findAllUsers() {
return new Promise((resolve, reject) => {
https.request({
method: "GET", hostname: "https://jsonplaceholder.typicode.com", path: "/users"
}, response => {
let buffers = [];
response.on("data", data => buffers.push(data));
response.on("end", () => {
try {
if(response.statusCode === 200)
resolve(JSON.parse(Buffer.concat(buffers).toString()));
else
reject(JSON.parse(Buffer.concat(buffers).toString()));
} catch(error) { reject(error); }
});
}).on("error", reject).end();
});
}

}

0 comments on commit 06605bf

Please sign in to comment.