How to use the @nestjs/microservices.GrpcMethod 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 new-eden-social / new-eden-social / src / services / notification / grpc / notification.grpc.controller.ts View on Github external
@GrpcMethod('NotificationService')
  getLatest(data: IGetLatestRequest): Observable {
    return from(this.notificationService.getLatest(
      data.characterId,
      data.pagination.limit,
      data.pagination.page
    )).pipe(
      map<{ notifications: Notification[], count: number }, IPaginatedNotificationResponse>(notificationData => ({
        notifications: notificationData.notifications.map(this.notificationTransform),
        count: notificationData.count,
      }))
    );
  }

  @GrpcMethod('NotificationService')
  markAsSeen(data: IMarkAsSeenRequest): Observable {
    return from(this.notificationService.get(
      data.notificationId,
      data.characterId,
    )).pipe(
      flatMap(notification => this.notificationService.markAsSeen(notification)),
      map(this.notificationTransform)
    );
  }

  private notificationTransform(notification: Notification): INotificationResponse {
    return {
      id: notification.id,
      createdAt: notification.createdAt.toISOString(),
      seenAt: notification.seenAt.toISOString(),
      type: notification.type,
github new-eden-social / new-eden-social / src / services / post / grpc / post.grpc.controller.ts View on Github external
import { PostService } from '@new-eden-social/services-post/post.service';
import { Observable, from } from 'rxjs';
import { Post } from '@new-eden-social/services-post/post.entity';
import { map } from 'rxjs/operators';
import { IURLMetadata } from '@new-eden-social/services-metascraper/metascraper.interface';
import { GrpcMethod } from '@nestjs/microservices';

@Controller()
export class PostGrpcController implements IPostGrpcService {

  constructor(
    private readonly postService: PostService,
    ) {
  }

  @GrpcMethod('PostService')
  get(data: IGetRequest): Observable {
    return from(this.postService.get(data.postId)).pipe(
      map(this.postTransform)
    );
  }

  @GrpcMethod('PostService')
  createAsCharacter(data: ICreateAsCharacterRequest): Observable {
    return from(this.postService.createAsCharacter(data.post, data.characterId)).pipe(
      map(this.postTransform)
    );
  }

  @GrpcMethod('PostService')
  createAsCorporation(data: ICreateAsCorporationRequest): Observable {
    return from(this.postService.createAsCorporation(data.post, data.corporationId)).pipe(
github notadd / nt-module-cms / src / pages / controllers / page.controller.ts View on Github external
}

    @GrpcMethod('PageService')
    async deletePage(body: { id: number }) {
        await this.pageService.deletePage(body.id);
        return { code: 200, message: 'ๅˆ ้™คๆˆๅŠŸ!' };
    }

    @GrpcMethod('PageService')
    async getAllPage(body: { pageNumber: number, pageSize: number, name: string }) {
        const data = (await this.pageService.getAllPage(body.pageNumber, body.pageSize, body.name)).data;
        const total = (await this.pageService.getAllPage(body.pageNumber, body.pageSize, body.name)).total;
        return { code: 200, message: 'ๆŸฅ่ฏขๆˆๅŠŸ!', data, total }
    }

    @GrpcMethod('PageService')
    async getOnePage(body: { alias: string }) {
        const data = await this.pageService.getOnePage(body.alias);
        return { code: 200, message: 'ๆŸฅ่ฏขๆˆๅŠŸ!', data };
    }

}
github new-eden-social / new-eden-social / src / services / character / grpc / character.grpc.controller.ts View on Github external
@GrpcMethod('CharacterService')
  exists(data: IExistsGetRefreshRequest): Observable {
    return from(this.characterService.exists(data.characterId)).pipe(
      map(exists => ({ exists })),
    );
  }

  @GrpcMethod('CharacterService')
  get(data: IExistsGetRefreshRequest): Observable {
    return from(this.characterService.get(data.characterId)).pipe(
      map(this.characterTransform),
    );
  }

  @GrpcMethod('CharacterService')
  getNotUpdated(data: IGetNotUpdatedRequest): Observable {
    return from(this.characterService.getNotUpdated(data.interval, data.limit)).pipe(
      map(characters => ({ characters: characters.map(this.characterTransform)}))
    );
  }

  @GrpcMethod('CharacterService')
  refresh(data: IExistsGetRefreshRequest): Observable {
    return from(this.characterService.get(data.characterId)).pipe(
      map(this.characterTransform),
    );
  }

  @GrpcMethod('CharacterService')
  roles(data: IExistsGetRefreshRequest): Observable {
    return from(this.characterService.getRoles(data.characterId)).pipe(
github notadd / nt-module-user / src / controllers / user.grpc.controller.ts View on Github external
return { code: 200, message: t('Revert recycled user successfully') };
    }

    @GrpcMethod('UserService')
    async updateUserInfoById(payload: { userId: number, updateUserInput: UpdateUserInput }) {
        await this.userService.updateUserInfo(payload.userId, payload.updateUserInput);
        return { code: 200, message: t('Update user information successfully') };
    }

    @GrpcMethod('UserService')
    async updateCurrentUserInfo(payload: { userId: number, updateCurrentUserInput: UpdateUserInput }) {
        await this.userService.updateUserInfo(payload.userId, payload.updateCurrentUserInput);
        return { code: 200, message: t('Update current login user information successfully') };
    }

    @GrpcMethod('UserService')
    async findUserInfoByIds(payload: { userIds: number[] }) {
        const data = await this.userService.findUserInfoById(payload.userIds) as UserInfoData[];
        return { code: 200, message: t('Query the specified users information successfully'), data };
    }

    @GrpcMethod('UserService')
    async findCurrentUserInfo(payload: { userId: number }) {
        const data = await this.userService.findUserInfoById(payload.userId) as UserInfoData;
        return { code: 200, message: t('Query the current login user information successfully'), data };
    }

    @GrpcMethod('UserService')
    async findRegisterUserInputInfo() {
        const data = await this.userService.findOneWithInfoItemsByRoleIds([1]);
        return { code: 200, message: t('Query user registration information item successfully'), data };
    }
github notadd / nt-module-cms / src / articles / controllers / classify.controller.ts View on Github external
return { code: 200, message: 'ๆทปๅŠ ๆˆๅŠŸ!' };
    }

    @GrpcMethod('ClassifyService')
    async delClassify(body: { id: number }) {
        await this.classifyService.delClassify(body.id);
        return { code: 200, message: 'ๅˆ ้™คๆˆๅŠŸ!' };
    }

    @GrpcMethod('ClassifyService')
    async updateClassify(body: { classify: Classify }) {
        await this.classifyService.updateClassify(body.classify);
        return { code: 200, message: 'ไฟฎๆ”นๆˆๅŠŸ!' };
    }

    @GrpcMethod('ClassifyService')
    async getAllClassify(body: { id: number }) {
        const data = await this.classifyService.getAllClassify(body.id);
        return { code: 200, message: 'ๆŸฅ่ฏขๆˆๅŠŸ!', data: JSON.stringify(data) };
    }

    @GrpcMethod('ClassifyService')
    async getOneClassify(body: { id: number }) {
        const data = await this.classifyService.getOneClassify(body.id);
        return { code: 200, message: 'ๆŸฅ่ฏขๆˆๅŠŸ!', data: JSON.stringify(data) };
    }

    @GrpcMethod('ClassifyService')
    async getParentClassify(body: { id: number }) {
        const data = await this.classifyService.getParentClassify(body.id);
        return { code: 200, message: 'ๆŸฅ่ฏขๆˆๅŠŸ!', data };
    }
github notadd / nt-module-user / src / controllers / user.grpc.controller.ts View on Github external
data = result.usersInfo;
            count = result.count;
        } else {
            data = result;
        }
        return { code: 200, message: t('Query all users successfully'), data, count };
    }

    @GrpcMethod('UserService')
    async findUsersInRole(payload: { roleId: number, pageNumber: number, pageSize: number }) {
        const { roleId, pageNumber, pageSize } = payload;
        const { usersInfo, count } = await this.userService.findByRoleId(roleId, pageNumber, pageSize);
        return { code: 200, message: t('Query the user under the role successfully'), data: usersInfo, count };
    }

    @GrpcMethod('UserService')
    async findUsersInOrganization(payload: { organizationId: number, pageNumber: number, pageSize: number }) {
        const { organizationId, pageNumber, pageSize } = payload;
        const { usersInfo, count } = await this.userService.findByOrganizationId(organizationId, pageNumber, pageSize);
        return { code: 200, message: t('Query users under the organization successfully'), data: usersInfo, count };
    }

    @GrpcMethod('UserService')
    async findOneWithRolesAndPermissions(payload: { username: string }) {
        const data = await this.userService.findOneWithRolesAndPermissions(payload.username);
        return { code: 200, message: t('Query users roles and permissions successfully'), data };
    }

    @GrpcMethod('UserService')
    async addPermissionToUser(payload: { userId: number, permissionId: number }) {
        await this.userService.addPermissionToUser(payload.userId, payload.permissionId);
        return { code: 200, message: t('Add permission to user successfully') };
github new-eden-social / new-eden-social / src / services / character / grpc / character.grpc.controller.ts View on Github external
@GrpcMethod('CharacterService')
  getNotUpdated(data: IGetNotUpdatedRequest): Observable {
    return from(this.characterService.getNotUpdated(data.interval, data.limit)).pipe(
      map(characters => ({ characters: characters.map(this.characterTransform)}))
    );
  }

  @GrpcMethod('CharacterService')
  refresh(data: IExistsGetRefreshRequest): Observable {
    return from(this.characterService.get(data.characterId)).pipe(
      map(this.characterTransform),
    );
  }

  @GrpcMethod('CharacterService')
  roles(data: IExistsGetRefreshRequest): Observable {
    return from(this.characterService.getRoles(data.characterId)).pipe(
      map(roles => roles),
    );
  }

  private characterTransform(character: Character): ICharacterResponse {
    return {
      id: character.id,
      handle: character.handle,
      corporationId: character.corporationId,
      name: character.name,
      description: character.description,
      gender: character.gender,
      raceId: character.raceId,
      bloodlineId: character.bloodlineId,
github juicycleff / ultimate-backend / apps / service-payment / src / plan / plan.service.ts View on Github external
import { Controller } from '@nestjs/common';
import { GrpcMethod } from '@nestjs/microservices';
import { BooleanPayload } from '@ultimatebackend/contracts';

@Controller()
export class PlanService {

  @GrpcMethod('PlanService', 'PlanExist')
  async planExist(data: { params: string[] }): Promise {
    return {
      success: true,
    };
  }

  @GrpcMethod('PlanService', 'FindOne')
  async findOne(data: { params: string[] }): Promise {
    return {
      success: true,
    };
  }
}
github notadd / nt-module-user / src / controllers / user.grpc.controller.ts View on Github external
return { code: 200, message: t('Delete user to recycle bin successfully') };
    }

    @GrpcMethod('UserService')
    async deleteRecycledUser(payload: { userId: number }) {
        await this.userService.deleteUser(payload.userId);
        return { code: 200, message: t('Delete user in the recycle bin successfully') };
    }

    @GrpcMethod('UserService')
    async revertBannedUser(payload: { userId: number }) {
        await this.userService.revertBannedOrRecycledUser(payload.userId, 'banned');
        return { code: 200, message: t('Revert banned user successfully') };
    }

    @GrpcMethod('UserService')
    async revertRecycledUser(payload: { userId: number }) {
        await this.userService.revertBannedOrRecycledUser(payload.userId, 'recycled');
        return { code: 200, message: t('Revert recycled user successfully') };
    }

    @GrpcMethod('UserService')
    async updateUserInfoById(payload: { userId: number, updateUserInput: UpdateUserInput }) {
        await this.userService.updateUserInfo(payload.userId, payload.updateUserInput);
        return { code: 200, message: t('Update user information successfully') };
    }

    @GrpcMethod('UserService')
    async updateCurrentUserInfo(payload: { userId: number, updateCurrentUserInput: UpdateUserInput }) {
        await this.userService.updateUserInfo(payload.userId, payload.updateCurrentUserInput);
        return { code: 200, message: t('Update current login user information successfully') };
    }