Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: validate & process values for composite #106

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/imports/mailConsumer/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import Mustache from 'mustache';
import { CronJob } from 'cron';
import BluebirdPromise from 'bluebird';
import { CronJob } from 'cron';
import Mustache from 'mustache';

import { createTransport } from 'nodemailer';
import smtpTransport from 'nodemailer-smtp-transport';

import isObject from 'lodash/isObject';
import extend from 'lodash/extend';
import omit from 'lodash/omit';
import isEmpty from 'lodash/isEmpty';
import get from 'lodash/get';
import has from 'lodash/has';
import isEmpty from 'lodash/isEmpty';
import isObject from 'lodash/isObject';
import join from 'lodash/join';
import map from 'lodash/map';
import omit from 'lodash/omit';
import range from 'lodash/range';
import set from 'lodash/set';

import { logger } from '../utils/logger';
import { MetaObject } from '@imports/model/MetaObject';
import { errorReturn, successReturn } from '../utils/return';
import { renderTemplate } from '../template';
import { logger } from '../utils/logger';
import { errorReturn, successReturn } from '../utils/return';

const MAIL_CONSUME_SCHEDULE = process.env.MAIL_CONSUME_SCHEDULE || '*/1 * * * * *';
const TZ = process.env.TZ || 'America/Sao_Paulo';
Expand Down Expand Up @@ -199,7 +199,7 @@ async function consume() {
await BluebirdPromise.each(range(0, mailCount), async () => {
const updatedRecords = await MetaObject.Collections['Message'].findOneAndUpdate(query, update, options);

if (updatedRecords.value == null) {
if (updatedRecords == null || updatedRecords.value == null) {
return;
}

Expand Down
30 changes: 20 additions & 10 deletions src/imports/meta/validateAndProcessValueFor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ import { hash as bcryptHash } from 'bcryptjs';

import { createHash } from 'crypto';

import has from 'lodash/has';
import isArray from 'lodash/isArray';
import isBoolean from 'lodash/isBoolean';
import isDate from 'lodash/isDate';
import isEqual from 'lodash/isEqual';
import isFunction from 'lodash/isFunction';
import isNumber from 'lodash/isNumber';
import isObject from 'lodash/isObject';
import isString from 'lodash/isString';
import isBoolean from 'lodash/isBoolean';
import has from 'lodash/has';
import size from 'lodash/size';
import isFunction from 'lodash/isFunction';
import isEqual from 'lodash/isEqual';
import isDate from 'lodash/isDate';
import omit from 'lodash/omit';
import size from 'lodash/size';

import { DateTime } from 'luxon';

import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
import { lowerCase } from 'lower-case';
import { titleCase } from 'title-case';
import { upperCase } from 'upper-case';
import { lowerCase } from 'lower-case';

import { MetaObject } from '@imports/model/MetaObject';
import { logger } from '../utils/logger';

import { removeInheritedFields } from '../meta/removeInheritedFields';
import { getNextCode } from './getNextCode';
import { stringToDate } from '../data/dateParser';
import { copyDescriptionAndInheritedFields } from '../meta/copyDescriptionAndInheritedFields';
import { removeInheritedFields } from '../meta/removeInheritedFields';
import { getNextCode } from './getNextCode';

import { BCRYPT_SALT_ROUNDS } from '../consts';

Expand Down Expand Up @@ -1006,7 +1006,17 @@ export async function validateAndProcessValueFor({ meta, fieldName, value, actio
const referenceDataValidationResults = await Promise.all(
Object.keys(value).map(async key => {
const subValue = value[key];
const validationResult = await validateAndProcessValueFor({ referenceMeta, key, subValue, actionType, value, idsToUpdate });
const params = {
meta: referenceMeta,
fieldName: key,
value: subValue,
actionType,
objectOriginalValues: value,
objectNewValues: value,
idsToUpdate
};

const validationResult = await validateAndProcessValueFor(params);
if (validationResult.success === false) {
return validationResult;
}
Expand Down
Loading