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

Add casts to NULL, IS NOT NULL, IN and BETWEEN to MongooseRepository #3

Closed
jlenon7 opened this issue Aug 30, 2021 · 0 comments · Fixed by #4
Closed

Add casts to NULL, IS NOT NULL, IN and BETWEEN to MongooseRepository #3

jlenon7 opened this issue Aug 30, 2021 · 0 comments · Fixed by #4
Assignees

Comments

@jlenon7
Copy link
Contributor

jlenon7 commented Aug 30, 2021

Example:

Object.keys(where).forEach(key => {
    let value = where[key];

    if (value === 'null') value = null
    if (value === '!null') value = { $ne: null }

    if (Array.isArray(value)) {
        value = { $in: value }
    }

    if (value.includes('->')) {
        const firstValue = value.split('->')[0].replace(/\s/g, '')
        const secondValue = value.split('->')[1].replace(/\s/g, '')

        value = { $gte: firstValue, $lte: secondValue }
    }

    query.where(key, value);
});
@jlenon7 jlenon7 self-assigned this Aug 30, 2021
@jlenon7 jlenon7 linked a pull request Aug 30, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant