Notification system enhanced
- Base for notifcation center - Show text in map if no data is available
This commit is contained in:
18
backend/models/notifications/notification.interface.ts
Normal file
18
backend/models/notifications/notification.interface.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Document } from "mongoose";
|
||||
import { IUser } from "../user/user.interface";
|
||||
|
||||
export enum ISeverity {
|
||||
INFO = 0,
|
||||
SUCCESS = 1,
|
||||
WARN = 2,
|
||||
ERROR = 3
|
||||
}
|
||||
|
||||
export type NotificationType = 'beat' | 'phone_alive' | 'phone_dead' | 'phone_register' | 'panic';
|
||||
|
||||
export interface INotification extends Document {
|
||||
type: NotificationType;
|
||||
severity: ISeverity;
|
||||
message: any;
|
||||
user: IUser;
|
||||
}
|
||||
11
backend/models/notifications/notification.model.ts
Normal file
11
backend/models/notifications/notification.model.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Model, model } from 'mongoose';
|
||||
import { IUser } from '../user/user.interface';
|
||||
import { INotification, ISeverity, NotificationType } from './notification.interface';
|
||||
import { schemaNotification } from './notification.schema';
|
||||
|
||||
const modelNotification: Model<INotification> = model<INotification>('Notification', schemaNotification, 'Notification');
|
||||
export { modelNotification as Notification };
|
||||
|
||||
export function addNotification(type: NotificationType, severity: ISeverity, message: any, user: IUser) {
|
||||
return modelNotification.create({ type, severity, message, user });
|
||||
}
|
||||
15
backend/models/notifications/notification.schema.ts
Normal file
15
backend/models/notifications/notification.schema.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Schema, SchemaTypes } from 'mongoose';
|
||||
const schemaNotification = new Schema({
|
||||
type: { type: String, required: true },
|
||||
severity: { type: Number, required: true },
|
||||
message: { type: Object, required: true },
|
||||
user: { type: SchemaTypes.ObjectId }
|
||||
}, {
|
||||
timestamps: {
|
||||
createdAt: true,
|
||||
updatedAt: false
|
||||
},
|
||||
versionKey: false
|
||||
});
|
||||
|
||||
export { schemaNotification };
|
||||
Reference in New Issue
Block a user