Skip to content

Commit

Permalink
feat: implement createAction predicate rather than negating isSearchA…
Browse files Browse the repository at this point in the history
…ction predicate
  • Loading branch information
a-wallen committed Sep 25, 2024
1 parent e8908df commit 2d25661
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {{classname}} = require('../{{apiPackage}}/{{classname}}');
{{/apis}}
{{/apiInfo}}
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction, isCreateAction } = require('../utils/utils');

const actions = {
{{#apiInfo}}
Expand All @@ -19,6 +19,6 @@ const actions = {

module.exports = {
searchActions: () => Object.entries(actions).reduce((actions, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...actions, [key]: searchMiddleware(value)} : actions, {}),
createActions: () => Object.entries(actions).reduce((actions, [key, value]) => !isSearchAction(key) ? {...actions, [key]: value} : actions, {}),
createActions: () => Object.entries(actions).reduce((actions, [key, value]) => isCreateAction(key) ? {...actions, [key]: value} : actions, {}),
triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ module.exports = {
method: '{{httpMethod}}',
removeMissingValuesFrom: { params: true, body: true },
headers: {
'x-api-key': '{{=<% %>=}}{{bundle.authData.apiKey}}<%={{ }}=%>',
{{^isMultipart}}'Content-Type': '{{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}',{{/isMultipart}}
'Accept': '{{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const searchMiddleware = (action) => {
return action
}

const isCreateAction = (key) => {
// TODO: return true if the key is a "create" action for your API
return !isSearchAction(key);
}

const requestOptionsMiddleware = (z, bundle, requestOptions) => {
// TODO: modify the request options for all outgoing request to your api
// if you are using session authentication without a Bearer token.
Expand Down Expand Up @@ -50,4 +55,5 @@ module.exports = {
requestOptionsMiddleware: requestOptionsMiddleware,
isTrigger: isTrigger,
triggerMiddleware: triggerMiddleware,
isCreateAction: isCreateAction,
}

0 comments on commit 2d25661

Please sign in to comment.