服务状态(/status)

This commit is contained in:
masnn committed 2020-05-31 20:07:52 +08:00
1 parent b2989cb9ea
commit 216a4a91e4
19 files changed
+322 -136

No files matched your search

+6 -5
View File
@@ -23,6 +23,7 @@ async function add(
) {
const _id = new ObjectID();
const doc = {
_id,
content,
owner,
domainId,
@@ -53,8 +54,10 @@ async function set(domainId, docType, docId, args) {
}
function deleteOne(domainId, docType, docId) {
// TODO(twd2): delete status?
return coll.deleteOne({ domainId, docType, docId });
return Promise.all([
coll.deleteMany({ domainId, docType, docId }),
coll.deleteOne({ domainId, docType, docId }),
]);
}
function deleteMulti(domainId, docType, args = {}) {
@@ -134,9 +137,7 @@ async function getSub(domainId, docType, docId, key, subId) {
});
if (!doc) return [null, null];
for (const sdoc of doc[key] || []) {
if (sdoc._id === subId) {
return [doc, sdoc];
}
if (sdoc._id === subId) return [doc, sdoc];
}
return [doc, null];
}
+6 -5
View File
@@ -1,3 +1,4 @@
const builtin = require('./builtin');
const document = require('./document');
const system = require('./system');
const { UserNotFoundError, UserAlreadyExistError } = require('../error');
@@ -40,15 +41,15 @@ class USER {
async function getPerm(domainId, udoc) {
if (udoc._id === 1) { // Is Guest
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, 'guest');
return p.content;
return p ? p.content : builtin.BUILTIN_ROLES.guest.perm;
}
if (udoc.priv === 1) {
if (udoc.priv === 1) { // Is superadmin
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, 'admin');
return p.content;
return p ? p.content : builtin.BUILTIN_ROLES.admin.perm;
}
const role = await document.getStatus(domainId, document.TYPE_DOMAIN_ROLE, 0, udoc._id);
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, role.role || 'default');
return p.content;
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, (role || {}).role || 'default');
return p ? p.content : builtin.BUILTIN_ROLES.default.perm;
}
async function getById(domainId, _id) {