update database
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import 'dart:convert';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
|
||||
part 'notification_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.notificationModel)
|
||||
class NotificationModel extends HiveObject {
|
||||
NotificationModel({required this.notificationId, required this.userId, required this.type, required this.title, required this.message, this.data, required this.isRead, required this.isPushed, required this.createdAt, this.readAt});
|
||||
|
||||
@HiveField(0) final String notificationId;
|
||||
@HiveField(1) final String userId;
|
||||
@HiveField(2) final String type;
|
||||
@HiveField(3) final String title;
|
||||
@HiveField(4) final String message;
|
||||
@HiveField(5) final String? data;
|
||||
@HiveField(6) final bool isRead;
|
||||
@HiveField(7) final bool isPushed;
|
||||
@HiveField(8) final DateTime createdAt;
|
||||
@HiveField(9) final DateTime? readAt;
|
||||
|
||||
factory NotificationModel.fromJson(Map<String, dynamic> json) => NotificationModel(
|
||||
notificationId: json['notification_id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
type: json['type'] as String,
|
||||
title: json['title'] as String,
|
||||
message: json['message'] as String,
|
||||
data: json['data'] != null ? jsonEncode(json['data']) : null,
|
||||
isRead: json['is_read'] as bool? ?? false,
|
||||
isPushed: json['is_pushed'] as bool? ?? false,
|
||||
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
|
||||
readAt: json['read_at'] != null ? DateTime.parse(json['read_at']?.toString() ?? '') : null,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'notification_id': notificationId,
|
||||
'user_id': userId,
|
||||
'type': type,
|
||||
'title': title,
|
||||
'message': message,
|
||||
'data': data != null ? jsonDecode(data!) : null,
|
||||
'is_read': isRead,
|
||||
'is_pushed': isPushed,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'read_at': readAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
Map<String, dynamic>? get dataMap {
|
||||
if (data == null) return null;
|
||||
try {
|
||||
return jsonDecode(data!) as Map<String, dynamic>;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user