Skip to content

Commit

Permalink
fix(api): testing a fix for NotificationService.send()
Browse files Browse the repository at this point in the history
typeorm Any was not working

typeorm/typeorm#3150
  • Loading branch information
xmlking committed Jun 20, 2019
1 parent 2f0826c commit 3ce2827
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 9 additions & 1 deletion apps/api/API-TESTING.md
Expand Up @@ -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
Expand Down Expand Up @@ -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" \
Expand Down
@@ -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';
Expand Down Expand Up @@ -57,7 +57,8 @@ export class NotificationService extends CrudService<Notification> 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:
Expand All @@ -78,10 +79,7 @@ export class NotificationService extends CrudService<Notification> 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) {
Expand Down

0 comments on commit 3ce2827

Please sign in to comment.