update model.user.create() api

This commit is contained in:
undefined committed 2020-07-22 18:54:18 +08:00
1 parent 162d93e5db
commit 37756c3724
14 files changed
+31 -57

No files matched your search

+2 -5
View File
@@ -42,7 +42,7 @@ export async function add(
export async function get(
domainId: string, pid: string | number,
uid: number = null, doThrow = true,
uid: number = null,
): Promise<Pdoc> {
if (typeof pid !== 'number') {
if (!Number.isNaN(parseInt(pid, 10))) pid = parseInt(pid, 10);
@@ -50,10 +50,7 @@ export async function get(
const pdoc = Number.isInteger(pid)
? await document.get(domainId, document.TYPE_PROBLEM, pid)
: (await document.getMulti(domainId, document.TYPE_PROBLEM, { pid }).toArray())[0];
if (!pdoc) {
if (doThrow) throw new ProblemNotFoundError(domainId, pid);
return null;
}
if (!pdoc) return null;
if (uid) {
pdoc.psdoc = await document.getStatus(domainId, document.TYPE_PROBLEM, pdoc.docId, uid);
}
+1 -1
View File
@@ -62,7 +62,7 @@ export async function add(domainId: string, data: RdocBase, addTask: boolean): P
judgeAt: null,
});
const [pdoc, res] = await Promise.all([
problem.get(domainId, data.pid, null, false),
problem.get(domainId, data.pid, null),
coll.insertOne(data),
]);
if (addTask) {
+4 -3
View File
@@ -164,9 +164,10 @@ export async function inc(_id: number, field: string, n = 1) {
return udoc;
}
export async function create({
uid = null, mail, uname, password, regip = '127.0.0.1', priv = PRIV.PRIV_DEFAULT,
}) {
export async function create(
mail: string, uname: string, password: string,
uid: number, regip = '127.0.0.1', priv = PRIV.PRIV_DEFAULT,
) {
const salt = String.random();
if (!uid) uid = await system.inc('user');
try {