Skip to content

Commit

Permalink
fix(notifications): a few fixes when adding the pkgs to the show-case (
Browse files Browse the repository at this point in the history
…#1077)

* fix(notifications): make openapi.yaml location relative

* chore(notifications): update README for POST example

* fix(notifications): add workaround for missing SQLite "ilike"

* chore: sidebar item can be provided with a className
  • Loading branch information
mareklibra authored Jan 18, 2024
1 parent 145e95b commit 75c4dc5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
6 changes: 1 addition & 5 deletions plugins/notifications-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ A notification without target users or groups is considered a system notificatio
Request (User message and then system message):

```bash
curl -X POST http://localhost:7007/api/notifications/notifications -H "Content-Type: application/json" -d '{"title": "My message title", "message": "I have nothing to say", "origin": "my-origin", "targetUsers": ["jdoe"], "targetGroups": ["jdoe"], "actions": [{"title": "my-title", "url": "http://foo.bar"}, {"title": "another action", "url": "https://foo.foo.bar"}]}'
```

```bash
curl -X POST http://localhost:7007/api/notifications/notifications -H "Content-Type: application/json" -d '{"title": "My message title", "message": "I have nothing to say", "origin": "my-origin", "actions": [{"title": "my-title", "url": "http://foo.bar"}, {"title": "another action", "url": "https://foo.foo.bar"}]}'
curl -X POST http://localhost:7007/api/notifications/notifications -H "Content-Type: application/json" -d '{"title": "My message title", "message": "I have nothing to say", "origin": "my-origin", "topic":"my topic", "targetUsers": ["default/guest"], "actions": [{"title": "my-title", "url": "http://foo.bar"}, {"title": "another action", "url": "https://foo.foo.bar"}]}'
```

Optionally add `-H "Authorization: Bearer eyJh.....` with a valid JWT token if the service-to-service authorization is enabled (see above).
Expand Down
3 changes: 2 additions & 1 deletion plugins/notifications-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"supertest": "6.3.3"
},
"files": [
"dist"
"dist",
"src/openapi.yaml"
]
}
4 changes: 3 additions & 1 deletion plugins/notifications-backend/src/service/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ function createQuery(
// filter by text
if (filter.containsText) {
query.andWhere(function () {
this.whereILike('title', `%${filter.containsText}%`).orWhereILike(
// case-insensitive "whereILike" should be used instead but
// there is bug for SQLite around this: https://github.com/knex/knex/issues/5604
this.whereLike('title', `%${filter.containsText}%`).orWhereLike(
'message',
`%${filter.containsText}%`,
);
Expand Down
6 changes: 5 additions & 1 deletion plugins/notifications-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
} from './permissions';
import { RouterOptions } from './types';

// TODO: fix filename resolving
const OPENAPI_ROOT =
'../../node_modules/@janus-idp/plugin-notifications-backend/src';

export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
Expand All @@ -38,7 +42,7 @@ export async function createRouter(
formats: fullFormats, // open issue: https://github.com/openapistack/openapi-backend/issues/280
},
validate: true,
definition: '../../plugins/notifications-backend/src/openapi.yaml',
definition: `${OPENAPI_ROOT}/openapi.yaml`,
});

await api.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type NotificationsSidebarItemProps = {
* Example: 5000
*/
pollingInterval?: number;
className?: string;
};

const useStyles = makeStyles(_theme => ({
Expand All @@ -42,6 +43,7 @@ const useStyles = makeStyles(_theme => ({

export const NotificationsSidebarItem = ({
pollingInterval,
className,
}: NotificationsSidebarItemProps) => {
const styles = useStyles();
const notificationsApi = useApi(notificationsApiRef);
Expand Down Expand Up @@ -88,6 +90,7 @@ export const NotificationsSidebarItem = ({
return (
<>
<SidebarItem
className={className}
icon={icon}
to={NOTIFICATIONS_ROUTE}
text="Notifications"
Expand Down

0 comments on commit 75c4dc5

Please sign in to comment.