This repository was archived by the owner on Apr 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed
Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { dateToDateTime } from "../helpers/utils";
1616export 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 ) } ` ,
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 33 ErrorCode ,
44 Authorizations ,
55 ValidationTypes ,
6- EventType
6+ EventType ,
7+ NotificationCategories
78} from "../interfaces/enum" ;
89import { getUserByEmail } from "../crud/user" ;
910import {
@@ -21,6 +22,8 @@ import { can } from "../helpers/authorization";
2122import { validate } from "../helpers/utils" ;
2223import { Locals , KeyValue } from "../interfaces/general" ;
2324import { createEvent } from "../crud/event" ;
25+ import { createNotification } from "../crud/notification" ;
26+ import { getOrganization } from "../crud/organization" ;
2427
2528export 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 (
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ import {
1616 ErrorCode ,
1717 EventType ,
1818 Authorizations ,
19- ValidationTypes
19+ ValidationTypes ,
20+ NotificationCategories
2021} from "../interfaces/enum" ;
2122import {
2223 createEvent ,
@@ -42,6 +43,7 @@ import {
4243import { customers , cards } from "stripe" ;
4344import { validate } from "../helpers/utils" ;
4445import { getUser } from "../crud/user" ;
46+ import { createNotification } from "../crud/notification" ;
4547
4648export 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,
You can’t perform that action at this time.
0 commit comments