How to use the typescript-rest.Errors function in typescript-rest

To help you get started, we’ve selected a few typescript-rest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vellengs / typerx / dist / controllers / account-controller.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            throw new typescript_rest_1.Errors.UnauthorizedError('没有登录');
            // return null;
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / account.service.js View on Github external
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('禁止非管理员更新帐号信息!');
            }
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / setting.service.js View on Github external
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');
            }
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / menu.service.js View on Github external
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
github vellengs / typerx / packages / server / dist / interceptor / interceptor.js View on Github external
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;
    });
}
github vellengs / typerx / packages / server / dist / modules / cms / category.service.js View on Github external
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;
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / user.service.js View on Github external
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');
            }
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / account.service.js View on Github external
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('禁止非管理员更新帐号信息!');
            }
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / group.service.js View on Github external
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;
        });
    }
github vellengs / typerx / packages / server / dist / modules / core / user.service.js View on Github external
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');
            }
        });
    }