Skip to content

Commit

Permalink
fix: load environment and environment alias
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Apr 7, 2020
1 parent 73b030c commit 4f5edfe
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/api-headless-cms/src/handler/plugins/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ export default () => {

// Before continuing with the rest of the models, we must load the environment and assign it to the context.
let environment = null;
let environmentAlias = null;
if (context.cms.environment && typeof context.cms.environment === "string") {
if (context.commodo.isId(context.cms.environment)) {
environment = await context.models.CmsEnvironment.findById(context.cms.environment);
} else {
environment = await context.models.CmsEnvironmentAlias.findOne({
environmentAlias = await context.models.CmsEnvironmentAlias.findOne({
query: { slug: context.cms.environment }
});
environment = await context.models.CmsEnvironmentAlias.environment;
environment = await environmentAlias.environment;
}
}

Expand All @@ -68,6 +69,7 @@ export default () => {

context.cms.environment = environment.slug;
context.cms.getEnvironment = () => environment;
context.cms.getEnvironmentAlias = () => environmentAlias;

const modifyQueryArgs = (args = {}) => {
const returnArgs = cloneDeep(args);
Expand Down

0 comments on commit 4f5edfe

Please sign in to comment.