Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((newsItem) => {
const errMessages = [];
const profile = planningProfile(this.store.getState());
const schema = get(profile, 'schema') || DEFAULT_PLANNING_SCHEMA;
const requiredError = (field) => this.gettext('[{{ field }}] is a required field')
.replace('{{ field }}', field);
const labels = GET_LABEL_MAP(this.gettext);
if (get(newsItem, 'assignment_id')) {
errMessages.push(this.gettext('Item already linked to a Planning item'));
}
Object.keys(schema)
.filter((field) => DEFAULT_SCHEMA.hasOwnProperty(field)) // filter out planning only fields
.filter((field) => get(schema[field], 'required') &&
isEmpty(get(newsItem, field)) &&
!isNumber(get(newsItem, field)))
.forEach((field) => {
errMessages.push(requiredError(labels[field] || field));
});
if (errMessages.length) {
errMessages.forEach((err) => {