From 030866124be9409acb30416d8689ac1c0783063c Mon Sep 17 00:00:00 2001 From: Lam Kee Wei Date: Tue, 24 Aug 2021 11:34:48 +0800 Subject: [PATCH] refactor: move identity services to module --- middleware/auth.js | 2 +- services/{ => identity}/AuthService.js | 0 services/{ => identity}/SiteService.js | 2 +- services/{ => identity}/TokenStore.js | 0 services/{ => identity}/index.js | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename services/{ => identity}/AuthService.js (100%) rename services/{ => identity}/SiteService.js (91%) rename services/{ => identity}/TokenStore.js (100%) rename services/{ => identity}/index.js (85%) diff --git a/middleware/auth.js b/middleware/auth.js index e7cf2e83e..cccd98fb3 100644 --- a/middleware/auth.js +++ b/middleware/auth.js @@ -11,7 +11,7 @@ const { NotFoundError } = require("@errors/NotFoundError") const jwtUtils = require("@utils/jwt-utils") // Import services -const { authService, siteService } = require("@services") +const { authService, siteService } = require("@services/identity") // Instantiate router object const auth = express.Router() diff --git a/services/AuthService.js b/services/identity/AuthService.js similarity index 100% rename from services/AuthService.js rename to services/identity/AuthService.js diff --git a/services/SiteService.js b/services/identity/SiteService.js similarity index 91% rename from services/SiteService.js rename to services/identity/SiteService.js index 1b77b5fb8..e6ebeb4e2 100644 --- a/services/SiteService.js +++ b/services/identity/SiteService.js @@ -1,5 +1,5 @@ class SiteService { - constructor(repository, tokenStore) { + constructor({ repository, tokenStore }) { this.repository = repository this.tokenStore = tokenStore } diff --git a/services/TokenStore.js b/services/identity/TokenStore.js similarity index 100% rename from services/TokenStore.js rename to services/identity/TokenStore.js diff --git a/services/index.js b/services/identity/index.js similarity index 85% rename from services/index.js rename to services/identity/index.js index 25b98ec41..5d1da6587 100644 --- a/services/index.js +++ b/services/identity/index.js @@ -9,7 +9,7 @@ const IS_LOCAL_DEV = process.env.NODE_ENV === "LOCAL_DEV" const tokenStore = IS_LOCAL_DEV ? { getToken: (_apiTokenName) => process.env.LOCAL_SITE_ACCESS_TOKEN } : new TokenStore() -const siteService = new SiteService(db.Site, tokenStore) +const siteService = new SiteService({ repository: db.Site, tokenStore }) const authService = new AuthService() module.exports = { authService, siteService }