From 5dd4504d30658f34bd2d45df34048b5b3177d138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santos?= Date: Wed, 18 Oct 2023 20:38:57 +0100 Subject: [PATCH] fixed pre save in Process --- src/models/Process.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/models/Process.ts b/src/models/Process.ts index 839d783..6dcc54e 100644 --- a/src/models/Process.ts +++ b/src/models/Process.ts @@ -1,6 +1,6 @@ import { Types, Document } from 'mongoose'; import { Resource } from './Resource'; -import { Triple, TripleClass, TripleDocument } from './Triple'; +import { Triple, TripleClass } from './Triple'; import { humanize } from 'humanize-digest'; import { Domain } from './Domain'; import { Path, PathDocument } from './Path'; @@ -17,7 +17,8 @@ import { @index({ createdAt: 1 }) @pre('save', async function () { const today = new Date(new Date().setUTCHours(0, 0, 0, 0)); - const count = await this.collection.countDocuments({ + + const count = await Process.countDocuments({ createdAt: { $gt: today }, }); if (!this.pid) { @@ -25,6 +26,9 @@ import { const word = humanize(date); this.pid = `${word}-${date}`; } + if (!this.notification) { + this.notification = {}; + } this.notification.ssePath = `/processes/${this.pid}/events`; }) class NotificationClass { @@ -55,7 +59,7 @@ class ProcessClass { createdAt!: Date; updatedAt!: Date; - @prop({ required: true, index: true, unique: true }) + @prop({ index: true, unique: true }) public pid!: string; @prop({ required: true })