chore: project controller

This commit is contained in:
xiaojunnuo
2026-02-11 00:07:29 +08:00
parent 784bcb0aa5
commit 1e416b9f8a
33 changed files with 773 additions and 53 deletions

View File

@@ -1,11 +1,17 @@
import { Inject } from '@midwayjs/core';
import { ApplicationContext, Inject } from '@midwayjs/core';
import type {IMidwayContainer} from '@midwayjs/core';
import * as koa from '@midwayjs/koa';
import { Constants } from './constants.js';
import { isEnterprise } from './mode.js';
export abstract class BaseController {
@Inject()
ctx: koa.Context;
@ApplicationContext()
applicationContext: IMidwayContainer;
/**
* 成功返回
* @param data 返回数据
@@ -55,4 +61,36 @@ export abstract class BaseController {
}
}
getProjectId(permission:string) {
if (!isEnterprise()) {
return null
}
const projectIdStr = this.ctx.headers["project-id"] as string;
if (!projectIdStr) {
throw new Error("projectId 不能为空")
}
const userId = this.getUserId()
const projectId = parseInt(projectIdStr)
this.checkProjectPermission(userId, projectId,permission)
return projectId;
}
getProjectUserId(permission:string){
let userId = this.getUserId()
const projectId = this.getProjectId(permission)
if(projectId){
userId = 0
}
return {
projectId,userId
}
}
async checkProjectPermission(userId: number, projectId: number,permission:string) {
const projectService:any = await this.applicationContext.getAsync("projectService");
await projectService.checkPermission({userId,projectId,permission})
}
}