generated from Greenstand/treetracker-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
639 additions
and
5 deletions.
There are no files selected for viewing
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
const j2s = require('joi-to-swagger'); | ||
const { | ||
appConfigPostSchema, | ||
activateAppConfigSchema, | ||
appConfigGetQuerySchema, | ||
appInstallationsGetQuerySchema, | ||
} = require('./schemas'); | ||
|
||
const { swagger: configPostSchema } = j2s(appConfigPostSchema); | ||
const { swagger: configGetSchema } = j2s(appConfigGetQuerySchema); | ||
const { swagger: installationGetSchema } = j2s(appInstallationsGetQuerySchema); | ||
const { swagger: activateConfigSchema } = j2s(activateAppConfigSchema); | ||
|
||
const appConfigResponse = { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/AppConfig', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const appConfigSwagger = { | ||
'/app_config': { | ||
get: { | ||
tags: ['app_config'], | ||
summary: 'get all app configs', | ||
parameters: [ | ||
{ | ||
schema: { | ||
...configGetSchema, | ||
}, | ||
in: 'query', | ||
name: 'query', | ||
description: 'Allowed query parameters', | ||
}, | ||
], | ||
responses: { | ||
200: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
appConfigs: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/AppConfig', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
post: { | ||
tags: ['app_config'], | ||
summary: 'create a new app config', | ||
requestBody: { | ||
content: { | ||
'application/json': { | ||
schema: { ...configPostSchema }, | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
201: appConfigResponse, | ||
}, | ||
}, | ||
}, | ||
'/app_installation': { | ||
get: { | ||
tags: ['app_config'], | ||
summary: 'get all app installations', | ||
parameters: [ | ||
{ | ||
schema: { | ||
...installationGetSchema, | ||
}, | ||
in: 'query', | ||
name: 'query', | ||
description: 'Allowed query parameters', | ||
}, | ||
], | ||
responses: { | ||
200: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
appInstallations: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/AppInstallation', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
'/activate_app_config': { | ||
post: { | ||
tags: ['app_config'], | ||
summary: 'bind a wallet to an app_config', | ||
requestBody: { | ||
content: { | ||
'application/json': { | ||
schema: { ...activateConfigSchema }, | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
201: appConfigResponse, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const appConfigComponent = { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string', format: 'uuid' }, | ||
config_code: { type: 'string' }, | ||
stakeholder_id: { type: 'string', format: 'uuid' }, | ||
org_name: { type: 'string' }, | ||
capture_flow: { type: 'object' }, | ||
capture_setup_flow: { type: 'object' }, | ||
created_at: { type: 'string', format: 'date-time' }, | ||
updated_at: { type: 'string', format: 'date-time' }, | ||
app_installation_count: { type: 'number' }, | ||
}, | ||
}; | ||
|
||
const appInstallationComponent = { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string', format: 'uuid' }, | ||
wallet: { type: 'string' }, | ||
app_config_id: { type: 'string', format: 'uuid' }, | ||
config_code: { type: 'string' }, | ||
created_at: { type: 'string', format: 'date-time' }, | ||
latest_login_at: { type: 'string', format: 'date-time' }, | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
appConfigComponent, | ||
appInstallationComponent, | ||
appConfigSwagger, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const AppConfigService = require('../../services/AppConfigService'); | ||
const { | ||
getFilterAndLimitOptions, | ||
generatePrevAndNext, | ||
} = require('../../utils/helper'); | ||
const { | ||
appConfigPostSchema, | ||
activateAppConfigSchema, | ||
appConfigGetQuerySchema, | ||
appInstallationsGetQuerySchema, | ||
} = require('./schemas'); | ||
|
||
const appInstallationGet = async (req, res) => { | ||
await appInstallationsGetQuerySchema.validateAsync(req.query, { | ||
abortEarly: false, | ||
}); | ||
|
||
const { filter, limitOptions } = getFilterAndLimitOptions(req.query); | ||
const appConfigService = new AppConfigService(); | ||
|
||
const { appInstallations, totalCount } = | ||
await appConfigService.getAppInstallations(filter, limitOptions); | ||
|
||
const url = 'app_installation'; | ||
|
||
const links = generatePrevAndNext({ | ||
url, | ||
count: totalCount, | ||
limitOptions, | ||
queryObject: { ...filter, ...limitOptions }, | ||
}); | ||
|
||
res.send({ | ||
appInstallations, | ||
links, | ||
totalCount, | ||
query: { ...limitOptions, ...filter }, | ||
}); | ||
}; | ||
|
||
const appConfigGet = async (req, res) => { | ||
await appConfigGetQuerySchema.validateAsync(req.query, { | ||
abortEarly: false, | ||
}); | ||
|
||
const { filter, limitOptions } = getFilterAndLimitOptions(req.query); | ||
const appConfigService = new AppConfigService(); | ||
|
||
const { appConfigs, totalCount } = await appConfigService.getAppConfigs( | ||
filter, | ||
limitOptions, | ||
); | ||
|
||
const url = 'app_config'; | ||
|
||
const links = generatePrevAndNext({ | ||
url, | ||
count: totalCount, | ||
limitOptions, | ||
queryObject: { ...filter, ...limitOptions }, | ||
}); | ||
|
||
res.send({ | ||
appConfigs, | ||
links, | ||
totalCount, | ||
query: { ...limitOptions, ...filter }, | ||
}); | ||
}; | ||
|
||
const appConfigPost = async function (req, res) { | ||
await appConfigPostSchema.validateAsync(req.body, { | ||
abortEarly: false, | ||
}); | ||
|
||
const appConfigService = new AppConfigService(); | ||
const result = await appConfigService.createAppConfig(req.body); | ||
|
||
res.send(result); | ||
}; | ||
|
||
const activateAppConfig = async function (req, res) { | ||
await activateAppConfigSchema.validateAsync(req.body, { | ||
abortEarly: false, | ||
}); | ||
|
||
const appConfigService = new AppConfigService(); | ||
const result = await appConfigService.activateAppConfig(req.body); | ||
|
||
res.send(result); | ||
}; | ||
|
||
module.exports = { | ||
appInstallationGet, | ||
appConfigGet, | ||
appConfigPost, | ||
activateAppConfig, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const Joi = require('joi'); | ||
|
||
const appConfigPostSchema = Joi.object({ | ||
stakeholder_id: Joi.string().uuid().required(), | ||
config_code: Joi.string().alphanum().required(), | ||
capture_flow: Joi.object(), | ||
capture_setup_flow: Joi.object(), | ||
}); | ||
|
||
const activateAppConfigSchema = Joi.object({ | ||
wallet: Joi.string().required(), | ||
config_code: Joi.string().alphanum().required(), | ||
}); | ||
|
||
const appConfigGetQuerySchema = Joi.object({ | ||
stakeholder_id: Joi.string().uuid(), | ||
config_code: Joi.string().alphanum(), | ||
limit: Joi.number().integer().min(1), | ||
offset: Joi.number().integer().min(0), | ||
}); | ||
|
||
const appInstallationsGetQuerySchema = Joi.object({ | ||
wallet: Joi.string(), | ||
stakeholder_id: Joi.string().uuid(), | ||
config_code: Joi.string().alphanum(), | ||
limit: Joi.number().integer().min(1), | ||
offset: Joi.number().integer().min(0), | ||
}); | ||
|
||
module.exports = { | ||
appConfigPostSchema, | ||
activateAppConfigSchema, | ||
appConfigGetQuerySchema, | ||
appInstallationsGetQuerySchema, | ||
}; |
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
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
Oops, something went wrong.