当我尝试通过@ odata.body使用PATCH
或PUT HTTP
请求来访问正文数据时,出现了“超出最大调用堆栈大小”的信息。
我试图对此PATCH请求https://www.npmjs.com/package/odata-v4-server做出类似的操作,但是没有用。 我试图用PUT更改PATCH,但还是没有。
import { ODataController, Edm, odata} from "odata-v4-server";
import { User } from "../model/User";
import "reflect-metadata";
import { ObjectID } from "mongodb";
import connection from "../connection";
@odata.type(User)
@Edm.EntitySet("User")
export class UsersController extends ODataController {
@odata.GET
async findOne(@odata.key key: string): Promise<User> {
const connect = await connection();
return connect.getRepository(User).findOne({_id:key});
}
@odata.POST
async create():Promise<User>{
const connect = await connection();
var key = new ObjectID();
return await connect.getRepository(User).save({_id: key.toString()});
}
@odata.PATCH
async update(@odata.body delta:any){
console.log(delta);
}
@odata.DELETE
async remove(@odata.key key:string) {
const connect = await connection();
await connect.getRepository(User).delete({username:key})
}
}
GET, POST and DELETE
工作正常,但PATCH
不能正常工作。