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
This commit is contained in:
ChengLei Shao 2022-04-24 22:33:40 +08:00 committed by GitHub
parent b1086ee728
commit c1f94d3d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,6 @@ import { NotificationService } from './NotificationService';
import _ from 'lodash'; import _ from 'lodash';
export class Notification extends Model { export class Notification extends Model {
[key: string]: any; [key: string]: any;
get db(): Database { get db(): Database {
@ -20,12 +19,14 @@ export class Notification extends Model {
const rows = await collection.repository.find({ const rows = await collection.repository.find({
filter, filter,
}); });
receivers = rows.map(row => row[dataField]); receivers = rows.map((row) => row[dataField]);
} }
return receivers; return receivers;
} }
async send(options: any = {}) { async send(options: any = {}) {
const { transaction } = options;
if (!this.service) { if (!this.service) {
this.service = await this.getService(); this.service = await this.getService();
} }
@ -35,7 +36,7 @@ export class Notification extends Model {
to = Array.isArray(to) ? to : [to]; to = Array.isArray(to) ? to : [to];
receivers.push(...to); receivers.push(...to);
} }
console.log(receivers) console.log(receivers);
for (const receiver of receivers) { for (const receiver of receivers) {
try { try {
const response = await (this.service as NotificationService).send({ const response = await (this.service as NotificationService).send({
@ -43,21 +44,31 @@ export class Notification extends Model {
subject: this.getSubject(), subject: this.getSubject(),
html: this.getBody(options), html: this.getBody(options),
}); });
await this.createLog({ await this.createLog(
{
receiver, receiver,
state: 'success', state: 'success',
response, response,
}); },
{
transaction,
},
);
await new Promise((resolve) => { await new Promise((resolve) => {
setTimeout(resolve, 100); setTimeout(resolve, 100);
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await this.createLog({ await this.createLog(
{
receiver, receiver,
state: 'fail', state: 'fail',
response: {}, response: {},
}); },
{
transaction,
},
);
} }
} }
} }
@ -67,7 +78,7 @@ export class Notification extends Model {
} }
getBody(data) { getBody(data) {
const compiled = _.template(this.body) const compiled = _.template(this.body);
const body = compiled(data); const body = compiled(data);
return body; return body;
} }