mirror of
https://github.com/ComfortablyCoding/strapi-plugin-slugify.git
synced 2025-12-17 00:01:53 -05:00
* 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>
37 lines
996 B
JavaScript
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,
|
|
};
|