使用订阅者(基于 TypeORM 的数据库)我找不到如何访问请求(让授权用户通过 Rest api 创建预订)
我尝试按照文档中的描述使用 Injectable ,但似乎在这里不起作用。
感谢帮助
预订.subscriber.ts
import { Inject, Injectable, Scope } from '@nestjs/common';
import { throwError } from 'rxjs';
import { Account } from 'src/accounts';
import { Room } from 'src/rooms';
import { TransactionEntity, TransactionsModule } from 'src/transactions';
import {
EventSubscriber,
EntitySubscriberInterface,
InsertEvent,
getRepository,
LessThan,
MoreThan,
} from 'typeorm';
import { Booking } from './booking.entity';
import { REQUEST } from '@nestjs/core';
import { Request } from 'express';
@EventSubscriber()
@Injectable({ scope: Scope.REQUEST })
export class BookingsSubscriber implements EntitySubscriberInterface<Booking> {
constructor(@Inject(REQUEST) private request: Request) {
console.log('request', this.request) // return undefined
}
listenTo() {
return Booking;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1989 次 |
| 最近记录: |