修复 @param 在类扩展时作用域污染的问题,完善interface

This commit is contained in:
undefined committed 2020-07-11 13:35:28 +08:00
1 parent cd6938dd6c
commit dd7914e1fb
31 files changed
+269 -179

No files matched your search

+1
View File
@@ -609,6 +609,7 @@ export const USER_GENDER_ICONS = {
};
global.Hydro.model.builtin = {
Permission,
PERM,
PERMS,
PERMS_BY_FAMILY,
+1 -1
View File
@@ -531,7 +531,7 @@ export function getMulti(domainId: string, query = {}, type = document.TYPE_CONT
return document.getMulti(domainId, type, query);
}
export function _getStatusJournal(tsdoc) {
function _getStatusJournal(tsdoc) {
return tsdoc.journal.sort((a, b) => (a.rid.generationTime - b.rid.generationTime));
}
+1
View File
@@ -222,6 +222,7 @@ global.Hydro.model.discussion = {
setStar,
getStatus,
addNode,
getNode,
getNodes,
getVnode,
getListVnodes,
-2
View File
@@ -417,5 +417,3 @@ global.Hydro.model.document = {
TYPE_FILE,
TYPE_TRAINING,
};
export default global.Hydro.model.document;
+2 -17
View File
@@ -3,26 +3,10 @@ import { STATUS } from './builtin';
import * as file from './file';
import * as document from './document';
import * as domain from './domain';
import { Pdoc } from '../interface';
import { ProblemNotFoundError } from '../error';
import readConfig from '../lib/readConfig';
export interface Pdoc {
_id: ObjectID
domainId: string
docId: number
pid: string
owner: number
title: string
content: string
nSubmit: number
nAccept: number
tag: string[]
category: string[],
data: ObjectID | null
hidden: boolean
config: string
}
export const pdocHidden: Pdoc = {
_id: new ObjectID(),
domainId: 'system',
@@ -180,6 +164,7 @@ export async function setTestdata(domainId: string, _id: number, filePath: strin
}
global.Hydro.model.problem = {
pdocHidden,
add,
inc,
get,
+9 -37
View File
@@ -1,45 +1,15 @@
import _ from 'lodash';
import yaml from 'js-yaml';
import { ObjectID, FilterQuery } from 'mongodb';
import { ObjectID } from 'mongodb';
import { STATUS } from './builtin';
import * as task from './task';
import * as problem from './problem';
import { Rdoc, TestCase } from '../interface';
import { RecordNotFoundError } from '../error';
import * as db from '../service/db';
const coll = db.collection('record');
export interface TestCase {
time: number,
memory: number,
status: number,
message: string,
}
export interface Rdoc {
_id: ObjectID,
domainId: string,
pid: ObjectID
uid: number,
lang: string,
code: string,
score: number,
memory: number,
time: number,
judgeTexts: string[],
compilerTexts: string[],
testCases: TestCase[],
rejudged: boolean,
judger: string,
judgeAt: Date,
status: number,
type: string,
hidden: boolean,
input?: string,
tid?: ObjectID,
ttype?: number,
}
export interface RdocBase {
_id?: ObjectID,
domainId?: string,
@@ -119,7 +89,7 @@ export async function add(domainId: string, data: RdocBase, addTask = true) {
return res.insertedId;
}
export async function get(domainId: string, _id: ObjectID) {
export async function get(domainId: string, _id: ObjectID): Promise<Rdoc> {
const rdoc = await coll.findOne({ domainId, _id });
if (!rdoc) throw new RecordNotFoundError(_id);
return rdoc;
@@ -132,7 +102,7 @@ export function getMulti(domainId: string, query: any) {
export async function update(
domainId: string, _id: ObjectID,
$set: any = {}, $push: any = {}, $unset: any = {},
) {
): Promise<Rdoc> {
const $update: any = {};
if ($set && Object.keys($set).length) $update.$set = $set;
if ($push && Object.keys($push).length) $update.$push = $push;
@@ -157,11 +127,13 @@ export function reset(domainId: string, rid: ObjectID) {
});
}
export function count<T>(domainId: string, query: FilterQuery<T>) {
export function count(domainId: string, query: any) {
return coll.find({ domainId, ...query }).count();
}
export async function getList(domainId: string, rids: ObjectID[], showHidden = false) {
export async function getList(
domainId: string, rids: ObjectID[], showHidden = false,
): Promise<{ [key: string]: Rdoc }> {
const r = {};
for (const rid of rids) {
// eslint-disable-next-line no-await-in-loop
@@ -184,7 +156,7 @@ export function getUserInProblemMulti(
return coll.find({ domainId, uid, pid });
}
export function getByUid(domainId: string, uid: number) {
export function getByUid(domainId: string, uid: number): Promise<Rdoc[]> {
return coll.find({ domainId, uid }).toArray();
}
+11 -10
View File
@@ -1,8 +1,9 @@
import moment from 'moment-timezone';
import * as builtin from './builtin';
import { Setting as _Setting } from '../interface';
const countries = moment.tz.countries();
const tzs = new Set();
const tzs: Set<string> = new Set();
for (const country of countries) {
const tz = moment.tz.zonesForCountry(country);
for (const t of tz) tzs.add(t);
@@ -25,40 +26,40 @@ export const DOMAIN_SETTINGS_BY_KEY = {};
export const SYSTEM_SETTINGS_BY_KEY = {};
export const Setting = (
family, key, range = null,
value = null, type = 'text', name = '',
family: string, key: string, range: Array<[string, string]> | { [key: string]: string } = null,
value: any = null, type = 'text', name = '',
desc = '', flag = 0,
) => ({
): _Setting => ({
family, key, range, value, type, name, desc, flag,
});
export const PreferenceSetting = (...settings) => {
export const PreferenceSetting = (...settings: _Setting[]) => {
for (const setting of settings) {
PREFERENCE_SETTINGS.push(setting);
SETTINGS.push(setting);
SETTINGS_BY_KEY[setting.key] = setting;
}
};
export const AccountSetting = (...settings) => {
export const AccountSetting = (...settings: _Setting[]) => {
for (const setting of settings) {
ACCOUNT_SETTINGS.push(setting);
SETTINGS.push(setting);
SETTINGS_BY_KEY[setting.key] = setting;
}
};
export const DomainUserSetting = (...settings) => {
export const DomainUserSetting = (...settings: _Setting[]) => {
for (const setting of settings) {
DOMAIN_USER_SETTINGS.push(setting);
DOMAIN_USER_SETTINGS_BY_KEY[setting.key] = setting;
}
};
export const DomainSetting = (...settings) => {
export const DomainSetting = (...settings: _Setting[]) => {
for (const setting of settings) {
DOMAIN_SETTINGS.push(setting);
DOMAIN_SETTINGS_BY_KEY[setting.key] = setting;
}
};
export const SystemSetting = (...settings) => {
export const SystemSetting = (...settings: _Setting[]) => {
for (const setting of settings) {
SYSTEM_SETTINGS.push(setting);
SYSTEM_SETTINGS_BY_KEY[setting.key] = setting;
@@ -69,7 +70,7 @@ PreferenceSetting(
// TODO generate by global.Hydro.locales
Setting('setting_display', 'viewLang', builtin.VIEW_LANGS.map((i) => [i.code, i.name]),
'zh_CN', 'select', 'UI Language'),
Setting('setting_display', 'timezone', timezones,
Setting('setting_display', 'timezone', timezones as [string, string][],
'Asia/Shanghai', 'select', 'Timezone'),
Setting('setting_usage', 'codeLang', builtin.LANG_TEXTS,
null, 'select', 'Default Code Language'),
-6
View File
@@ -4,12 +4,6 @@ import * as db from '../service/db';
const coll = db.collection('task');
export interface Task {
_id: ObjectID,
count: number,
executeAfter: number,
}
export async function add(task: any) {
const t = { ...task };
if (typeof t.executeAfter === 'object') t.executeAfter = t.executeAfter.getTime();
+1
View File
@@ -90,6 +90,7 @@ global.Hydro.model.token = {
TYPE_CSRF_TOKEN,
TYPE_OAUTH,
TYPE_REGISTRATION,
TYPE_LOSTPASS,
ensureIndexes,
add,
+1
View File
@@ -304,6 +304,7 @@ export function ensureIndexes() {
}
global.Hydro.model.user = {
User,
changePassword,
create,
getByEmail,