Created
October 20, 2020 15:11
-
-
Save goldytech/1ca35374f497d738621ca17e7e5e7fc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const db = require("../database"); | |
/** | |
* @typedef {import('moleculer').Context} Context Moleculer's Context | |
*/ | |
module.exports = { | |
name: "greeter", | |
/** | |
* Settings | |
*/ | |
settings: { | |
}, | |
/** | |
* Dependencies | |
*/ | |
dependencies: [], | |
/** | |
* Actions | |
*/ | |
actions: { | |
/** | |
* Say a 'Hello' action. | |
* | |
* @returns | |
*/ | |
hello: { | |
rest: { | |
method: "GET", | |
path: "/hello" | |
}, | |
async handler() { | |
return "Hello Moleculer"; | |
} | |
}, | |
/** | |
* Welcome, a username | |
* | |
* @param {String} name - User name | |
*/ | |
welcome: { | |
rest: "/welcome", | |
params: { | |
name: "string" | |
}, | |
/** @param {Context} ctx */ | |
async handler(ctx) { | |
return `Welcome, ${ctx.params.name}`; | |
} | |
} | |
}, | |
/** | |
* Events | |
*/ | |
events: { | |
}, | |
/** | |
* Methods | |
*/ | |
methods: { | |
}, | |
/** | |
* Service created lifecycle event handler | |
*/ | |
async created() { | |
await db.sequelize.sync({alter:true}); | |
}, | |
/** | |
* Service started lifecycle event handler | |
*/ | |
async started() { | |
}, | |
/** | |
* Service stopped lifecycle event handler | |
*/ | |
async stopped() { | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment