ObjectID -> ObjectId
This commit is contained in:
parent
748d64254e
commit
5afb16e2bb
@ -4,5 +4,8 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
timeout: 999999,
|
timeout: 999999,
|
||||||
exit: true,
|
exit: true,
|
||||||
'preserve-symlinks': true
|
'preserve-symlinks': true,
|
||||||
|
spec: [
|
||||||
|
'./test/**/*.test.ts'
|
||||||
|
]
|
||||||
}
|
}
|
@ -9,20 +9,21 @@
|
|||||||
"api": "tsrpc api",
|
"api": "tsrpc api",
|
||||||
"doc": "tsrpc doc",
|
"doc": "tsrpc doc",
|
||||||
"dev": "tsrpc dev",
|
"dev": "tsrpc dev",
|
||||||
"build": "tsrpc build"
|
"build": "tsrpc build",
|
||||||
|
"test": "mocha"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/mocha": "^8.2.3",
|
"@types/mocha": "^8.2.3",
|
||||||
"@types/mongodb": "^3.6.20",
|
"@types/mongodb": "^3.6.20",
|
||||||
"@types/node": "^15.14.9",
|
"@types/node": "^15.14.9",
|
||||||
"mocha": "^9.1.2",
|
"mocha": "^9.1.3",
|
||||||
"onchange": "^7.1.0",
|
"onchange": "^7.1.0",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.4.0",
|
||||||
"tsrpc-cli": "^2.0.8",
|
"tsrpc-cli": "^2.3.1",
|
||||||
"typescript": "^4.4.3"
|
"typescript": "^4.5.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mongodb": "^3.7.2",
|
"mongodb": "^4.2.2",
|
||||||
"tsrpc": "^3.0.9"
|
"tsrpc": "^3.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
import { ObjectID } from 'mongodb';
|
import { ObjectId } from 'mongodb';
|
||||||
import { ApiCall } from "tsrpc";
|
import { ApiCall } from "tsrpc";
|
||||||
import { Global } from "../models/Global";
|
import { Global } from "../models/Global";
|
||||||
import { ReqDelPost, ResDelPost } from "../shared/protocols/PtlDelPost";
|
import { ReqDelPost, ResDelPost } from "../shared/protocols/PtlDelPost";
|
||||||
|
|
||||||
export async function ApiDelPost(call: ApiCall<ReqDelPost, ResDelPost>) {
|
export async function ApiDelPost(call: ApiCall<ReqDelPost, ResDelPost>) {
|
||||||
let op = await Global.collection('Post').deleteOne({
|
let op = await Global.collection('Post').deleteOne({
|
||||||
_id: new ObjectID(call.req._id)
|
_id: new ObjectId(call.req._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
call.succ({});
|
call.succ({});
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ObjectID } from 'mongodb';
|
import { ObjectId } from 'mongodb';
|
||||||
import { ApiCall } from "tsrpc";
|
import { ApiCall } from "tsrpc";
|
||||||
import { Global } from "../models/Global";
|
import { Global } from "../models/Global";
|
||||||
import { ReqGetPost, ResGetPost } from "../shared/protocols/PtlGetPost";
|
import { ReqGetPost, ResGetPost } from "../shared/protocols/PtlGetPost";
|
||||||
|
|
||||||
export async function ApiGetPost(call: ApiCall<ReqGetPost, ResGetPost>) {
|
export async function ApiGetPost(call: ApiCall<ReqGetPost, ResGetPost>) {
|
||||||
let op = await Global.collection('Post').findOne({
|
let op = await Global.collection('Post').findOne({
|
||||||
_id: new ObjectID(call.req._id)
|
_id: new ObjectId(call.req._id)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!op) {
|
if (!op) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ObjectID } from 'mongodb';
|
import { ObjectId } from 'mongodb';
|
||||||
import { ApiCall } from "tsrpc";
|
import { ApiCall } from "tsrpc";
|
||||||
import { Global } from "../models/Global";
|
import { Global } from "../models/Global";
|
||||||
import { ReqUpdatePost, ResUpdatePost } from "../shared/protocols/PtlUpdatePost";
|
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 { _id, ...update } = call.req.update;
|
||||||
|
|
||||||
let op = await Global.collection('Post').updateOne({
|
let op = await Global.collection('Post').updateOne({
|
||||||
_id: new ObjectID(_id)
|
_id: new ObjectId(_id)
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
...update,
|
...update,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export const BackConfig = {
|
export const BackConfig = {
|
||||||
// Please replace by your db
|
// 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',
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { ObjectID } from "mongodb";
|
import { ObjectId } from "mongodb";
|
||||||
import { Overwrite } from "tsrpc";
|
import { Overwrite } from "tsrpc";
|
||||||
import { Post } from "../../shared/protocols/models/Post";
|
import { Post } from "../../shared/protocols/models/Post";
|
||||||
|
|
||||||
export type DbPost = Overwrite<Post, {
|
export type DbPost = Overwrite<Post, {
|
||||||
_id: ObjectID
|
_id: ObjectId
|
||||||
}>
|
}>
|
Loading…
x
Reference in New Issue
Block a user