Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 5092f80

Browse files
✨ Create unread notifications
1 parent 73d913a commit 5092f80

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/crud/notification.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { dateToDateTime } from "../helpers/utils";
1616
export const createNotification = async (notification: Notification) => {
1717
notification.createdAt = new Date();
1818
notification.updatedAt = notification.createdAt;
19+
notification.read = !!notification.read;
1920
deleteItemFromCache(CacheCategories.USER_NOTIFICATIONS, notification.userId);
2021
return await query(
2122
`INSERT INTO \`api-keys\` ${tableValues(notification)}`,

src/interfaces/tables/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface Notification {
4848
category: NotificationCategories;
4949
text: string;
5050
link: string;
51-
read: boolean;
51+
read?: boolean;
5252
createdAt?: Date;
5353
updatedAt?: Date;
5454
}

src/rest/membership.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
ErrorCode,
44
Authorizations,
55
ValidationTypes,
6-
EventType
6+
EventType,
7+
NotificationCategories
78
} from "../interfaces/enum";
89
import { getUserByEmail } from "../crud/user";
910
import {
@@ -21,6 +22,8 @@ import { can } from "../helpers/authorization";
2122
import { validate } from "../helpers/utils";
2223
import { Locals, KeyValue } from "../interfaces/general";
2324
import { createEvent } from "../crud/event";
25+
import { createNotification } from "../crud/notification";
26+
import { getOrganization } from "../crud/organization";
2427

2528
export const getMembershipDetailsForUser = async (
2629
userId: number,
@@ -65,6 +68,14 @@ export const inviteMemberToOrganization = async (
6568
} catch (error) {}
6669
if (isMemberAlready) throw new Error(ErrorCode.USER_IS_MEMBER_ALREADY);
6770
await createMembership({ userId: newUser.id, organizationId, role });
71+
await createNotification({
72+
userId: newUser.id,
73+
category: NotificationCategories.JOINED_ORGANIZATION,
74+
text: `You were invited to the organization <strong>${
75+
(await getOrganization(organizationId)).name
76+
}</strong>`,
77+
link: "/settings/organizations"
78+
});
6879
return;
6980
} else {
7081
await register(

src/rest/organization.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
ErrorCode,
1717
EventType,
1818
Authorizations,
19-
ValidationTypes
19+
ValidationTypes,
20+
NotificationCategories
2021
} from "../interfaces/enum";
2122
import {
2223
createEvent,
@@ -42,6 +43,7 @@ import {
4243
import { customers, cards } from "stripe";
4344
import { validate } from "../helpers/utils";
4445
import { getUser } from "../crud/user";
46+
import { createNotification } from "../crud/notification";
4547

4648
export const getOrganizationForUser = async (
4749
userId: number,
@@ -72,6 +74,14 @@ export const newOrganizationForUser = async (
7274
userId,
7375
role: MembershipRole.OWNER
7476
});
77+
await createNotification({
78+
userId,
79+
category: NotificationCategories.JOINED_ORGANIZATION,
80+
text: `You created the organization <strong>${
81+
(await getOrganization(organizationId)).name
82+
}</strong>`,
83+
link: "/settings/organizations"
84+
});
7585
await createEvent(
7686
{
7787
userId,

0 commit comments

Comments
 (0)