mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
chore: project query
This commit is contained in:
@@ -30,7 +30,10 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
@Post('/page', { summary: Constants.per.authOnly })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
body.query.userId = userId;
|
||||
const domains = body.query?.domains;
|
||||
delete body.query.domains;
|
||||
|
||||
@@ -76,17 +79,20 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
body.query.userId = userId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
|
||||
@Post('/getOptionsByIds', { summary: Constants.per.authOnly })
|
||||
async getOptionsByIds(@Body(ALL) body: {ids:any[]}) {
|
||||
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const list = await this.service.list({
|
||||
query:{
|
||||
userId: this.getUserId(),
|
||||
projectId,
|
||||
userId,
|
||||
},
|
||||
buildQuery: (bq: SelectQueryBuilder<any>) => {
|
||||
bq.andWhere('id in (:...ids)', { ids: body.ids });
|
||||
@@ -107,33 +113,37 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
|
||||
@Post('/add', { summary: Constants.per.authOnly })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
bean.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
bean.projectId = projectId
|
||||
bean.userId = userId;
|
||||
return await super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { summary: Constants.per.authOnly })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.service.checkUserId(bean.id, this.getUserId());
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
delete bean.userId;
|
||||
return await super.update(bean);
|
||||
}
|
||||
@Post('/info', { summary: Constants.per.authOnly })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { summary: Constants.per.authOnly })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/all', { summary: Constants.per.authOnly })
|
||||
async all() {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const list: any = await this.service.find({
|
||||
where: {
|
||||
userId: this.getUserId(),
|
||||
projectId,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
return this.ok(list);
|
||||
@@ -143,7 +153,7 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
|
||||
@Post('/getCert', { summary: Constants.per.authOnly })
|
||||
async getCert(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.getService(),id,"read");
|
||||
const certInfoEntity = await this.service.info(id);
|
||||
const certInfo = JSON.parse(certInfoEntity.certInfo);
|
||||
return this.ok(certInfo);
|
||||
@@ -151,7 +161,8 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
|
||||
@Get('/download', { summary: Constants.per.authOnly })
|
||||
async download(@Query('id') id: number) {
|
||||
const certInfo = await this.service.info(id)
|
||||
await this.checkOwner(this.getService(),id,"read");
|
||||
const certInfo = await this.getService().info(id)
|
||||
if (certInfo == null) {
|
||||
throw new CommonException('file not found');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
@Post('/page', { summary: Constants.per.authOnly })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
body.query.userId = userId;
|
||||
const certDomains = body.query.certDomains;
|
||||
const domain = body.query.domain;
|
||||
const name = body.query.name;
|
||||
@@ -55,13 +57,17 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
body.query.userId = userId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { summary: Constants.per.authOnly })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
bean.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
bean.projectId = projectId
|
||||
bean.userId = userId;
|
||||
const res = await this.service.add(bean);
|
||||
const entity = await this.service.info(res.id);
|
||||
if (entity.disabled) {
|
||||
@@ -72,7 +78,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
|
||||
@Post('/update', { summary: Constants.per.authOnly })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.service.checkUserId(bean.id, this.getUserId());
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
delete bean.userId;
|
||||
await this.service.update(bean);
|
||||
const entity = await this.service.info(bean.id);
|
||||
@@ -83,27 +89,27 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
}
|
||||
@Post('/info', { summary: Constants.per.authOnly })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { summary: Constants.per.authOnly })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
|
||||
@Post('/batchDelete', { summary: Constants.per.authOnly })
|
||||
async batchDelete(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
await this.service.batchDelete(body.ids,userId);
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
await this.service.batchDelete(body.ids,userId,projectId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/check', { summary: Constants.per.authOnly })
|
||||
async check(@Body('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
await this.service.check(id, true, 0);
|
||||
await utils.sleep(1000);
|
||||
return this.ok();
|
||||
@@ -111,26 +117,27 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
|
||||
@Post('/checkAll', { summary: Constants.per.authOnly })
|
||||
async checkAll() {
|
||||
const userId = this.getUserId();
|
||||
await this.service.checkAllByUsers(userId);
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
await this.service.checkAllByUsers(userId,projectId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/import', { summary: Constants.per.authOnly })
|
||||
async doImport(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
await this.service.doImport({
|
||||
text:body.text,
|
||||
groupId:body.groupId,
|
||||
userId
|
||||
userId,
|
||||
projectId
|
||||
})
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
|
||||
@Post('/ipCheckChange', { summary: Constants.per.authOnly })
|
||||
async ipCheckChange(@Body(ALL) bean: any) {
|
||||
const userId = this.getUserId();
|
||||
await this.service.checkUserId(bean.id, userId)
|
||||
await this.checkOwner(this.service,bean.id,"read");
|
||||
await this.service.ipCheckChange({
|
||||
id: bean.id,
|
||||
ipCheck: bean.ipCheck
|
||||
@@ -140,8 +147,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
|
||||
@Post('/disabledChange', { summary: Constants.per.authOnly })
|
||||
async disabledChange(@Body(ALL) bean: any) {
|
||||
const userId = this.getUserId();
|
||||
await this.service.checkUserId(bean.id, userId)
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
await this.service.disabledChange({
|
||||
id: bean.id,
|
||||
disabled: bean.disabled
|
||||
@@ -151,14 +157,19 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
|
||||
@Post("/setting/get", { summary: Constants.per.authOnly })
|
||||
async get() {
|
||||
const userId = this.getUserId();
|
||||
const { userId } = await this.getProjectUserIdRead()
|
||||
const setting = await this.service.getSetting(userId)
|
||||
return this.ok(setting);
|
||||
}
|
||||
|
||||
@Post("/setting/save", { summary: Constants.per.authOnly })
|
||||
async save(@Body(ALL) bean: any) {
|
||||
const userId = this.getUserId();
|
||||
const { userId } = await this.getProjectUserIdWrite()
|
||||
if(userId === 0){
|
||||
if(!this.isAdmin()){
|
||||
throw new Error("仅管理员可以修改");
|
||||
}
|
||||
}
|
||||
const setting = new UserSiteMonitorSetting();
|
||||
merge(setting, bean);
|
||||
|
||||
|
||||
@@ -22,8 +22,10 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
|
||||
@Post('/page', { summary: Constants.per.authOnly })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
page: body.page,
|
||||
@@ -35,13 +37,17 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { summary: Constants.per.authOnly })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
bean.userId = this.getUserId();
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId
|
||||
bean.from = "manual"
|
||||
const res = await this.service.add(bean);
|
||||
const siteEntity = await this.siteInfoService.info(bean.siteId);
|
||||
@@ -54,7 +60,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
|
||||
@Post('/update', { summary: Constants.per.authOnly })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.service.checkUserId(bean.id, this.getUserId());
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
delete bean.userId;
|
||||
await this.service.update(bean);
|
||||
const siteEntity = await this.siteInfoService.info(bean.siteId);
|
||||
@@ -66,23 +72,24 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
}
|
||||
@Post('/info', { summary: Constants.per.authOnly })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { summary: Constants.per.authOnly })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
const entity = await this.service.info(id);
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
|
||||
const res = await super.delete(id);
|
||||
await this.service.updateIpCount(entity.siteId)
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/check', { summary: Constants.per.authOnly })
|
||||
async check(@Body('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
const entity = await this.service.info(id);
|
||||
const siteEntity = await this.siteInfoService.info(entity.siteId);
|
||||
const domain = siteEntity.domain;
|
||||
@@ -93,8 +100,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
|
||||
@Post('/checkAll', { summary: Constants.per.authOnly })
|
||||
async checkAll(@Body('siteId') siteId: number) {
|
||||
const userId = this.getUserId();
|
||||
await this.siteInfoService.checkUserId(siteId, userId);
|
||||
await this.getProjectUserIdRead()
|
||||
const siteEntity = await this.siteInfoService.info(siteId);
|
||||
await this.service.syncAndCheck(siteEntity);
|
||||
return this.ok();
|
||||
@@ -102,22 +108,20 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
|
||||
@Post('/sync', { summary: Constants.per.authOnly })
|
||||
async sync(@Body('siteId') siteId: number) {
|
||||
const userId = this.getUserId();
|
||||
await this.getProjectUserIdWrite()
|
||||
const entity = await this.siteInfoService.info(siteId)
|
||||
if(entity.userId != userId){
|
||||
throw new Error('无权限')
|
||||
}
|
||||
await this.service.sync(entity);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/import', { summary: Constants.per.authOnly })
|
||||
async doImport(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite()
|
||||
await this.service.doImport({
|
||||
text:body.text,
|
||||
userId,
|
||||
siteId:body.siteId
|
||||
siteId:body.siteId,
|
||||
projectId
|
||||
})
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user