mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
problem_copy
This commit is contained in:
1 parent
37756c3724
commit
9e96c471af
14 files changed
+118
-159
No files matched your search
@@ -18,6 +18,18 @@ export const TYPE_TRAINING = 40;
|
||||
export const TYPE_FILE = 50;
|
||||
export const TYPE_HOMEWORK = 60;
|
||||
|
||||
export async function add(
|
||||
domainId: string, content: string, owner: number,
|
||||
docType: number, docId: DocID,
|
||||
parentType?: number | null, parentId?: DocID,
|
||||
args?: any,
|
||||
): Promise<typeof docId>
|
||||
export async function add(
|
||||
domainId: string, content: string, owner: number,
|
||||
docType: number, docId: null,
|
||||
parentType?: number, parentId?: DocID,
|
||||
args?: any,
|
||||
): Promise<ObjectID>
|
||||
export async function add(
|
||||
domainId: string, content: string, owner: number,
|
||||
docType: number, docId: DocID = null,
|
||||
|
||||
@@ -30,13 +30,13 @@ export function edit(domainId: string, $set: any) {
|
||||
return coll.updateOne({ _id: domainId }, { $set });
|
||||
}
|
||||
|
||||
export async function inc(domainId: string, field: string, n: number): Promise<DomainDoc | null> {
|
||||
export async function inc(domainId: string, field: string, n: number): Promise<number | null> {
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ _id: domainId },
|
||||
{ $inc: { [field]: n } },
|
||||
{ returnOriginal: false },
|
||||
);
|
||||
return res.value;
|
||||
return res.value.field;
|
||||
}
|
||||
|
||||
export async function getList(domainIds: string[]): Promise<Dictionary<DomainDoc>> {
|
||||
@@ -91,10 +91,14 @@ export async function deleteRoles(domainId: string, roles: string[]) {
|
||||
]);
|
||||
}
|
||||
|
||||
export async function getDomainUser(domainId: string, udoc: Udoc) {
|
||||
interface DomainUserArg {
|
||||
_id: number,
|
||||
priv: number,
|
||||
}
|
||||
export async function getDomainUser(domainId: string, udoc: DomainUserArg) {
|
||||
let dudoc = await collUser.findOne({ domainId, uid: udoc._id });
|
||||
dudoc = dudoc || {};
|
||||
if (udoc._id === 1) dudoc.role = 'guest';
|
||||
if (!(udoc.priv & PRIV.PRIV_USER_PROFILE)) dudoc.role = 'guest';
|
||||
if (udoc.priv & PRIV.PRIV_MANAGE_ALL_DOMAIN) dudoc.role = 'admin';
|
||||
dudoc.role = dudoc.role || 'default';
|
||||
const ddoc = await get(domainId);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { STATUS } from './builtin';
|
||||
import * as file from './file';
|
||||
import * as document from './document';
|
||||
import * as domain from './domain';
|
||||
import { Pdoc, Pdict } from '../interface';
|
||||
import { Pdoc, Pdict, ProblemDataSource } from '../interface';
|
||||
import { ProblemNotFoundError } from '../error';
|
||||
import readConfig from '../lib/readConfig';
|
||||
|
||||
@@ -28,16 +28,16 @@ export const pdocHidden: Pdoc = {
|
||||
|
||||
export async function add(
|
||||
domainId: string, pid: string = null, title: string, content: string, owner: number,
|
||||
tag: string[] = [], category: string[] = [], data: ObjectID = null, hidden = false,
|
||||
tag: string[] = [], category: string[] = [], data: ProblemDataSource = null, hidden = false,
|
||||
) {
|
||||
const d = await domain.inc(domainId, 'pidCounter', 1);
|
||||
if (!pid) pid = d.pidCounter.toString();
|
||||
const pidCounter = await domain.inc(domainId, 'pidCounter', 1);
|
||||
if (!pid) pid = pidCounter.toString();
|
||||
return await document.add(
|
||||
domainId, content, owner, document.TYPE_PROBLEM, d.pidCounter, null, null,
|
||||
domainId, content, owner, document.TYPE_PROBLEM, pidCounter, null, null,
|
||||
{
|
||||
pid, title, data, category, tag, hidden, nSubmit: 0, nAccept: 0,
|
||||
},
|
||||
);
|
||||
) as number;
|
||||
}
|
||||
|
||||
export async function get(
|
||||
@@ -153,7 +153,7 @@ export async function setTestdata(domainId: string, _id: number, filePath: strin
|
||||
const pdoc = await get(domainId, _id);
|
||||
const config = await readConfig(filePath);
|
||||
const id = await file.add(filePath, 'data.zip', 1);
|
||||
if (pdoc.data && typeof pdoc.data === 'object') file.dec(pdoc.data);
|
||||
if (pdoc.data instanceof ObjectID) file.del(pdoc.data);
|
||||
return await edit(domainId, _id, { data: id, config });
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user