How to use the @nestjs/microservices.RpcException function in @nestjs/microservices

To help you get started, we’ve selected a few @nestjs/microservices 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 ConnextProject / indra / modules / node / src / channel / channel.service.ts View on Github external
async deposit(
    multisigAddress: string,
    amount: BigNumber,
    notifyCounterparty: boolean = false,
    tokenAddress?: string,
  ): Promise {
    const channel = await this.channelRepository.findByMultisigAddress(multisigAddress);
    if (!channel) {
      throw new RpcException(`No channel exists for multisigAddress ${multisigAddress}`);
    }

    const depositResponse = await this.node.rpcRouter.dispatch(
      jsonRpcDeserialize({
        id: Date.now(),
        jsonrpc: "2.0",
        method: NodeTypes.RpcMethodName.DEPOSIT,
        params: {
          amount,
          multisigAddress,
          notifyCounterparty,
          tokenAddress,
        } as NodeTypes.DepositParams,
      }),
    );
    logger.log(`depositResponse.result: ${JSON.stringify(depositResponse!.result)}`);
github notadd / nt-module-cms / src / articles / services / article.service.ts View on Github external
async createArticle(art: inputArticle) {
        const classify = await this.claRepo.findOne({ id: art.classifyId })
        const user = (await this.userService.findUserInfoByIds({ userIds: [art.userId] }).toPromise()).data[0];
        if (!classify) {
            throw new RpcException({ code: 404, message: '该文章分类不存在!' });
        }
        const exist = await this.artRepo.save(this.artRepo.create({
            userId: art.userId,
            title: art.title,
            cover: art.cover,
            abstract: art.abstract,
            content: art.content,
            top: art.top,
            source: art.source,
            status: user.userRoles.length && user.userRoles[0].id === 1 ? 0 : 1,
            createdAt: art.createAt,
            classify
        }));
        if (art.infoKVs && art.infoKVs.length) {
            await this.createOrUpdateArtInfos(exist, art.infoKVs, 'create');
        }
github notadd / nt-module-cms / src / articles / services / article.service.ts View on Github external
async recoverArticleByIds(ids: number[]) {
        const articles: number[] = [];
        await this.artRepo.findByIds(ids).then(art => {
            art.map((key, value) => {
                articles.push(key.id);
            })
        });
        const noExist = _.difference(ids, articles);
        if (noExist.length > 0) {
            throw new RpcException({ code: 404, message: `id为${noExist}的文章不存在` });
        }
        await this.artRepo.update(ids, { recycling: false });
    }
github notadd / nt-module-user / src / services / role.service.ts View on Github external
async setPermissions(id: number, permissionIds: number[]) {
        const role = await this.roleRepo.findOne(id);
        if (!role) {
            throw new RpcException({ code: 404, message: t('The role id of %s does not exist', id.toString()) });
        }

        const permissionArr = await this.permissionRepo.findByIds(permissionIds);
        permissionIds.forEach(permissionId => {
            const exist: Permission | undefined = permissionArr.find(permission => {
                return permission.id === permissionId;
            });

            if (!exist) {
                throw new RpcException({ code: 404, message: t('The permission id of %s does not exist', permissionId.toString()) });
            }
        });

        role.permissions = permissionArr;
        await this.roleRepo.save(role);
    }
github notadd / nt-module-cms / src / pages / services / page.service.ts View on Github external
async updatePage(page: Page) {
        const exist = await this.pageRepo.findOne(page.id, { relations: ['contents'] });
        const pageSort = await this.psRepo.findOne({ where: { id: page.pageSort } });
        if (!pageSort) {
            throw new RpcException({ code: 404, message: '该页面分类不存在!' });
        }
        exist.pageSort = pageSort;
        if (page.alias && page.alias !== exist.alias) {
            if (await this.pageRepo.findOne({ where: { alias: page.alias, pageSort: page.pageSort } })) {
                throw new RpcException({ code: 406, message: '页面别名重复!' });
            }
        }
        if (page.contents) {
            const same = await this.contentRepo.find({ where: { page: page.id } });
            await this.contentRepo.remove(same);
        }
        await this.pageRepo.save(this.pageRepo.create(page));
    }
github notadd / nt-module-user / src / services / organization.service.ts View on Github external
async updateOrganization(id: number, name: string, parentId: number): Promise {
        const exist = await this.organizationReq.findOne(id);
        if (!exist) {
            throw new RpcException({ code: 404, message: t('The organization with id of %s does not exist', id.toString()) });
        }

        if (name !== exist.name) {
            await this.entityCheckService.checkNameExist(Organization, name);
        }

        let parent: Organization | undefined;
        if (parentId) {
            parent = await this.organizationReq.findOne(parentId);
            if (!parent) {
                throw new RpcException({ code: 404, message: t('The parent organization with id of %s does not exist', parentId.toString()) });
            }
        }
        try {
            exist.name = name;
            exist.parent = parent as any;
github notadd / nt-module-cms / src / articles / services / article.service.ts View on Github external
async updateArticle(art: updateArticle) {
        try {
            const article = await this.artRepo.findOne(art.id, { relations: ['artInfos'] });
            if (!article) {
                throw new RpcException({ code: 404, message: '该文章不存在!' });
            }
            art.status = 0;
            art.modifyAt = moment().format('YYYY-MM-DD HH:mm:ss');
            await this.artRepo.save(this.artRepo.create(art));
            if (art.infoKVs && art.infoKVs.length) {
                await this.createOrUpdateArtInfos(article, art.infoKVs, 'update');
            }
        } catch (error) {
            throw new RpcException({ code: 500, message: error.toString() });
        }
    }
github notadd / nt-module-cms / src / articles / services / article.service.ts View on Github external
async deleteArticleByIds(ids: number[]) {
        const articles: number[] = [];
        await this.artRepo.findByIds(ids).then(art => {
            art.map((key, value) => {
                articles.push(key.id);
            })
        });
        const noExist = _.difference(ids, articles);
        if (noExist.length > 0) {
            throw new RpcException({ code: 404, message: `id为${noExist}的文章不存在` });
        }
        await this.artRepo.delete(ids);
    }
github notadd / nt-module-cms / src / plugin / message-board / services / message-board.service.ts View on Github external
async createMessageBoard(messageBoard: CreateBoardInput) {
        try {
            if (await this.mbRepo.findOne({ where: { alias: messageBoard.alias } })) {
                throw new RpcException({ code: 406, message: '留言板别名重复!' });
            }
            const board = await this.mbRepo.save(this.mbRepo.create({ name: messageBoard.name, alias: messageBoard.alias }));
            if (messageBoard.boardItem && messageBoard.boardItem.length) {
                const array = messageBoard.boardItem.map(item => item.alias);
                for (let i = 0; i < array.length; i++) {
                    const same = array.filter(item => item === array[i]);
                    if (same.length > 1) {
                        throw new RpcException({ code: 406, message: '信息项别名重复!' });
                    }
                }
                for (const i of messageBoard.boardItem) {
                    const item = await this.itemRepo.findOne(i.itemId);
                    await this.biRepo.save(this.biRepo.create({
                        name: i.name,
                        alias: i.alias,
                        required: i.required,
github notadd / nt-module-cms / src / articles / services / article.service.ts View on Github external
async recycleArticleByIds(ids: number[]) {
        const articles: number[] = [];
        await this.artRepo.findByIds(ids).then(art => {
            art.map((key, value) => {
                articles.push(key.id);
            })
        });
        const noExist = _.difference(ids, articles);
        if (noExist.length > 0) {
            throw new RpcException({ code: 404, message: `id为${noExist}的文章不存在` });
        }
        await this.artRepo.update(ids, { recycling: true });
    }