fixed mongodb type bug
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { Document, ObjectId } from "mongodb";
|
||||
import { ApiCall } from "tsrpc";
|
||||
import { Global } from "../models/Global";
|
||||
import { ReqAddPost, ResAddPost } from "../shared/protocols/PtlAddPost";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ReqDelPost, ResDelPost } from "../shared/protocols/PtlDelPost";
|
||||
|
||||
export async function ApiDelPost(call: ApiCall<ReqDelPost, ResDelPost>) {
|
||||
let op = await Global.collection('Post').deleteOne({
|
||||
_id: new ObjectId(call.req._id)
|
||||
_id: call.req._id
|
||||
})
|
||||
|
||||
call.succ({});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ReqGetPost, ResGetPost } from "../shared/protocols/PtlGetPost";
|
||||
|
||||
export async function ApiGetPost(call: ApiCall<ReqGetPost, ResGetPost>) {
|
||||
let op = await Global.collection('Post').findOne({
|
||||
_id: new ObjectId(call.req._id)
|
||||
_id: call.req._id
|
||||
});
|
||||
|
||||
if (!op) {
|
||||
@@ -16,7 +16,7 @@ export async function ApiGetPost(call: ApiCall<ReqGetPost, ResGetPost>) {
|
||||
call.succ({
|
||||
post: {
|
||||
...op,
|
||||
_id: op._id.toHexString()
|
||||
_id: op._id
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -7,7 +7,7 @@ export async function ApiUpdatePost(call: ApiCall<ReqUpdatePost, ResUpdatePost>)
|
||||
let { _id, ...update } = call.req.update;
|
||||
|
||||
let op = await Global.collection('Post').updateOne({
|
||||
_id: new ObjectId(_id)
|
||||
_id: _id
|
||||
}, {
|
||||
$set: {
|
||||
...update,
|
||||
|
||||
Reference in New Issue
Block a user