-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ported SubscriptionBeforeSaveInterceptor
- Loading branch information
Showing
5 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/api/subscriptions/broadcast-push-notification-filter.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
ArgumentMetadata, | ||
HttpException, | ||
HttpStatus, | ||
Injectable, | ||
PipeTransform, | ||
} from '@nestjs/common'; | ||
import jmespath from 'jmespath'; | ||
|
||
@Injectable() | ||
export class BroadcastPushNotificationFilterPipe implements PipeTransform { | ||
transform(value: any, metadata: ArgumentMetadata) { | ||
let filter = value.broadcastPushNotificationFilter; | ||
if (!filter) { | ||
return value; | ||
} | ||
if (typeof filter !== 'string') { | ||
throw new HttpException( | ||
'invalid broadcastPushNotificationFilter', | ||
HttpStatus.BAD_REQUEST, | ||
); | ||
} | ||
filter = '[?' + filter + ']'; | ||
try { | ||
jmespath.compile(filter); | ||
} catch (ex) { | ||
throw new HttpException( | ||
'invalid broadcastPushNotificationFilter', | ||
HttpStatus.BAD_REQUEST, | ||
); | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters