Skip to content

Commit

Permalink
fixed pre save in Process
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefs committed Oct 18, 2023
1 parent 83c358b commit 5dd4504
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/models/Process.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,14 +17,18 @@ import {
@index({ createdAt: 1 })
@pre<ProcessClass>('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) {
const date = today.toISOString().split('T')[0] + '-' + count;
const word = humanize(date);
this.pid = `${word}-${date}`;
}
if (!this.notification) {
this.notification = {};
}
this.notification.ssePath = `/processes/${this.pid}/events`;
})
class NotificationClass {
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit 5dd4504

Please sign in to comment.