platform/packages/model/lib/angel3_model.dart

36 lines
909 B
Dart
Raw Normal View History

2023-01-02 01:01:11 +00:00
/// Represents a generic data model with an ID and timestamps.
2017-07-11 20:46:12 +00:00
class Model {
2018-12-31 00:30:23 +00:00
/// A unique identifier corresponding to this item.
2021-08-08 02:45:56 +00:00
String? id;
2018-12-31 00:30:23 +00:00
/// The time at which this item was created.
2021-03-18 00:15:01 +00:00
DateTime? createdAt;
2018-12-31 00:30:23 +00:00
/// The last time at which this item was updated.
2021-03-18 00:15:01 +00:00
DateTime? updatedAt;
2017-07-11 20:46:12 +00:00
2021-08-08 02:45:56 +00:00
Model({this.id, this.createdAt, this.updatedAt});
2018-12-31 00:30:23 +00:00
/// Returns the [id], parsed as an [int].
2023-01-02 01:01:11 +00:00
int get idAsInt => id != null ? int.tryParse(id ?? "-1") ?? -1 : -1;
/// Returns the [id] or "" if null.
String get idAsString => id ?? "";
}
/// Represents a generic data model with audit log feature.
class AuditableModel extends Model {
/// The authorized user who created the record.
String? createdBy;
/// The user who updated the record last time.
String? updatedBy;
AuditableModel(
{super.id,
super.createdAt,
this.createdBy,
super.updatedAt,
this.updatedBy});
2018-12-31 00:30:23 +00:00
}