Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Oyentes Typeorm con parámetros

¿Es posible usar oyentes TypeORM con parámetros?

Ejemplo:

 @BeforeInsert() public async doSomething(myImportantParam) { // using myImportantParam here }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Como en la documentación de @BeforeInsert , no le permite agregar ningún parámetro al oyente.

Sin embargo, creo que puede crear un constructor para su entidad que tome myImportantParam como argumento y puede usar this.myImportantParam para acceder al valor dentro del oyente.

A continuación se muestra un código de ejemplo (supongamos que myImportantParam es una cadena).

clase de entidad:

 @Entity() export class Post { constructor(myImportantParam: string) { this.myImportantParam = myImportantParam; } myImportantParam: string; @BeforeInsert() updateDates() { // Now you can use `this.myImportantParam` to access your value foo(this.myImportantParam); } /*... more code here ...*/ }

Clase de servicio:

 export class PostService { async addNewPost() { const myImportantParam = 'This is what I need!'; const post = new Post(myImportantParam); // Add any other properties the post might have /*... more code here ...*/ // Insert the updated post await getRepository(Post).insert(post); } /*... more code here ...*/ }

Espero que esto ayude. Salud 🍻 !!!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!