mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add either pattern
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
|
||||
export interface NotificationLive {
|
||||
id: string;
|
||||
title: string;
|
||||
Service: string;
|
||||
Object: string;
|
||||
IdObject: string;
|
||||
FolderId: string;
|
||||
body: string;
|
||||
dateInit: string; // Assuming dateInit and dateEnd are strings representing formatted dates
|
||||
dateEnd: string;
|
||||
Location: string;
|
||||
TypeAgenda: string;
|
||||
Role: string;
|
||||
Status: string;
|
||||
read: boolean;
|
||||
}
|
||||
@@ -6,12 +6,18 @@ import { LocalNotificationService } from './datasource/local-notification.servic
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { NotificationListMapper } from '../domain/mapper/notificationListMapper';
|
||||
import { NotificationTable } from './infra/db/notification.db';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { NotificationMapper } from '../domain/mapper/notificationMapper';
|
||||
import { NotificationLive } from './dto/NotificationLiveOutputDTO';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotificationRepositoryService {
|
||||
|
||||
private notificationSubject: Subject<NotificationLive> = new Subject<NotificationLive>();
|
||||
|
||||
constructor(
|
||||
private RemoteNotificationService: RemoteNotificationService,
|
||||
private FirebasePushNotificationService: FirebasePushNotificationService,
|
||||
@@ -19,10 +25,9 @@ export class NotificationRepositoryService {
|
||||
) {
|
||||
|
||||
this.FirebasePushNotificationService.onReceiveForeground(async (data)=> {
|
||||
this.notificationSubject.next(NotificationMapper(data));
|
||||
console.log('FirebasePushNotificationService', data)
|
||||
|
||||
this.init()
|
||||
|
||||
})
|
||||
|
||||
|
||||
@@ -32,6 +37,12 @@ export class NotificationRepositoryService {
|
||||
|
||||
}
|
||||
|
||||
listenToEventNotification(): Observable<any> {
|
||||
return this.notificationSubject.pipe(
|
||||
filter(notification => notification.Service == 'agenda' )
|
||||
)
|
||||
}
|
||||
|
||||
async init() {
|
||||
const result = await this.getNotification({
|
||||
PageNumber: "1",
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { NotificationLive } from '../../data/dto/NotificationLiveOutputDTO';
|
||||
|
||||
|
||||
|
||||
function getFormatedTime(dateString) {
|
||||
var date = new Date(dateString);
|
||||
var hours = date.getHours() /* > 12 ? date.getHours() - 12 : date.getHours() */;
|
||||
var am_pm = date.getHours() >= 12 ? "pm" : "am";
|
||||
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
|
||||
let time = hours + ":" + minutes /* + " " + am_pm */;
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
export function NotificationMapper(notification: any): NotificationLive {
|
||||
|
||||
let notificationObject;
|
||||
|
||||
if (notification.notification) {
|
||||
|
||||
notificationObject = {
|
||||
id: notification?.id || uuidv4(),
|
||||
title: notification.notification.title,
|
||||
Service: notification.data.Service || notification.data.service,
|
||||
Object: notification.data.Object || notification.data.object,
|
||||
IdObject: notification.data.IdObject || notification.data.idObject,
|
||||
FolderId: notification.data.FolderId || notification.data.folderId,
|
||||
body: notification.notification.body,
|
||||
dateInit: getFormatedTime(notification.data.dateInit),
|
||||
dateEnd: getFormatedTime(notification.data.dateEnd),
|
||||
Location: notification.data.Location,
|
||||
TypeAgenda: notification.data.TypeAgenda,
|
||||
Role: notification.data.Role,
|
||||
Status: notification.data.Status,
|
||||
read: false,
|
||||
}
|
||||
|
||||
} else if (notification.data) {
|
||||
notificationObject = {
|
||||
id: notification?.id || uuidv4(),
|
||||
title: notification.title,
|
||||
Service: notification.data.Service || notification.data.service,
|
||||
Object: notification.data.Object || notification.data.object,
|
||||
IdObject: notification.data.IdObject || notification.data.idObject,
|
||||
FolderId: notification.data.FolderId || notification.data.folderId,
|
||||
body: notification.body,
|
||||
dateInit: getFormatedTime(notification.data.dateInit),
|
||||
dateEnd: getFormatedTime(notification.data.dateEnd),
|
||||
Location: notification.data.Location,
|
||||
TypeAgenda: notification.data.TypeAgenda,
|
||||
Role: notification.data.Role,
|
||||
Status: notification.data.Status,
|
||||
read: false,
|
||||
}
|
||||
|
||||
} else {
|
||||
{
|
||||
notificationObject = {
|
||||
id: notification?.id || uuidv4(),
|
||||
FolderId: notification.FolderId || notification.data.folderId,
|
||||
IdObject: notification.IdObject || notification.data.idObject,
|
||||
Location: notification.Location,
|
||||
Object: notification.Object || notification.data.object,
|
||||
Role: notification.Role,
|
||||
Service: notification.Service || notification.data.service,
|
||||
Status: notification.Status,
|
||||
TypeAgenda: notification.TypeAgenda,
|
||||
body: notification.body,
|
||||
dateEnd: notification.dateEnd,
|
||||
dateInit: notification.dateInit,
|
||||
index: notification.index,
|
||||
title: notification.title,
|
||||
read: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return notificationObject
|
||||
}
|
||||
Reference in New Issue
Block a user