From c1f94d3d1bff3e277a686a1cd680b1317bd9c852 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Sun, 24 Apr 2022 22:33:40 +0800 Subject: [PATCH] Fix multiple apps (#317) * chore: multiple apps * fix: multiple apps with application options * fix: multiple apps AppSelector type * chore: multiple apps with plugin config * chore: rename multiple-apps to multiple-apps-manager * chore: application association * chore: plugin multi-app manager * chore: notifications transaction --- .../notifications/src/models/Notification.ts | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/plugins/notifications/src/models/Notification.ts b/packages/plugins/notifications/src/models/Notification.ts index 273f336b8..05cc547df 100644 --- a/packages/plugins/notifications/src/models/Notification.ts +++ b/packages/plugins/notifications/src/models/Notification.ts @@ -3,7 +3,6 @@ import { NotificationService } from './NotificationService'; import _ from 'lodash'; export class Notification extends Model { - [key: string]: any; get db(): Database { @@ -20,12 +19,14 @@ export class Notification extends Model { const rows = await collection.repository.find({ filter, }); - receivers = rows.map(row => row[dataField]); + receivers = rows.map((row) => row[dataField]); } return receivers; } async send(options: any = {}) { + const { transaction } = options; + if (!this.service) { this.service = await this.getService(); } @@ -35,7 +36,7 @@ export class Notification extends Model { to = Array.isArray(to) ? to : [to]; receivers.push(...to); } - console.log(receivers) + console.log(receivers); for (const receiver of receivers) { try { const response = await (this.service as NotificationService).send({ @@ -43,21 +44,31 @@ export class Notification extends Model { subject: this.getSubject(), html: this.getBody(options), }); - await this.createLog({ - receiver, - state: 'success', - response, - }); + await this.createLog( + { + receiver, + state: 'success', + response, + }, + { + transaction, + }, + ); await new Promise((resolve) => { setTimeout(resolve, 100); }); } catch (error) { console.error(error); - await this.createLog({ - receiver, - state: 'fail', - response: {}, - }); + await this.createLog( + { + receiver, + state: 'fail', + response: {}, + }, + { + transaction, + }, + ); } } } @@ -67,7 +78,7 @@ export class Notification extends Model { } getBody(data) { - const compiled = _.template(this.body) + const compiled = _.template(this.body); const body = compiled(data); return body; }