Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return __awaiter(this, void 0, void 0, function* () {
throw new typescript_rest_1.Errors.UnauthorizedError('没有登录');
// return null;
});
}
return __awaiter(this, void 0, void 0, function* () {
if (admin && admin.isAdmin) {
// this.setKeyWord(entry);
const doc = yield core_database_1.CoreDatabase.Account.findOneAndUpdate({
_id: entry.id,
}, entry).exec();
return doc;
}
else {
throw new typescript_rest_1.Errors.ForbiddenError('禁止非管理员更新帐号信息!');
}
});
}
return __awaiter(this, void 0, void 0, function* () {
if (entry.id) {
const result = yield core_database_1.CoreDatabase.Setting.findOneAndUpdate({ _id: entry.id }, { $set: entry }, { upsert: true, 'new': true }).exec();
return this.pure(result);
}
else {
throw new typescript_rest_1.Errors.BadRequestError('settings not found');
}
});
}
return __awaiter(this, void 0, void 0, function* () {
if (!user) {
throw new typescript_rest_1.Errors.UnauthorizedError("user is not authenticated");
}
if (!user.isAdmin) {
const account = yield core_database_1.CoreDatabase.Account.findOne({ _id: user.id }, 'groups').exec();
const roles = account.toObject().roles || [];
const roleDocs = (yield core_database_1.CoreDatabase.Group.find({
_id: { $in: roles }
}, 'permissions').exec()) || [];
const permissions = [];
roleDocs.forEach((g) => {
permissions.push(...g.permissions);
});
const menus = yield core_database_1.CoreDatabase.Menu.find({
_id: {
$in: permissions
},
isMenu: true
return __awaiter(this, void 0, void 0, function* () {
if (req.user && !req.user.isAdmin &&
req.route.path.startsWith(exports.apiPrefix) &&
!isPublicApi(req)) {
const result = yield hasPermission(req.user.id, req.method.toLowerCase() + req.route.path);
if (!result) {
throw new typescript_rest_1.Errors.ForbiddenError("no permission");
}
}
return req;
});
}
return __awaiter(this, void 0, void 0, function* () {
if (entry.id === entry.parent) {
throw new typescript_rest_1.Errors.BadRequestError('can not be set parent by self.');
}
const doc = yield cms_database_1.CmsDatabase.Category.findOneAndUpdate({
_id: entry.id,
}, entry).exec();
return doc;
});
}
return __awaiter(this, void 0, void 0, function* () {
const { request } = context;
const profile = yield core_database_1.CoreDatabase.Profile.findOneAndUpdate({
_id: request.user.id,
}, entry, { upsert: true, new: true }).exec();
entry.profile = profile._id;
const account = yield core_database_1.CoreDatabase.Account.findOneAndUpdate({
_id: request.user.id,
}, entry, { new: true }).populate('profile').exec();
if (profile) {
const instance = repository_1.Repository.mergeProfile(account);
return instance;
}
else {
throw new typescript_rest_1.Errors.BadRequestError('user not found');
}
});
}
return __awaiter(this, void 0, void 0, function* () {
if (admin && admin.isAdmin) {
this.setKeyWord(entry);
const doc = yield core_database_1.CoreDatabase.Account.findOneAndUpdate({
_id: entry.id,
}, entry, {
new: true
}).exec();
return doc;
}
else {
throw new typescript_rest_1.Errors.ForbiddenError('禁止非管理员更新帐号信息!');
}
});
}
return __awaiter(this, void 0, void 0, function* () {
if (entry.id === entry.parent) {
throw new typescript_rest_1.Errors.BadRequestError('can not be set parent by self.');
}
const doc = yield core_database_1.CoreDatabase.Group.findOneAndUpdate({
_id: entry.id,
}, entry).exec();
return doc;
});
}
return __awaiter(this, void 0, void 0, function* () {
const { request } = context;
const profile = yield core_database_1.CoreDatabase.Profile.findOneAndUpdate({
_id: request.user.id,
}, entry, { upsert: true, new: true }).exec();
entry.profile = profile._id;
const account = yield core_database_1.CoreDatabase.Account.findOneAndUpdate({
_id: request.user.id,
}, entry, { new: true }).populate('profile').exec();
if (profile) {
const instance = repository_1.Repository.mergeProfile(account);
return instance;
}
else {
throw new typescript_rest_1.Errors.BadRequestError('user not found');
}
});
}