-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ac0c5
commit 150e1a5
Showing
9 changed files
with
164 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Request, Response } from 'express'; | ||
import { getNotificationsService, deleteNotificationService } from '../services'; | ||
|
||
export const getAllNotifications = async (req: Request, res: Response) => { | ||
await getNotificationsService(req, res); | ||
}; | ||
|
||
export const deleteNotification = async (req: Request, res: Response) => { | ||
await deleteNotificationService(req, res); | ||
}; |
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,62 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
ManyToOne, | ||
OneToMany, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { User } from './User'; | ||
import { NotificationItem } from './NotificationItem'; | ||
|
||
@Entity() | ||
export class Notification { | ||
@PrimaryGeneratedColumn('uuid') | ||
@IsNotEmpty() | ||
id!: string; | ||
|
||
@ManyToOne(() => User) | ||
user!: User; | ||
|
||
@OneToMany(() => NotificationItem, notificationItem => notificationItem.notification) | ||
allNotifications!: NotificationItem[]; | ||
|
||
@Column('decimal') | ||
total: number = 0; | ||
|
||
@Column('decimal') | ||
unRead: number = 0; | ||
|
||
@CreateDateColumn() | ||
createdAt!: Date; | ||
|
||
@UpdateDateColumn() | ||
updatedAt!: Date; | ||
|
||
updateTotal (): void { | ||
if (this.allNotifications) { | ||
let total: number = 0; | ||
for (let i = 0; i < this.allNotifications.length; i++) { | ||
total += 1; | ||
} | ||
this.total = total; | ||
} else { | ||
this.total = 0; | ||
} | ||
} | ||
updateUnread (): void { | ||
if (this.allNotifications) { | ||
let unRead: number = 0; | ||
for (let i = 0; i < this.allNotifications.length; i++) { | ||
if(this.allNotifications[i].isRead === false){ | ||
unRead +=1 | ||
} | ||
} | ||
this.unRead = unRead; | ||
} else { | ||
this.unRead = 0; | ||
} | ||
} | ||
} |
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,47 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
ManyToOne, | ||
CreateDateColumn, | ||
} from 'typeorm'; | ||
import { IsNotEmpty, IsIn, IsBoolean } from 'class-validator'; | ||
import { Notification } from './Notification'; | ||
|
||
@Entity() | ||
export class NotificationItem{ | ||
@PrimaryGeneratedColumn('uuid') | ||
@IsNotEmpty() | ||
id!: string; | ||
|
||
@ManyToOne(() => Notification, nofication => nofication.allNotifications, { onDelete: 'CASCADE' }) | ||
@IsNotEmpty() | ||
notification!: Notification; | ||
|
||
@Column() | ||
@IsNotEmpty() | ||
content!: string | ||
|
||
@Column() | ||
@IsNotEmpty() | ||
@IsIn([ | ||
'product', | ||
'cart', | ||
'order', | ||
'user', | ||
'wish list', | ||
'coupon', | ||
]) | ||
type!: string | ||
|
||
@Column({ default: false }) | ||
@IsNotEmpty() | ||
@IsBoolean() | ||
isRead!: boolean | ||
|
||
@Column({ nullable: true }) | ||
link!: string | ||
|
||
@CreateDateColumn() | ||
createdAt!: Date; | ||
} |
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,9 @@ | ||
import { RequestHandler, Router } from 'express'; | ||
import { authMiddleware } from '../middlewares/verifyToken'; | ||
import {getAllNotifications, deleteNotification} from '../controllers/notificarionControllers' | ||
|
||
const router = Router(); | ||
router.get('/', authMiddleware as RequestHandler, getAllNotifications); | ||
router.delete('/:id', authMiddleware as RequestHandler, deleteNotification); | ||
|
||
export default router; |
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
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,9 @@ | ||
import { Request, Response } from 'express'; | ||
import { User } from '../../entities/User'; | ||
import { Notification } from '../../entities/Notification'; | ||
import { NotificationItem } from '../../entities/NotificationItem'; | ||
import { getRepository } from 'typeorm'; | ||
|
||
export const deleteNotificationService = async(req: Request, res: Response) => { | ||
|
||
} |
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,8 @@ | ||
import { Request, Response } from 'express'; | ||
import { User } from '../../entities/User'; | ||
import { Notification } from '../../entities/Notification'; | ||
import { getRepository } from 'typeorm'; | ||
|
||
export const getNotificationsService = async(req: Request, res: Response) => { | ||
|
||
} |
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,13 @@ | ||
import { Notification } from "../entities/Notification"; | ||
import { NotificationItem } from "../entities/NotificationItem"; | ||
import { getRepository } from 'typeorm'; | ||
|
||
interface noticationInfo{ | ||
content: string; | ||
type: string; | ||
link?: string; | ||
} | ||
|
||
export const sendNotification = (data: noticationInfo) =>{ | ||
|
||
} |