2020-11-09 06:42:24 +00:00
|
|
|
// Automatic Genearted File for NopeModule
|
|
|
|
// To update run `npm run build:backend`
|
|
|
|
|
|
|
|
import { INopeDispatcher } from "{{pathOfDispatcher}}";
|
|
|
|
import { Operation } from "express-openapi";
|
|
|
|
|
|
|
|
export default function (_dispatcher: INopeDispatcher) {
|
|
|
|
|
|
|
|
let operations = {
|
2020-11-11 16:07:11 +00:00
|
|
|
{{mode}}
|
2020-11-09 06:42:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Function to Parse the Inputs
|
|
|
|
const parseParams = (req) => {
|
|
|
|
return [{{#each schema.inputs}}req.body.{{name}}{{#unless @last}}, {{/unless}}{{/each}}]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define the Action.
|
|
|
|
async function {{mode}}(req, res, next) {
|
|
|
|
try {
|
|
|
|
// Transform the Operation to the Callback of the Dispatcher.
|
2020-11-11 16:07:11 +00:00
|
|
|
const result = await _dispatcher.performCall('{{id}}', parseParams(req))
|
2020-11-09 06:42:24 +00:00
|
|
|
// Finish the Task.
|
|
|
|
res.status(200).json(result)
|
|
|
|
} catch (e) {
|
|
|
|
// An error Occourd =>
|
|
|
|
res.status(500).json(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define the apiDoc for this specific Funtion
|
|
|
|
{{mode}}.apiDoc = {
|
2020-11-11 16:07:11 +00:00
|
|
|
tags: ['{{tag}}'],
|
2020-11-09 06:42:24 +00:00
|
|
|
{{#if methodDescription}}summary: '{{methodDescription}}',{{/if}}
|
|
|
|
{{#if operationId}}operationId: '{{operationId}}',{{/if}}
|
|
|
|
parameters: [
|
2020-11-12 16:07:05 +00:00
|
|
|
{{#if hasInput}}
|
2020-11-09 06:42:24 +00:00
|
|
|
{
|
|
|
|
name: '{{name}}',
|
|
|
|
in: "body",
|
|
|
|
description: '{{description}}',
|
2020-11-12 16:07:05 +00:00
|
|
|
required: true,
|
|
|
|
schema: {{{parsedInput}}}
|
|
|
|
}
|
|
|
|
{{/if}}
|
2020-11-09 06:42:24 +00:00
|
|
|
],
|
|
|
|
responses: {
|
|
|
|
200: {
|
|
|
|
{{#if resultDescription}}description: '{{resultDescription}}',{{/if}}
|
|
|
|
schema: {{{parsedOutput}}}
|
|
|
|
},
|
|
|
|
default: {
|
|
|
|
description: 'An error occurred',
|
|
|
|
schema: {
|
|
|
|
additionalProperties: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} as Operation;
|
|
|
|
|
|
|
|
return operations;
|
|
|
|
}
|