mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: update to mongodb5 (#514)
This commit is contained in:
1 parent
5a02010120
commit
0685b88066
59 files changed
+610
-601
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { SolutionNotFoundError } from '../error';
|
||||
import * as bus from '../service/bus';
|
||||
import * as document from './document';
|
||||
@@ -11,7 +11,7 @@ class SolutionModel {
|
||||
);
|
||||
}
|
||||
|
||||
static async get(domainId: string, psid: ObjectID) {
|
||||
static async get(domainId: string, psid: ObjectId) {
|
||||
const psdoc = await document.get(domainId, document.TYPE_PROBLEM_SOLUTION, psid);
|
||||
if (!psdoc) throw new SolutionNotFoundError(domainId, psid);
|
||||
return psdoc;
|
||||
@@ -24,11 +24,11 @@ class SolutionModel {
|
||||
.toArray();
|
||||
}
|
||||
|
||||
static edit(domainId: string, psid: ObjectID, content: string) {
|
||||
static edit(domainId: string, psid: ObjectId, content: string) {
|
||||
return document.set(domainId, document.TYPE_PROBLEM_SOLUTION, psid, { content });
|
||||
}
|
||||
|
||||
static async del(domainId: string, psid: ObjectID) {
|
||||
static async del(domainId: string, psid: ObjectId) {
|
||||
return await Promise.all([
|
||||
document.deleteOne(domainId, document.TYPE_PROBLEM_SOLUTION, psid),
|
||||
document.deleteMultiStatus(domainId, document.TYPE_PROBLEM_SOLUTION, { docId: psid }),
|
||||
@@ -53,23 +53,23 @@ class SolutionModel {
|
||||
).sort({ _id: -1 });
|
||||
}
|
||||
|
||||
static reply(domainId: string, psid: ObjectID, owner: number, content: string) {
|
||||
static reply(domainId: string, psid: ObjectId, owner: number, content: string) {
|
||||
return document.push(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'reply', content, owner);
|
||||
}
|
||||
|
||||
static getReply(domainId: string, psid: ObjectID, psrid: ObjectID) {
|
||||
static getReply(domainId: string, psid: ObjectId, psrid: ObjectId) {
|
||||
return document.getSub(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'reply', psrid);
|
||||
}
|
||||
|
||||
static editReply(domainId: string, psid: ObjectID, psrid: ObjectID, content: string) {
|
||||
static editReply(domainId: string, psid: ObjectId, psrid: ObjectId, content: string) {
|
||||
return document.setSub(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'reply', psrid, { content });
|
||||
}
|
||||
|
||||
static delReply(domainId: string, psid: ObjectID, psrid: ObjectID) {
|
||||
static delReply(domainId: string, psid: ObjectId, psrid: ObjectId) {
|
||||
return document.deleteSub(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'reply', psrid);
|
||||
}
|
||||
|
||||
static async vote(domainId: string, psid: ObjectID, uid: number, value: number) {
|
||||
static async vote(domainId: string, psid: ObjectId, uid: number, value: number) {
|
||||
let pssdoc = await document.getStatus(domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid);
|
||||
await document.setStatus(domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid, { vote: value });
|
||||
if (pssdoc) value += -pssdoc.vote;
|
||||
@@ -78,11 +78,11 @@ class SolutionModel {
|
||||
return [psdoc, pssdoc];
|
||||
}
|
||||
|
||||
static async getListStatus(domainId: string, psids: ObjectID[], uid: number) {
|
||||
const result: Record<string, { docId: ObjectID, vote: number }> = {};
|
||||
static async getListStatus(domainId: string, psids: ObjectId[], uid: number) {
|
||||
const result: Record<string, { docId: ObjectId, vote: number }> = {};
|
||||
const res = await document.getMultiStatus(
|
||||
domainId, document.TYPE_PROBLEM_SOLUTION, { uid, docId: { $in: psids } },
|
||||
).project({ docId: 1, vote: 1 }).toArray();
|
||||
).project<any>({ docId: 1, vote: 1 }).toArray();
|
||||
for (const i of res) result[i.docId] = i;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user