├── .gitignore ├── README.md ├── config.yml ├── controller └── index.js ├── domain ├── entities │ └── entity-user.js ├── orm │ └── orm-user.js ├── repositories │ └── repository_mongo.js └── services │ └── service-user.js ├── index.js ├── package.json ├── routes └── index.js ├── server └── index.js ├── test ├── endPoint.test.js └── functions.test.js └── util ├── enum.js └── magic.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | 64 | #Optional files 65 | package-lock.json 66 | .DS_Store 67 | .vscode 68 | .idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DOMAIN-DRIVEN DESIGN WITH NODEJS AND UNIT TESTS 2 | This is a project to explain hexagonal architecture and unit tests in node.js 3 | 4 | ## What is the Domain? 5 | To define domain-driven design we should first establish what we mean by domain in this context (and in development in general). The common dictionary definition of domain is: “A sphere of knowledge or activity.” Drilling down a bit from that, domain in the realm of software engineering commonly refers to the subject area on which the application is intended to apply. In other words, during application development, the domain is the “sphere of knowledge and activity around which the application logic revolves.” 6 | Another common term used during software development is the domain layer or domain logic which may be better known to many developers as the business logic. The business logic of an application refers to the higher-level rules for how business logic interact with one another to create and modify modelled data. 7 | 8 | 9 | ## Communication flow 10 | 11 | ![myimage-alt-tag](https://miro.medium.com/max/810/1*b75xN3W9mQzta37pT-siRQ.png) 12 | 13 | 14 | ## Dependencies 15 | You need install mongodb in your localhost. 16 | after that you on clone the project, downoland the packages and run it. 17 | 18 | ### GO version 19 | 20 | - [Nodejs v8.12](https://nodejs.org/en/) 21 | 22 | ### Base Framework 23 | - [Express](https://expressjs.com/) 24 | 25 | ### DB Connection 26 | - [Mongoose](https://mongoosejs.com/) 27 | 28 | ```sh 29 | $ git clone https://github.com/javierlecca/nodejs-hexagonal-architecture-and-unit-test.git 30 | $ npm i 31 | $ node index 32 | ``` 33 | -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | port: 8080 2 | db: 3 | mongodb: 4 | - enabled: true 5 | host: localhost 6 | port: 27017 7 | username: test 8 | password: 123456 9 | database: demo 10 | nameconn: connMongo 11 | lang: ES -------------------------------------------------------------------------------- /controller/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'), 4 | router = express.Router(), 5 | magic = require('../util/magic'), 6 | users = require('../domain/services/service-user'); 7 | 8 | console.log('[[ USERS ]]'); 9 | magic.LogInfo('[GET] = /users/') 10 | magic.LogInfo('[GET] = /users/:id') 11 | magic.LogSuccess('[POST] = /users/') 12 | magic.LogWarning('[PATCH] = /users/:id') 13 | magic.LogDanger('[DELETE] = /users/:id') 14 | 15 | router.get('/users/', users.GetAll); 16 | router.get('/users/:id', users.GetById); 17 | router.post('/users/', users.Store); 18 | router.delete('/users/:id', users.DeleteById); 19 | router.patch('/users/:id', users.UpdateById); 20 | 21 | module.exports = router; -------------------------------------------------------------------------------- /domain/entities/entity-user.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = (db) => { 4 | var userSchema = new db.Schema( 5 | { 6 | userId: String, 7 | name: String, 8 | lastName: String, 9 | age: Number, 10 | IsDelete: Boolean 11 | }, 12 | { 13 | timestamps: { 14 | createdAt: 'created_at', 15 | updatedAt: 'updated_at' 16 | } 17 | } 18 | ); 19 | return db.model('Users', userSchema); 20 | }; -------------------------------------------------------------------------------- /domain/orm/orm-user.js: -------------------------------------------------------------------------------- 1 | const conn = require('../repositories/repository_mongo'); 2 | const { uuid } = require('uuidv4'); 3 | 4 | 5 | exports.GetAll = async () =>{ 6 | try{ 7 | return await conn.db.connMongo.User.find({IsDelete: false}); 8 | }catch(err){ 9 | console.log(" err orm-user.GetAll = ", err); 10 | return await {err:{code: 123, messsage: err}} 11 | } 12 | } 13 | 14 | exports.GetById = async ( Id ) =>{ 15 | try{ 16 | return await conn.db.connMongo.User.findOne({ userId: Id, IsDelete: false }); 17 | }catch(err){ 18 | console.log(" err orm-user.GetById = ", err); 19 | return await {err:{code: 123, messsage: err}} 20 | } 21 | } 22 | 23 | exports.Store = async ( Name, LastName, Age ) =>{ 24 | try{ 25 | const datacenter = await new conn.db.connMongo.User({ 26 | userId: uuid(), 27 | name: Name, 28 | lastName: LastName, 29 | age: Age, 30 | IsDelete: false 31 | }); 32 | datacenter.save(); 33 | return true 34 | }catch(err){ 35 | console.log(" err orm-user.Store = ", err); 36 | return await {err:{code: 123, messsage: err}} 37 | } 38 | } 39 | 40 | exports.DeleteById = async ( Id ) =>{ 41 | try{ 42 | await conn.db.connMongo.User.findOneAndUpdate({userId: Id}, { IsDelete: true }) 43 | return true 44 | }catch(err){ 45 | console.log(" err orm-user.Store = ", err); 46 | return await {err:{code: 123, messsage: err}} 47 | } 48 | } 49 | 50 | exports.UpdateById = async ( Name, LastName, Age, Id ) =>{ 51 | try{ 52 | await conn.db.connMongo.User.findOneAndUpdate( 53 | { 54 | userId: Id 55 | },{ 56 | name: Name, 57 | lastName: LastName, 58 | age: Age 59 | }) 60 | return true 61 | }catch(err){ 62 | console.log(" err orm-user.Store = ", err); 63 | return await {err:{code: 123, messsage: err}} 64 | } 65 | } -------------------------------------------------------------------------------- /domain/repositories/repository_mongo.js: -------------------------------------------------------------------------------- 1 | const config = require('config-yml'); 2 | const mongoose = require('mongoose'); 3 | const enum_ = require('../../util/magic'); 4 | const user = require('../entities/entity-user'); 5 | 6 | mongoose.set('useFindAndModify', false); 7 | 8 | let arrayConns = [], db = {}; 9 | 10 | if (config.db.mongodb && config.db.mongodb.length > 0) { 11 | config.db.mongodb.map((c)=>{ 12 | mongoose.connect(`mongodb://${c.host}/${c.database}`, { 13 | useNewUrlParser: true, 14 | useUnifiedTopology: true, 15 | poolSize: 10 16 | }); 17 | db[c.nameconn] = {} 18 | db[c.nameconn].conn = mongoose; 19 | db[c.nameconn].User = user(mongoose); 20 | }) 21 | exports.db = db; 22 | }else{ 23 | enum_.LogDanger("No hay ninguna base de datos vinculada") 24 | } 25 | -------------------------------------------------------------------------------- /domain/services/service-user.js: -------------------------------------------------------------------------------- 1 | const magic = require('../../util/magic'); 2 | const enum_ = require('../../util/enum'); 3 | const ormUser = require('../orm/orm-user'); 4 | const { isUuid } = require('uuidv4'); 5 | 6 | 7 | exports.GetAll = async (req, res) =>{ 8 | let status = 'Success', errorCode ='', message='', data='', statusCode=0, resp={}; 9 | try{ 10 | respOrm = await ormUser.GetAll(); 11 | if(respOrm.err){ 12 | status = 'Failure', errorCode = respOrm.err.code, message = respOrm.err.messsage, statusCode = enum_.CODE_BAD_REQUEST; 13 | }else{ 14 | message = 'Success Response', data = respOrm, statusCode = data.length > 0 ? enum_.CODE_OK : enum_.CODE_NO_CONTENT; 15 | } 16 | resp = await magic.ResponseService(status,errorCode,message,data); 17 | return res.status(statusCode).send(resp); 18 | } catch(err) { 19 | console.log("err = ", err); 20 | resp = await magic.ResponseService('Failure',enum_.CRASH_LOGIC,err,''); 21 | return res.status(enum_.CODE_INTERNAL_SERVER_ERROR).send(resp); 22 | } 23 | } 24 | 25 | exports.GetById = async (req, res) =>{ 26 | let status = 'Success', errorCode ='', message='', data='', statusCode=0, resp={}; 27 | try{ 28 | const id = req.params.id; 29 | if(isUuid(id)){ 30 | respOrm = await ormUser.GetById(id); 31 | if(respOrm && respOrm.err){ 32 | status = 'Failure', errorCode = respOrm.err.code, message = respOrm.err.messsage, statusCode = enum_.CODE_BAD_REQUEST; 33 | }else{ 34 | if (respOrm) { 35 | message = 'Success Response', data= respOrm, statusCode = enum_.CODE_OK; 36 | }else{ 37 | status = 'Failure', errorCode = enum_.ID_NOT_FOUND, message = 'ID NOT FOUND', statusCode = enum_.CODE_NOT_FOUND; 38 | } 39 | } 40 | }else{ 41 | status = 'Failure', errorCode = enum_.FAIL_CONVERTED_UUID_TO_STRING, message = 'Error trying convert uuid to string', statusCode = enum_.CODE_BAD_REQUEST; 42 | } 43 | resp = await magic.ResponseService(status,errorCode,message,data); 44 | return res.status(statusCode).send(resp); 45 | } catch(err) { 46 | console.log("err = ", err); 47 | return res.status(enum_.CODE_INTERNAL_SERVER_ERROR).send(await magic.ResponseService('Failure',enum_.CRASH_LOGIC,err,'')); 48 | } 49 | } 50 | 51 | 52 | exports.Store = async (req, res) =>{ 53 | let status = 'Success', errorCode ='', message='', data='', statusCode=0, resp={}; 54 | try{ 55 | const Name = req.body.Name; 56 | const LastName = req.body.LastName; 57 | const Age = req.body.Age; 58 | if( Name && LastName && Age ){ 59 | respOrm = await ormUser.Store( Name, LastName, Age ); 60 | if(respOrm.err){ 61 | status = 'Failure', errorCode = respOrm.err.code, message = respOrm.err.messsage, statusCode = enum_.CODE_BAD_REQUEST; 62 | }else{ 63 | message = 'User created', statusCode = enum_.CODE_CREATED; 64 | } 65 | }else{ 66 | status = 'Failure', errorCode = enum_.ERROR_REQUIRED_FIELD, message = 'All fields are required', statusCode = enum_.CODE_BAD_REQUEST; 67 | } 68 | resp = await magic.ResponseService(status,errorCode,message,data) 69 | return res.status(statusCode).send(resp); 70 | } catch(err) { 71 | console.log("err = ", err); 72 | return res.status(enum_.CODE_INTERNAL_SERVER_ERROR).send(await magic.ResponseService('Failure',enum_.CRASH_LOGIC,'err','')); 73 | } 74 | } 75 | 76 | exports.UpdateById = async (req, res) =>{ 77 | let status = 'Success', errorCode ='', message='', data='', statusCode=0, resp={}; 78 | try{ 79 | const id = req.params.id; 80 | if(isUuid(id)){ 81 | const Name = req.body.Name; 82 | const LastName = req.body.LastName; 83 | const Age = req.body.Age; 84 | if( Name && LastName && Age ){ 85 | respOrm = await ormUser.UpdateById( Name, LastName, Age, id ); 86 | if(respOrm.err){ 87 | status = 'Failure', errorCode = respOrm.err.code, message = respOrm.err.messsage, statusCode = enum_.CODE_BAD_REQUEST; 88 | }else{ 89 | message = 'User updated', statusCode = enum_.CODE_CREATED; 90 | } 91 | }else{ 92 | status = 'Failure', errorCode = enum_.ERROR_REQUIRED_FIELD, message = 'All fields are required', statusCode = enum_.CODE_BAD_REQUEST; 93 | } 94 | }else{ 95 | status = 'Failure', errorCode = enum_.FAIL_CONVERTED_UUID_TO_STRING, message = 'Error trying convert uuid to string', statusCode = enum_.CODE_BAD_REQUEST; 96 | } 97 | resp = await magic.ResponseService(status,errorCode,message,data) 98 | return res.status(statusCode).send(resp); 99 | } catch(err) { 100 | console.log("err = ", err); 101 | return res.status(enum_.CODE_INTERNAL_SERVER_ERROR).send(await magic.ResponseService('Failure',enum_.CRASH_LOGIC,err,'')); 102 | } 103 | } 104 | exports.DeleteById = async (req, res) =>{ 105 | let status = 'Success', errorCode ='', message='', data='', statusCode=0, resp={}; 106 | try{ 107 | const id = req.params.id; 108 | if(isUuid(id)){ 109 | respOrm = await ormUser.DeleteById(id); 110 | if(respOrm.err){ 111 | status = 'Failure', errorCode = respOrm.err.code, message = respOrm.err.messsage, statusCode = enum_.CODE_BAD_REQUEST; 112 | }else{ 113 | message = 'User deleted', statusCode = enum_.CODE_OK; 114 | } 115 | }else{ 116 | status = 'Failure', errorCode = enum_.FAIL_CONVERTED_UUID_TO_STRING, message = 'Error trying convert uuid to string', statusCode = enum_.CODE_BAD_REQUEST; 117 | } 118 | resp = await magic.ResponseService(status,errorCode,message,data) 119 | return res.status(statusCode).send(resp); 120 | } catch(err) { 121 | console.log("err = ", err); 122 | return res.status(enum_.CODE_INTERNAL_SERVER_ERROR).send(await magic.ResponseService('Failure',enum_.CRASH_LOGIC,err,'')); 123 | } 124 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const config = require('config-yml'), 3 | server = require('./server'); 4 | 5 | server.listen(config.port); 6 | console.log('Servidor escuchando en puerto ' + config.port); 7 | 8 | server.on('error', err => { 9 | console.error(err); 10 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-hexagonal-architecture-and-unit-test", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "start": "nodemon index.js", 7 | "test": "jest" 8 | }, 9 | "author": "spsa", 10 | "license": "ISC", 11 | "dependencies": { 12 | "config-yml": "^0.10.3", 13 | "cors": "^2.8.5", 14 | "express": "^4.17.1", 15 | "helmet": "^3.21.2", 16 | "mongoose": "^5.9.1", 17 | "uuidv4": "^6.0.2" 18 | }, 19 | "devDependencies": { 20 | "jest": "^25.1.0", 21 | "supertest": "^4.0.2" 22 | }, 23 | "jest": { 24 | "testEnvironment": "node", 25 | "coveragePathIgnorePatterns": [ 26 | "/node_modules/" 27 | ], 28 | "verbose": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /routes/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const apiServices = require('../controller/index'); 4 | 5 | const routers = (app) =>{ 6 | app.use('/api/v1',apiServices); 7 | }; 8 | 9 | module.exports = routers; -------------------------------------------------------------------------------- /server/index.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | const express = require('express'); 5 | const bodyParser = require('body-parser'); 6 | const server = express(); 7 | const helmet = require('helmet'); 8 | const cors = require('cors'); 9 | 10 | server.use(helmet()); 11 | server.use(cors()); 12 | 13 | // parse application/x-www-form-urlencoded 14 | server.use(bodyParser.urlencoded({ extended: false, limit: '50mb' })); 15 | 16 | // parse application/json 17 | server.use(bodyParser.json({limit: '50mb'})); 18 | 19 | require('../routes')(server); 20 | 21 | module.exports = server; 22 | 23 | -------------------------------------------------------------------------------- /test/endPoint.test.js: -------------------------------------------------------------------------------- 1 | const request = require('supertest'); 2 | const app = require('../server'); 3 | 4 | describe('Post Endpoints', () => { 5 | it('should create a new user', async () => { 6 | const res = await request(app) 7 | .post('/api/v1/users/') 8 | .send({ 9 | Name: "Javier Eduardo", 10 | LastName: "Lecca Cruzado", 11 | Age: 28 12 | }); 13 | expect(res.statusCode).toEqual(201); 14 | expect(res.body.status).toEqual('Success'); 15 | }); 16 | }); -------------------------------------------------------------------------------- /test/functions.test.js: -------------------------------------------------------------------------------- 1 | const ormUser = require('../domain/orm/orm-user'); 2 | 3 | describe('Post Endpoints', () => { 4 | it('should info of a USER', async () => { 5 | const res = await ormUser.GetById("76b446ec-e739-496c-a639-8c42c9cf0f00"); 6 | expect(res.name).toEqual("joanna"); 7 | }); 8 | }); -------------------------------------------------------------------------------- /util/enum.js: -------------------------------------------------------------------------------- 1 | // ERRORS FROM BUSINESS LOGIC 2 | 3 | exports.ERROR_REQUIRED_FIELD = "BL2021"; 4 | exports.ID_NOT_FOUND = "BL2022"; 5 | exports.FAIL_CONVERTED_UUID_TO_STRING = "BL2023"; 6 | exports.NO_CONTENT = "BL2024"; 7 | exports.CRASH_LOGIC = "BL2025"; 8 | 9 | //COLORS TO SHOW DETAIL IN LOGS 10 | exports.BLACK_LOG = "\x1b[30m%s\x1b[0m"; 11 | exports.RED_LOG = "\x1b[31m%s\x1b[0m"; 12 | exports.GREEN_LOG = "\x1b[32m%s\x1b[0m"; 13 | exports.YELLOW_LOG = "\x1b[33m%s\x1b[0m"; 14 | exports.BLUE_LOG = "\x1b[34m%s\x1b[0m"; 15 | exports.MAGENTA_LOG = "\x1b[35m%s\x1b[0m"; 16 | exports.CYAN_LOG = "\x1b[36m%s\x1b[0m"; 17 | exports.WHITE_LOG = "\x1b[37m%s\x1b[0m"; 18 | 19 | // CODE STATUS 20 | exports.CODE_CONTINUE = 100; 21 | exports.CODE_SWITCHING_PROTOCOLS = 101; 22 | exports.CODE_PROCESSING = 102; 23 | exports.CODE_EARLYHINTS = 103; 24 | exports.CODE_OK = 200; 25 | exports.CODE_CREATED = 201; 26 | exports.CODE_ACCEPTED = 202; 27 | exports.CODE_NO_AUTHORITATIVE = 203; 28 | exports.CODE_NO_CONTENT = 204; 29 | exports.CODE_RESET_CONTENT = 205; 30 | exports.CODE_PARTIAL_CONTENT = 206; 31 | exports.CODE_MULTI_STATUS = 207; 32 | exports.CODE_ALREDY_REPORTED = 208; 33 | exports.CODE_IM_USED = 226; 34 | exports.CODE_MULTIPLE_CHOICES = 300; 35 | exports.CODE_MOVED_PERMANENTLY = 301; 36 | exports.CODE_FOUND = 302; 37 | exports.CODE_SEE_OTHER = 303; 38 | exports.CODE_NOT_MODIFIED = 304; 39 | exports.CODE_USE_PROXY = 305; 40 | exports.CODE_SWITCH_PROXY = 306; 41 | exports.CODE_TEMPORARY_REDIRECT = 307; 42 | exports.CODE_PERMANENT_REDIRECT = 308; 43 | exports.CODE_BAD_REQUEST = 400; 44 | exports.CODE_UNAUTHORIZED = 401; 45 | exports.CODE_PAYMENT_REQUIRED = 402; 46 | exports.CODE_FORBIDDEN = 403; 47 | exports.CODE_NOT_FOUND = 404; 48 | exports.CODE_METHOD_NOT_ALLOWED = 405; 49 | exports.CODE_NOT_ACEPTABLE = 406; 50 | exports.CODE_PROXY_AUTHENTICATION_REQUIRED = 407; 51 | exports.CODE_REQUEST_TIMEOUT = 408; 52 | exports.CODE_CONFLICT = 409; 53 | exports.CODE_GONE = 410; 54 | exports.CODE_LENGTH_REQUIRED = 411; 55 | exports.CODE_PRECONDITION_FAILED = 412; 56 | exports.CODE_PAYLOAD_TOO_LARGE = 413; 57 | exports.CODE_URI_TOO_LONG = 414; 58 | exports.CODE_UNSUPPORTED_MEDIA_TYPE = 415; 59 | exports.CODE_RANGE_NOT_SATISFIABLE = 416; 60 | exports.CODE_EXPECTATION_FAILED = 417; 61 | exports.CODE_IAM_A_TEAPOT = 418; 62 | exports.CODE_MISDIRECTED_REQUEST = 421; 63 | exports.CODE_UNPROCESSABLE_ENTITY = 422; 64 | exports.CODE_LOCKED = 423; 65 | exports.CODE_FAILED_DEPENDENCY = 424; 66 | exports.CODE_TOO_EARLY = 425; 67 | exports.CODE_UPGRADE_REQUIERED = 426; 68 | exports.CODE_PRECONDITION_REQUIRED = 428; 69 | exports.CODE_TOO_MANY_REQUESTS = 429; 70 | exports.CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; 71 | exports.CODE_UNAVAILABLE_FOR_LEGAL_REASONS = 451; 72 | exports.CODE_INTERNAL_SERVER_ERROR = 500; 73 | exports.CODE_NOT_IMPLEMENTED = 501; 74 | exports.CODE_BAD_GATEWAY = 502; 75 | exports.CODE_SERVICE_UNAVAILABLE = 503; 76 | exports.CODE_GETWAY_TIMEOUT = 504; 77 | exports.CODE_HTTP_VERSION_NOT_SUPPORTED = 505; 78 | exports.CODE_VARIANT_ALSO_NEGOTIATES = 506; 79 | exports.CODE_INSUFFICIENT_STORAGE = 507; 80 | exports.CODE_LOOP_DETECTED = 508; 81 | exports.CODE_NOT_EXTENDED = 509; 82 | exports.CODE_NETWORK_AUTHENTICATION_REQUIRED = 511; 83 | 84 | 85 | 86 | 87 | // RFC 88 | 89 | module.exports.VALIDATE_PROVIDER_CALL="ZRFC_ER_VALIDAR_PROVEEDOR"; -------------------------------------------------------------------------------- /util/magic.js: -------------------------------------------------------------------------------- 1 | const enum_ = require('./enum'); 2 | 3 | exports.ResponseService = async(status, errorCode, message, data)=>{ 4 | return await {status: status, Resp:{errorCode: errorCode, message: message, data: data}} 5 | 6 | } 7 | 8 | exports.LogSuccess = (msg) => { 9 | console.log(enum_.GREEN_LOG, msg); 10 | } 11 | exports.LogInfo = (msg) => { 12 | console.log(enum_.CYAN_LOG, msg); 13 | } 14 | exports.LogWarning = (msg) => { 15 | console.log(enum_.YELLOW_LOG, msg); 16 | } 17 | exports.LogDanger = (msg) => { 18 | console.log(enum_.RED_LOG, msg); 19 | } 20 | 21 | 22 | exports.ResponseService = async(status, code, message, data)=>{ 23 | return await {status: status, Resp:{Error: code, message: message, data: data}} 24 | 25 | } --------------------------------------------------------------------------------