我将Nestjs与firebase admin集成在一起,控制器未更新视图。使用该服务没有问题,请实时更新。
有人会提出一些建议,我的代码有什么问题?
注入控制器的服务是:
import { Injectable } from '@nestjs/common';
import * as admin from 'firebase-admin';
export interface Customer {
direction: string,
codLegal: string,
phone: string,
name: string
}
export interface CustomerId extends Customer{
id: string;
}
@Injectable()
export class CustomerService {
constructor() {}
findCustomers(): Promise<any>{
return new Promise((resolve, reject) => {
admin.firestore().collection('/data/LYvBew5FDpjLqcQjA2Ra/info')
.onSnapshot((querySnapshot) => {
const promises: any = [];
querySnapshot.forEach((doc: any) => {
promises.push({
id: doc.id,
data: doc.data() as Customer,
});
});
console.log(promises);
resolve(promises);
})
});
}
}
**基本控制器是:**
import { Controller, Get } from '@nestjs/common';
import { CustomerService } from './services/customer.service';
@Controller('customers') export class CustomerController {
constructor(private readonly customerService: CustomerService) {
}
@Get()
async findAll() {
try {
return await this.customerService.findCustomers();
}catch(err) {
console.log(err);
}
}
}
答案 0 :(得分:0)
就HTTP而言,控制器将不会更新视图。调用findAll路由并将其发送到客户端后,将呈现该视图。
如果您想实时显示视图更新,则应将Firebase包含在前端中。