Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

[enhancement] Use array in @post hooks #313

Closed
RyannGalea opened this issue Jul 2, 2019 · 2 comments
Closed

[enhancement] Use array in @post hooks #313

RyannGalea opened this issue Jul 2, 2019 · 2 comments

Comments

@RyannGalea
Copy link

RyannGalea commented Jul 2, 2019

I have instances where I want to achieve the same thing using different hooks but just end up having to duplicate the code, would it be possible or be a good idea to allow an array of hooks to do the same thing?

Currently:

      @Post<Contact>('save', (data) => addNotePost(data, Entities.CONTACT))
      @Post<Contact>('findOneAndUpdate', (data) => addNotePost(data, Entities.CONTACT))

Enhancement:

      @Post<Contact>(['save', 'findOneAndUpdate'], (data) => addNotePost(data, 
       Entities.CONTACT))
@hasezoey
Copy link
Contributor

hasezoey commented Jul 2, 2019

i think this is not within the scope of typegoose, but you could make a simple function like below:

function hookwrapper(next: () => void) {
    return addNotePost(next, Entities.CONTACT);
}

@Post<Contact>("save", hookwrapper)
@Post<Contact>("findOneAndUpdate", hookwrapper)

Note: this should work, but somehow i found that "save" and many others are not declared right (only "count" and "insertMany" are declared)

@hasezoey hasezoey mentioned this issue Jul 31, 2019
14 tasks
hasezoey referenced this issue in typegoose/typegoose Aug 5, 2019
- implemented szokodiakos#313
- refactored hooks's types for the new mongoose
- set rule "no-console" to warn instead of error (for debugging)
- set rule "unified-signatures" to false because otherwise it is not possible in hooks.ts (or would be ugly)

closes szokodiakos#313
hasezoey referenced this issue in typegoose/typegoose Aug 5, 2019
- implemented szokodiakos#313
- refactored hooks's types for the new mongoose
- set rule "no-console" to warn instead of error (for debugging)
- set rule "unified-signatures" to false because otherwise it is not possible in hooks.ts (or would be ugly)
- adding migration note for hooks

closes szokodiakos#313
@hasezoey
Copy link
Contributor

hasezoey commented Sep 8, 2019

@Ben305 this can be closed because it is included in v6.0.0

@Ben305 Ben305 closed this as completed Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants