diff --git a/server/AyaNova/Controllers/NotifyController.cs b/server/AyaNova/Controllers/NotifyController.cs index 76fec30f..d96220e0 100644 --- a/server/AyaNova/Controllers/NotifyController.cs +++ b/server/AyaNova/Controllers/NotifyController.cs @@ -125,7 +125,17 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); } - var ret = await ct.NotifyEvent.Select(z => new { z.Id, z.Created, z.EventDate, z.UserId, z.EventType, z.AyaType, z.Name }).ToListAsync(); + var ret = await ct.NotifyEvent.Include(z => z.NotifySubscription).Select(z => new + { + z.Id, + z.Created, + z.EventDate, + DeliverAfter = (z.EventDate + z.NotifySubscription.AgeValue - z.NotifySubscription.AdvanceNotice), + z.UserId, + z.EventType, + z.AyaType, + z.Name + }).ToListAsync(); return Ok(ApiOkResponse.Response(ret)); } diff --git a/server/AyaNova/biz/NotifyEventProcessor.cs b/server/AyaNova/biz/NotifyEventProcessor.cs index 0b4dab35..5acea4bd 100644 --- a/server/AyaNova/biz/NotifyEventProcessor.cs +++ b/server/AyaNova/biz/NotifyEventProcessor.cs @@ -158,8 +158,7 @@ namespace AyaNova.Biz UserId = sub.UserId, ObjectId = newObject.Id, NotifySubscriptionId = sub.Id, - //TODO: IdValue=((WorkOrder)newObject).WorkorderStatusId - EventDate = DateTime.UtcNow, + //TODO: IdValue=((WorkOrder)newObject).WorkorderStatusId Name = newObject.Name }; await ct.NotifyEvent.AddAsync(n); @@ -226,7 +225,6 @@ namespace AyaNova.Biz AyaType = newObject.AyaType, ObjectId = newObject.Id, NotifySubscriptionId = sub.Id, - EventDate = DateTime.UtcNow, Name = newObject.Name }; await ct.NotifyEvent.AddAsync(n); diff --git a/server/AyaNova/generator/CoreJobNotify.cs b/server/AyaNova/generator/CoreJobNotify.cs index fd1e1694..1bec5df0 100644 --- a/server/AyaNova/generator/CoreJobNotify.cs +++ b/server/AyaNova/generator/CoreJobNotify.cs @@ -128,7 +128,7 @@ namespace AyaNova.Biz if (notifyevent.NotifySubscription.AgeValue != TimeSpan.Zero) { var deliverAfter = notifyevent.EventDate + notifyevent.NotifySubscription.AgeValue - notifyevent.NotifySubscription.AdvanceNotice; - if (deliverAfter > DateTime.UtcNow) + if (deliverAfter < DateTime.UtcNow) { if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.App) { diff --git a/server/AyaNova/models/NotifyEvent.cs b/server/AyaNova/models/NotifyEvent.cs index 9c798b62..3c3e3ce3 100644 --- a/server/AyaNova/models/NotifyEvent.cs +++ b/server/AyaNova/models/NotifyEvent.cs @@ -19,7 +19,7 @@ namespace AyaNova.Models public AyaType AyaType { get; set; } public long ObjectId { get; set; } [Required] - public string Name {get;set;}//object name or closest equivalent for display + public string Name { get; set; }//object name or closest equivalent for display [Required] public NotifyEventType EventType { get; set; } [Required] @@ -31,10 +31,10 @@ namespace AyaNova.Models [Required] public decimal DecValue { get; set; } - // [Required]// public TimeSpan AgeValue { get; set; } + // [Required]// public TimeSpan AgeValue { get; set; } //date of the event actually occuring, e.g. WarrantyExpiry date. Compared with subscription to determine if deliverable or not - public DateTime? EventDate { get; set; } + public DateTime EventDate { get; set; } //NO: Delivery code consults subscription instead of this // public DateTime? DeliverDate { get; set; }//date user wants the event notification delivered, usually same as event date but could be set earlier if Advance setting in effect. This is the date consulted for delivery only. public string Message { get; set; } @@ -42,13 +42,13 @@ namespace AyaNova.Models public NotifyEvent() { - Created = DateTime.UtcNow; + Created = EventDate = DateTime.UtcNow; IdValue = 0; DecValue = 0; - // AgeValue = TimeSpan.Zero; + // AgeValue = TimeSpan.Zero; AyaType = AyaType.NoType; ObjectId = 0; - Name=string.Empty; + Name = string.Empty; } public override string ToString() @@ -56,7 +56,7 @@ namespace AyaNova.Models return JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.None); } - //linked entity + //linked entity public NotifySubscription NotifySubscription { get; set; } }//eoc diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 53785b45..e4142ea8 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -337,7 +337,7 @@ $BODY$; //Add user options table await ExecQueryAsync("CREATE TABLE auseroptions (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " + - "userid bigint not null, translationid bigint not null REFERENCES atranslation (id), languageoverride text, timezoneoverride text, "+ + "userid bigint not null, translationid bigint not null REFERENCES atranslation (id), languageoverride text, timezoneoverride text, " + "currencyname text, hour12 bool not null, emailaddress text, uicolor varchar(12) not null default '#000000')"); @@ -691,7 +691,7 @@ $BODY$; await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created timestamp not null, " + "ayatype integer not null, objectid bigint not null, name varchar(255) not null, eventtype integer not null, notifysubscriptionid bigint not null references anotifysubscription(id) on delete cascade, " + - "userid bigint not null, idvalue bigint not null, decvalue decimal(19,4) not null, eventdate timestamp, message text)"); + "userid bigint not null, idvalue bigint not null, decvalue decimal(19,4) not null, eventdate timestamp not null, message text)"); await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid bigint not null, " +