From 5afb16e2bb21958b5a1a614156c3d05042d4fff4 Mon Sep 17 00:00:00 2001 From: k8w Date: Wed, 29 Dec 2021 22:48:25 +0800 Subject: [PATCH] ObjectID -> ObjectId --- examples/mongodb-crud/backend/.mocharc.js | 5 ++++- examples/mongodb-crud/backend/package.json | 15 ++++++++------- .../mongodb-crud/backend/src/api/ApiDelPost.ts | 4 ++-- .../mongodb-crud/backend/src/api/ApiGetPost.ts | 4 ++-- .../mongodb-crud/backend/src/api/ApiUpdatePost.ts | 4 ++-- .../mongodb-crud/backend/src/models/BackConfig.ts | 2 +- .../backend/src/models/dbItems/DbPost.ts | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/examples/mongodb-crud/backend/.mocharc.js b/examples/mongodb-crud/backend/.mocharc.js index b6cf8de..269695f 100644 --- a/examples/mongodb-crud/backend/.mocharc.js +++ b/examples/mongodb-crud/backend/.mocharc.js @@ -4,5 +4,8 @@ module.exports = { ], timeout: 999999, exit: true, - 'preserve-symlinks': true + 'preserve-symlinks': true, + spec: [ + './test/**/*.test.ts' + ] } \ No newline at end of file diff --git a/examples/mongodb-crud/backend/package.json b/examples/mongodb-crud/backend/package.json index b52ba9c..44b0e74 100644 --- a/examples/mongodb-crud/backend/package.json +++ b/examples/mongodb-crud/backend/package.json @@ -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" } } \ No newline at end of file diff --git a/examples/mongodb-crud/backend/src/api/ApiDelPost.ts b/examples/mongodb-crud/backend/src/api/ApiDelPost.ts index 90cbbd5..0c654a3 100644 --- a/examples/mongodb-crud/backend/src/api/ApiDelPost.ts +++ b/examples/mongodb-crud/backend/src/api/ApiDelPost.ts @@ -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) { let op = await Global.collection('Post').deleteOne({ - _id: new ObjectID(call.req._id) + _id: new ObjectId(call.req._id) }) call.succ({}); diff --git a/examples/mongodb-crud/backend/src/api/ApiGetPost.ts b/examples/mongodb-crud/backend/src/api/ApiGetPost.ts index 1bf035e..53232d6 100644 --- a/examples/mongodb-crud/backend/src/api/ApiGetPost.ts +++ b/examples/mongodb-crud/backend/src/api/ApiGetPost.ts @@ -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) { let op = await Global.collection('Post').findOne({ - _id: new ObjectID(call.req._id) + _id: new ObjectId(call.req._id) }); if (!op) { diff --git a/examples/mongodb-crud/backend/src/api/ApiUpdatePost.ts b/examples/mongodb-crud/backend/src/api/ApiUpdatePost.ts index 4cddbaa..ef2d66b 100644 --- a/examples/mongodb-crud/backend/src/api/ApiUpdatePost.ts +++ b/examples/mongodb-crud/backend/src/api/ApiUpdatePost.ts @@ -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) let { _id, ...update } = call.req.update; let op = await Global.collection('Post').updateOne({ - _id: new ObjectID(_id) + _id: new ObjectId(_id) }, { $set: { ...update, diff --git a/examples/mongodb-crud/backend/src/models/BackConfig.ts b/examples/mongodb-crud/backend/src/models/BackConfig.ts index 4ff60d0..ba42a27 100644 --- a/examples/mongodb-crud/backend/src/models/BackConfig.ts +++ b/examples/mongodb-crud/backend/src/models/BackConfig.ts @@ -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', } \ No newline at end of file diff --git a/examples/mongodb-crud/backend/src/models/dbItems/DbPost.ts b/examples/mongodb-crud/backend/src/models/dbItems/DbPost.ts index f7585bd..ca4b8f3 100644 --- a/examples/mongodb-crud/backend/src/models/dbItems/DbPost.ts +++ b/examples/mongodb-crud/backend/src/models/dbItems/DbPost.ts @@ -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 \ No newline at end of file