From 3ce2827e5f4b7b382b6785d136d46bfcc1a34c6a Mon Sep 17 00:00:00 2001 From: Sumanth Chinthagunta Date: Thu, 20 Jun 2019 14:54:43 -0700 Subject: [PATCH] fix(api): testing a fix for NotificationService.send() typeorm Any was not working https://github.com/typeorm/typeorm/issues/3150 --- apps/api/API-TESTING.md | 10 +++++++++- .../notifications/notification/notification.service.ts | 10 ++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/api/API-TESTING.md b/apps/api/API-TESTING.md index 38d559bf4..fbe28f81a 100644 --- a/apps/api/API-TESTING.md +++ b/apps/api/API-TESTING.md @@ -90,7 +90,7 @@ curl -v -X POST \ ```bash # OIDC_ISSUER_URL=https://keycloak.traefik.k8s/auth/realms/ngx -OIDC_ISSUER_URL=https://keycloak-ngx1.1d35.starter-us-east-1.openshiftapps.com/auth/realms/ngx +OIDC_ISSUER_URL=https://keycloak.kashmora.com/auth/realms/ngx OIDC_CLIENT_ID=ngxapi USERNAME=sumo3 @@ -126,6 +126,14 @@ curl -X GET \ -H "Authorization: Bearer $access_token" \ | jq . +curl -X POST \ + http://localhost:3000/api/notifications/send \ + -H "content-type: application/jsonn" \ + -H "Authorization: Bearer $access_token" \ + -d '{"id":"c938cdcc-20f6-4cf1-b4b7-989fa0c5188d", "topic":"sumo"}' \ + | jq . + + # Get User Profile curl -X POST $OIDC_ISSUER_URL/protocol/openid-connect/userinfo \ -H "Content-Type: application/x-www-form-urlencoded" \ diff --git a/apps/api/src/app/notifications/notification/notification.service.ts b/apps/api/src/app/notifications/notification/notification.service.ts index 7b54fb1ec..65f50edca 100644 --- a/apps/api/src/app/notifications/notification/notification.service.ts +++ b/apps/api/src/app/notifications/notification/notification.service.ts @@ -1,6 +1,6 @@ import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Any, In, Repository } from 'typeorm'; +import { Any, In, Raw, Repository } from 'typeorm'; import { CrudService, IPagination } from '../../core'; import { Notification, TargetType } from './notification.entity'; import { CQRSGateway } from '../../shared'; @@ -57,7 +57,8 @@ export class NotificationService extends CrudService implements On case TargetType.TOPIC: // FIXME: https://github.com/typeorm/typeorm/issues/3150 subscriptions = await this.subscriptionRepository.find({ - where: { topics: Any([notification.target]) }, + // where: { topics: Any([notification.target]) }, + where: { topics: Raw(alias => `${alias} && '{${notification.target}}'::text[]`) }, }); break; case TargetType.ALL: @@ -78,10 +79,7 @@ export class NotificationService extends CrudService implements On } async onMarkAllAsRead(command: NotificationsMarkAsReadCommand) { - await this.update( - { targetType: TargetType.USER, target: command.user.username }, - { read: true }, - ); + await this.update({ targetType: TargetType.USER, target: command.user.username }, { read: true }); } async onDeleteNotification(command: NotificationsDeleteCommand) {