strapi-plugin-slugify/server/utils/isValidFindSlugParams.js
Max Starr 38292fedd3
fix: broken imports due to change in strapi (#99)
* refactor broken imports

* update package info

* update package name

* fix other broken import

* fix(pkg.json): revert changes

* fix(santizeOutput): update import

* fix: namespace error imports

---------

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
2023-07-07 16:46:37 -04:00

37 lines
996 B
JavaScript

const { ValidationError } = require('@strapi/utils').errors;
const _ = require('lodash');
const isValidFindSlugParams = (params) => {
if (!params) {
throw new ValidationError('A model and slug must be provided.');
}
const { modelName, slug, modelsByName, publicationState } = params;
const model = modelsByName[modelName];
if (!modelName) {
throw new ValidationError('A model name path variable is required.');
}
if (!slug) {
throw new ValidationError('A slug path variable is required.');
}
if (!_.get(model, ['contentType', 'options', 'draftAndPublish'], false) && publicationState) {
throw new ValidationError(
'Filtering by publication state is only supported for content types that have Draft and Publish enabled.'
);
}
// ensure valid model is passed
if (!model) {
throw new ValidationError(
`${modelName} model name not found, all models must be defined in the settings and are case sensitive.`
);
}
};
module.exports = {
isValidFindSlugParams,
};