ObjectID -> ObjectId

This commit is contained in:
k8w 2021-12-29 22:48:25 +08:00
parent 748d64254e
commit 5afb16e2bb
7 changed files with 21 additions and 17 deletions

View File

@ -4,5 +4,8 @@ module.exports = {
],
timeout: 999999,
exit: true,
'preserve-symlinks': true
'preserve-symlinks': true,
spec: [
'./test/**/*.test.ts'
]
}

View File

@ -9,20 +9,21 @@
"api": "tsrpc api",
"doc": "tsrpc doc",
"dev": "tsrpc dev",
"build": "tsrpc build"
"build": "tsrpc build",
"test": "mocha"
},
"devDependencies": {
"@types/mocha": "^8.2.3",
"@types/mongodb": "^3.6.20",
"@types/node": "^15.14.9",
"mocha": "^9.1.2",
"mocha": "^9.1.3",
"onchange": "^7.1.0",
"ts-node": "^10.2.1",
"tsrpc-cli": "^2.0.8",
"typescript": "^4.4.3"
"ts-node": "^10.4.0",
"tsrpc-cli": "^2.3.1",
"typescript": "^4.5.4"
},
"dependencies": {
"mongodb": "^3.7.2",
"tsrpc": "^3.0.9"
"mongodb": "^4.2.2",
"tsrpc": "^3.1.4"
}
}

View File

@ -1,11 +1,11 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import { ApiCall } from "tsrpc";
import { Global } from "../models/Global";
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: new ObjectId(call.req._id)
})
call.succ({});

View File

@ -1,11 +1,11 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import { ApiCall } from "tsrpc";
import { Global } from "../models/Global";
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: new ObjectId(call.req._id)
});
if (!op) {

View File

@ -1,4 +1,4 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import { ApiCall } from "tsrpc";
import { Global } from "../models/Global";
import { ReqUpdatePost, ResUpdatePost } from "../shared/protocols/PtlUpdatePost";
@ -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: new ObjectId(_id)
}, {
$set: {
...update,

View File

@ -1,4 +1,4 @@
export const BackConfig = {
// Please replace by your db
mongoDb: 'mongodb://username:password@xxx.com:27017/test?authSource=admin',
mongoDb: 'mongodb+srv://test:test@tsrpc-example.0gzai.mongodb.net/tsrpc-example?retryWrites=true&w=majority',
}

View File

@ -1,7 +1,7 @@
import { ObjectID } from "mongodb";
import { ObjectId } from "mongodb";
import { Overwrite } from "tsrpc";
import { Post } from "../../shared/protocols/models/Post";
export type DbPost = Overwrite<Post, {
_id: ObjectID
_id: ObjectId
}>