mirror of
https://github.com/certd/certd.git
synced 2026-07-15 10:17:33 +08:00
refactor: 统一userProject查询参数传递逻辑
This commit is contained in:
@@ -50,7 +50,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||
this.checkNeedPlus(bean.type);
|
||||
const res = await super.add(bean);
|
||||
if (bean.isDefault) {
|
||||
await this.setDefault(res.id, bean.userId);
|
||||
await this.setDefault(res.id, bean.userId, bean.projectId);
|
||||
}
|
||||
bean.keyId = "nt_" + utils.id.simpleNanoId();
|
||||
return res;
|
||||
@@ -65,7 +65,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||
delete bean.keyId;
|
||||
const res = await super.update(bean);
|
||||
if (bean.isDefault) {
|
||||
await this.setDefault(bean.id, old.userId);
|
||||
await this.setDefault(bean.id, old.userId, old.projectId);
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -86,11 +86,11 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||
if (userId == null) {
|
||||
throw new ValidateException("userId不能为空");
|
||||
}
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
const res = await this.repository.findOne({
|
||||
where: {
|
||||
id,
|
||||
userId,
|
||||
projectId,
|
||||
...userProjectQuery,
|
||||
},
|
||||
});
|
||||
if (!res) {
|
||||
@@ -111,10 +111,10 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||
}
|
||||
|
||||
async getDefault(userId: number, projectId?: number): Promise<NotificationInstanceConfig> {
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
const res = await this.repository.findOne({
|
||||
where: {
|
||||
userId,
|
||||
projectId,
|
||||
...userProjectQuery,
|
||||
},
|
||||
order: {
|
||||
isDefault: "DESC",
|
||||
@@ -133,12 +133,7 @@ export class NotificationService extends BaseService<NotificationEntity> {
|
||||
if (userId == null) {
|
||||
throw new ValidateException("userId不能为空");
|
||||
}
|
||||
const query: any = {
|
||||
userId,
|
||||
};
|
||||
if (projectId) {
|
||||
query.projectId = projectId;
|
||||
}
|
||||
const query = this.buildUserProjectQuery(userId, projectId);
|
||||
await this.repository.update(query, {
|
||||
isDefault: false,
|
||||
});
|
||||
|
||||
@@ -876,41 +876,50 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
|
||||
async count(param: { userId?: any; projectId?: number }) {
|
||||
const query: any = {
|
||||
userId: param.userId,
|
||||
isTemplate: false,
|
||||
};
|
||||
if (param.projectId != null) {
|
||||
query.projectId = param.projectId;
|
||||
}
|
||||
const count = await this.repository.count({
|
||||
where: {
|
||||
userId: param.userId,
|
||||
projectId: param.projectId,
|
||||
isTemplate: false,
|
||||
},
|
||||
where: query,
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
async statusCount(param: { userId?: any; projectId?: number } = {}) {
|
||||
const query: any = {
|
||||
userId: param.userId,
|
||||
isTemplate: false,
|
||||
};
|
||||
if (param.projectId != null) {
|
||||
query.projectId = param.projectId;
|
||||
}
|
||||
const statusCount = await this.repository
|
||||
.createQueryBuilder()
|
||||
.select("status")
|
||||
.addSelect("count(1)", "count")
|
||||
.where({
|
||||
userId: param.userId,
|
||||
projectId: param.projectId,
|
||||
isTemplate: false,
|
||||
})
|
||||
.where(query)
|
||||
.groupBy("status")
|
||||
.getRawMany();
|
||||
return statusCount;
|
||||
}
|
||||
|
||||
async enableCount(param: { userId?: any; projectId?: number } = {}) {
|
||||
const query: any = {
|
||||
userId: param.userId,
|
||||
isTemplate: false,
|
||||
};
|
||||
if (param.projectId != null) {
|
||||
query.projectId = param.projectId;
|
||||
}
|
||||
const statusCount = await this.repository
|
||||
.createQueryBuilder()
|
||||
.select("disabled")
|
||||
.addSelect("count(1)", "count")
|
||||
.where({
|
||||
userId: param.userId,
|
||||
projectId: param.projectId,
|
||||
isTemplate: false,
|
||||
})
|
||||
.where(query)
|
||||
.groupBy("disabled")
|
||||
.getRawMany();
|
||||
const result = {
|
||||
@@ -924,6 +933,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
|
||||
async latestExpiringList({ userId, projectId }: any) {
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
let list = await this.repository.find({
|
||||
select: {
|
||||
id: true,
|
||||
@@ -931,9 +941,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
status: true,
|
||||
},
|
||||
where: {
|
||||
userId,
|
||||
...userProjectQuery,
|
||||
disabled: false,
|
||||
projectId,
|
||||
isTemplate: false,
|
||||
},
|
||||
});
|
||||
@@ -1262,6 +1271,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
|
||||
async getSimplePipelines(pipelineIds: number[], userId?: number, projectId?: number) {
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
return await this.repository.find({
|
||||
select: {
|
||||
id: true,
|
||||
@@ -1269,8 +1279,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
},
|
||||
where: {
|
||||
id: In(pipelineIds),
|
||||
userId,
|
||||
projectId,
|
||||
...userProjectQuery,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ export class SubDomainService extends BaseService<SubDomainEntity> {
|
||||
if (userId == null) {
|
||||
return [];
|
||||
}
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
const list = await this.find({
|
||||
where: {
|
||||
userId,
|
||||
projectId,
|
||||
...userProjectQuery,
|
||||
disabled: false,
|
||||
},
|
||||
});
|
||||
@@ -45,11 +45,11 @@ export class SubDomainService extends BaseService<SubDomainEntity> {
|
||||
if (userId == null) {
|
||||
throw new Error("用户ID不能为空");
|
||||
}
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
const exist = await this.repository.findOne({
|
||||
where: {
|
||||
domain,
|
||||
userId,
|
||||
projectId,
|
||||
...userProjectQuery,
|
||||
},
|
||||
});
|
||||
if (exist) {
|
||||
|
||||
Reference in New Issue
Block a user