mirror of https://github.com/certd/certd
chore: 优化 notification check plus
parent
5969f71e67
commit
e65f5b9f78
|
@ -4,7 +4,6 @@ import { FormItemProps, HistoryResult, Pipeline } from "../dt/index.js";
|
||||||
import { HttpClient, ILogger, utils } from "@certd/basic";
|
import { HttpClient, ILogger, utils } from "@certd/basic";
|
||||||
import * as _ from "lodash-es";
|
import * as _ from "lodash-es";
|
||||||
import { IEmailService } from "../service/index.js";
|
import { IEmailService } from "../service/index.js";
|
||||||
import { isPlus } from "@certd/plus-core";
|
|
||||||
|
|
||||||
export type NotificationBody = {
|
export type NotificationBody = {
|
||||||
userId?: number;
|
userId?: number;
|
||||||
|
@ -81,9 +80,6 @@ export abstract class BaseNotification implements INotification {
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
|
|
||||||
async doSend(body: NotificationBody) {
|
async doSend(body: NotificationBody) {
|
||||||
if (this.define.needPlus && !isPlus()) {
|
|
||||||
body.content = `${body.content}\n\n注意:此通知渠道已调整为专业版功能,后续版本将不再支持发送,请尽快修改或升级为专业版`;
|
|
||||||
}
|
|
||||||
return await this.send(body);
|
return await this.send(body);
|
||||||
}
|
}
|
||||||
abstract send(body: NotificationBody): Promise<void>;
|
abstract send(body: NotificationBody): Promise<void>;
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||||
import { BaseService, SysInstallInfo, SysSettingsService, SysSiteInfo, ValidateException } from '@certd/lib-server';
|
import {
|
||||||
|
BaseService,
|
||||||
|
NeedVIPException,
|
||||||
|
SysInstallInfo,
|
||||||
|
SysSettingsService,
|
||||||
|
SysSiteInfo,
|
||||||
|
ValidateException
|
||||||
|
} from "@certd/lib-server";
|
||||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { NotificationEntity } from '../entity/notification.js';
|
import { NotificationEntity } from '../entity/notification.js';
|
||||||
import { NotificationInstanceConfig, notificationRegistry, NotificationSendReq, sendNotification } from '@certd/pipeline';
|
import { NotificationInstanceConfig, notificationRegistry, NotificationSendReq, sendNotification } from '@certd/pipeline';
|
||||||
import { http, utils } from '@certd/basic';
|
import { http, utils } from '@certd/basic';
|
||||||
import { EmailService } from '../../basic/service/email-service.js';
|
import { EmailService } from '../../basic/service/email-service.js';
|
||||||
import { isComm } from '@certd/plus-core';
|
import { isComm, isPlus } from '@certd/plus-core';
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||||
|
@ -46,6 +53,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async add(bean: NotificationEntity) {
|
async add(bean: NotificationEntity) {
|
||||||
|
this.checkNeedPlus(bean.type);
|
||||||
const res = await super.add(bean);
|
const res = await super.add(bean);
|
||||||
if(bean.isDefault){
|
if(bean.isDefault){
|
||||||
await this.setDefault(res.id, bean.userId);
|
await this.setDefault(res.id, bean.userId);
|
||||||
|
@ -54,14 +62,28 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(bean: NotificationEntity) {
|
async update(bean: NotificationEntity) {
|
||||||
|
|
||||||
|
const old = await this.info(bean.id);
|
||||||
|
this.checkNeedPlus(old.type);
|
||||||
|
|
||||||
|
delete bean.userId;
|
||||||
|
delete bean.type
|
||||||
const res = await super.update(bean);
|
const res = await super.update(bean);
|
||||||
if(bean.isDefault){
|
if(bean.isDefault){
|
||||||
const old = await this.info(bean.id);
|
|
||||||
await this.setDefault(bean.id, old.userId);
|
await this.setDefault(bean.id, old.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkNeedPlus(type: string){
|
||||||
|
const define = this.getDefineByType(type)
|
||||||
|
//@ts-ignore
|
||||||
|
if (define.needPlus && !isPlus()) {
|
||||||
|
throw new NeedVIPException("此通知类型为专业版功能,请升级到专业版或以上级别");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getById(id: number, userId: number): Promise<NotificationInstanceConfig> {
|
async getById(id: number, userId: number): Promise<NotificationInstanceConfig> {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
throw new ValidateException('id不能为空');
|
throw new ValidateException('id不能为空');
|
||||||
|
|
Loading…
Reference in New Issue