chore: project controller ok

This commit is contained in:
xiaojunnuo
2026-02-13 21:28:17 +08:00
parent 3f87752d1f
commit 4ee6e38a94
42 changed files with 399 additions and 198 deletions
@@ -3,22 +3,24 @@ import {NotificationService} from "../notification-service.js";
export class NotificationGetter implements INotificationService {
userId: number;
projectId: number;
notificationService: NotificationService;
constructor(userId: number, notificationService: NotificationService) {
constructor(userId: number, projectId: number, notificationService: NotificationService) {
this.userId = userId;
this.projectId = projectId;
this.notificationService = notificationService;
}
async getDefault() {
return await this.notificationService.getDefault(this.userId);
return await this.notificationService.getDefault(this.userId, this.projectId);
}
async getById(id: any) {
return await this.notificationService.getById(id, this.userId);
return await this.notificationService.getById(id, this.userId, this.projectId);
}
async send(req: NotificationSendReq): Promise<void> {
return await this.notificationService.send(req, this.userId);
return await this.notificationService.send(req, this.userId, this.projectId);
}
}
@@ -15,9 +15,11 @@ const serviceNames = [
]
export class TaskServiceGetter implements IServiceGetter{
private userId: number;
private projectId: number;
private appCtx : IMidwayContainer;
constructor(userId:number,appCtx:IMidwayContainer) {
constructor(userId:number,projectId:number,appCtx:IMidwayContainer) {
this.userId = userId;
this.projectId = projectId;
this.appCtx = appCtx
}
async get<T>(serviceName: string): Promise<T> {
@@ -51,7 +53,7 @@ export class TaskServiceGetter implements IServiceGetter{
async getAccessService(): Promise<AccessGetter> {
const accessService:AccessService = await this.appCtx.getAsync("accessService")
return new AccessGetter(this.userId, accessService.getById.bind(accessService));
return new AccessGetter(this.userId, this.projectId, accessService.getById.bind(accessService));
}
@@ -62,7 +64,7 @@ export class TaskServiceGetter implements IServiceGetter{
async getNotificationService(): Promise<NotificationGetter> {
const notificationService:NotificationService = await this.appCtx.getAsync("notificationService")
return new NotificationGetter(this.userId, notificationService);
return new NotificationGetter(this.userId, this.projectId, notificationService);
}
async getDomainVerifierGetter(): Promise<DomainVerifierGetter> {
@@ -78,12 +80,14 @@ export class TaskServiceBuilder {
create(req:TaskServiceCreateReq){
const userId = req.userId;
return new TaskServiceGetter(userId,this.appCtx)
const projectId = req.projectId;
return new TaskServiceGetter(userId,projectId,this.appCtx)
}
}
export type TaskServiceCreateReq = {
userId: number;
projectId?: number;
}
@@ -84,7 +84,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
}
}
async getById(id: number, userId: number): Promise<NotificationInstanceConfig> {
async getById(id: number, userId: number, projectId?: number): Promise<NotificationInstanceConfig> {
if (!id) {
throw new ValidateException('id不能为空');
}
@@ -95,6 +95,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
where: {
id,
userId,
projectId,
},
});
if (!res) {
@@ -114,10 +115,11 @@ export class NotificationService extends BaseService<NotificationEntity> {
};
}
async getDefault(userId: number): Promise<NotificationInstanceConfig> {
async getDefault(userId: number, projectId?: number): Promise<NotificationInstanceConfig> {
const res = await this.repository.findOne({
where: {
userId,
projectId,
},
order: {
isDefault: 'DESC',
@@ -129,7 +131,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
return this.buildNotificationInstanceConfig(res);
}
async setDefault(id: number, userId: number) {
async setDefault(id: number, userId: number, projectId?: number) {
if (!id) {
throw new ValidateException('id不能为空');
}
@@ -139,6 +141,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
await this.repository.update(
{
userId,
projectId,
},
{
isDefault: false,
@@ -148,6 +151,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
{
id,
userId,
projectId,
},
{
isDefault: true,
@@ -155,8 +159,8 @@ export class NotificationService extends BaseService<NotificationEntity> {
);
}
async getOrCreateDefault(email: string, userId: any) {
const defaultConfig = await this.getDefault(userId);
async getOrCreateDefault(email: string, userId: any, projectId?: number) {
const defaultConfig = await this.getDefault(userId, projectId);
if (defaultConfig) {
return defaultConfig;
}
@@ -169,21 +173,22 @@ export class NotificationService extends BaseService<NotificationEntity> {
name: '邮件通知',
setting: JSON.stringify(setting),
isDefault: true,
projectId,
});
return this.buildNotificationInstanceConfig(res);
}
async send(req: NotificationSendReq, userId?: number) {
async send(req: NotificationSendReq, userId?: number, projectId?: number) {
const logger = req.logger;
let notifyConfig: NotificationInstanceConfig = null;
if (req.id && req.id > 0) {
notifyConfig = await this.getById(req.id, userId);
notifyConfig = await this.getById(req.id, userId, projectId);
if (!notifyConfig) {
logger.warn(`未找到通知配置<${req.id}>,请确认是否已被删除`);
}
}
if (!notifyConfig) {
notifyConfig = await this.getDefault(userId);
notifyConfig = await this.getDefault(userId, projectId);
if (!notifyConfig) {
logger.warn(`未找到默认通知配置`);
}