试图从 javascript 日期转换为 firestore 时间戳抛出
TypeError: Cannot read property 'Timestamp' of undefined
Run Code Online (Sandbox Code Playgroud)
我以两种方式尝试过:
const admin = require('firebase-admin');
const db = admin.firestore();
const timestamp = db.Timestamp.fromDate(new Date(date));
Run Code Online (Sandbox Code Playgroud)
const firebase = require('firebase');
const timestamp = firebase.firestore.Timestamp.fromDate(new Date(date));
Run Code Online (Sandbox Code Playgroud)
日期用作设置了一个param新日期的格式如下:“2017年1月29日”。
预期结果:firestore 时间戳。
实际结果:类型错误:无法读取未定义的属性“时间戳”
注意:db 和 firebase 为 null 或未定义。
是否有从 javascript 日期对象创建 firestore 时间戳的明确方法?
我有一个使用@Controller('tasks')装饰器的控制器。在这个控制器中,我有一个路由@Get('/week'),通常请求应该去localhost:4000/tasks/week但它返回一个错误的请求:
{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed (numeric string is expected)"
}
Run Code Online (Sandbox Code Playgroud)
下面是我的代码:
@Controller('tasks')
@UseGuards(AuthGuard())
export class TasksController {
constructor(private tasksService: TasksService) { }
@Get('/:id')
getTaskById(@Param('id', ParseIntPipe) id: number): Promise<Task> {
return this.tasksService.getTaskById(id);
}
@Get('/week')
getTasksByWeek(@GetUser() user: User): Promise<Task[]> {
return this.tasksService.getTasksByWeek(user);
}
Run Code Online (Sandbox Code Playgroud)
从 Get() 装饰器中删除/week有效但不添加它。
预期结果:返回数据
实际结果:
{
"statusCode": 400,
"error": "Bad Request",
"message": "Validation failed (numeric string is expected)"
}
Run Code Online (Sandbox Code Playgroud)