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

Help with inserting subdocuments #316

Closed
luke-robertson opened this issue Apr 9, 2019 · 1 comment
Closed

Help with inserting subdocuments #316

luke-robertson opened this issue Apr 9, 2019 · 1 comment

Comments

@luke-robertson
Copy link

luke-robertson commented Apr 9, 2019

Hello, iv spent the last 2 hours trying to figure this out

I have a table called issues with a array called tags : [ { value: '', label: '' }, { value: '', label: '' } ]

I started by patching this array with the old values + new values, but this means the user could edit the values on the front end technically

I then tried to use this inside a before hook on the patch :

context.app.service('issues').patch(id, { $push: { tags: data } })

But it either infinite looped or just deleted the table

How / where can i use this ?

Should it be on the before hook on a patch ?

Do i need a new API / service which will use the $push method?

@luke-robertson
Copy link
Author

if anyone visits this, i made a new custom service for this

looked like this :

class Service {
  constructor(options) {
    this.options = options || {}
    this.issues = options.issues
  }

  async patch(id, data, params) {
    await this.issues.patch(id, { $push: { [data.target]: data } })
    return await this.issues.get(id)
  }
}

module.exports = function(options) {
  return new Service(options)
}

module.exports.Service = Service

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

No branches or pull requests

1 participant