ui: add ProblemSelectAutoComplete

This commit is contained in:
undefined committed 2021-04-11 18:22:47 +08:00
1 parent 1c89596cb3
commit 90443546c8
7 files changed
+80 -3

No files matched your search

+8 -1
View File
@@ -1,6 +1,6 @@
import type { Readable } from 'stream';
import { ObjectID, FilterQuery } from 'mongodb';
import { Dictionary, pick } from 'lodash';
import { Dictionary, escapeRegExp, pick } from 'lodash';
import { STATUS } from './builtin';
import * as document from './document';
import domain from './domain';
@@ -208,6 +208,13 @@ export class ProblemModel {
return Object.assign(r, l);
}
static async getPrefixList(domainId: string, prefix: string) {
prefix = prefix.toLowerCase();
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }] };
return await document.getMulti(domainId, document.TYPE_PROBLEM, filter, ['domainId', 'docId', 'pid', 'title']).toArray();
}
static async getListStatus(domainId: string, uid: number, pids: number[]) {
const psdocs = await ProblemModel.getMultiStatus(
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },