From c684f339ae5267d960828e682d52157976c21afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Bucek?= Date: Thu, 25 Aug 2022 21:21:13 +0200 Subject: [PATCH] PohlesBackend: Resolving the Mongoose Populate issue. There is a difference between calling model::populate and doc::populate. When called on the model it alters a build command that is then executed. When called on the document it is automatically executed and returns a Promise. --- src/services/Ticket.service.ts | 19 ++++--------------- src/services/Year.service.ts | 4 ---- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/services/Ticket.service.ts b/src/services/Ticket.service.ts index 42b1633..3128206 100644 --- a/src/services/Ticket.service.ts +++ b/src/services/Ticket.service.ts @@ -28,12 +28,9 @@ export class TicketService { let doc = new this.model(obj); await doc.save(); doc = await doc - .populate("owner") - //@ts-ignore - .populate("year") - .populate("time") - .execPopulate(); + .populate(["owner", "year", "time"]) this.wss.broadcast("new-ticket", doc); + // this.nodemailerService.sendTestMail(); return doc; } @@ -106,11 +103,7 @@ export class TicketService { }); await doc.save(); doc = await doc - .populate("owner") - //@ts-ignore - .populate("year") - .populate("time") - .execPopulate(); + .populate(["owner", "year", "time"]) this.wss.broadcast("new-ticket", doc); await this.nodemailerService.sendAndParse( // @ts-ignore @@ -181,11 +174,7 @@ export class TicketService { obj.save(); let res = await obj - .populate("owner") - //@ts-ignore - .populate("year") - .populate("time") - .execPopulate(); + .populate(["owner", "year", "time"]) this.wss.broadcast("update-ticket", res); return res; } diff --git a/src/services/Year.service.ts b/src/services/Year.service.ts index 564fe86..5c4c9fc 100644 --- a/src/services/Year.service.ts +++ b/src/services/Year.service.ts @@ -17,8 +17,6 @@ export class YearService { await doc.save() doc = await doc .populate("times") - //@ts-ignore - .execPopulate(); this.wss.broadcast("new-year", doc); return doc; } @@ -73,8 +71,6 @@ export class YearService { obj.save(); let res = await obj .populate("times") - //@ts-ignore - .execPopulate() this.wss.broadcast("update-year", res); return res; }