refactor: 统一userProject查询参数传递逻辑

This commit is contained in:
xiaojunnuo
2026-06-04 00:00:40 +08:00
parent cdb812ef63
commit 2cbacb4338
30 changed files with 158 additions and 134 deletions
@@ -56,11 +56,11 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
}
async updateDomains(pipelineId: number, userId: number, projectId: number, domains: string[], fromType?: string) {
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
const found = await this.repository.findOne({
where: {
pipelineId,
userId,
projectId,
...userProjectQuery,
},
});
const bean = new CertInfoEntity();
@@ -112,6 +112,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
});
}
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
const list = await this.find({
select: {
id: true,
@@ -120,8 +121,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
pipelineId: true,
},
where: {
userId,
projectId,
...userProjectQuery,
},
order: {
id: "DESC",
@@ -210,27 +210,25 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
}
async count({ userId, projectId }: { userId: number; projectId?: number }) {
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
const total = await this.repository.count({
where: {
userId,
...userProjectQuery,
expiresTime: Not(IsNull()),
projectId,
},
});
const expired = await this.repository.count({
where: {
userId,
...userProjectQuery,
expiresTime: LessThan(new Date().getTime()),
projectId,
},
});
const expiring = await this.repository.count({
where: {
userId,
...userProjectQuery,
expiresTime: Between(new Date().getTime(), new Date().getTime() + 15 * 24 * 60 * 60 * 1000),
projectId,
},
});
@@ -531,7 +531,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
}
const query: any = { disabled: false };
query.userId = userId;
if (projectId) {
if (projectId != null) {
query.projectId = projectId;
}
const siteCount = await this.repository.count({
@@ -584,10 +584,10 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
}
async batchDelete(ids: number[], userId: number, projectId?: number): Promise<void> {
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
await this.repository.delete({
id: In(ids),
userId,
projectId,
...userProjectQuery,
});
}
}
@@ -285,11 +285,11 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
throw new Error("siteId is required");
}
const userProjectQuery = this.buildUserProjectQuery(req.userId, req.projectId);
const siteEntity = await this.siteInfoRepository.findOne({
where: {
id: req.siteId,
userId: req.userId,
projectId: req.projectId,
...userProjectQuery,
},
});
if (!siteEntity) {