fixed mongodb type bug

This commit is contained in:
k8w
2022-01-11 21:16:25 +08:00
parent 5afb16e2bb
commit 6707825188
15 changed files with 56 additions and 47 deletions

View File

@@ -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";

View File

@@ -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({});

View File

@@ -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
}
})
}

View File

@@ -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,