Files
cnpmcore/app/core/service/ScopeManagerService.ts
MK (fengmk2) e5162f20aa fix: improve TypeScript type definitions across codebase (#844)
This commit enhances type safety and fixes type-related issues
throughout the project including:
- Updated type definitions in entities, repositories, and models
- Improved type annotations in services and controllers
- Fixed type issues in adapters and utilities
- Enhanced test file type definitions
- Added typings/index.d.ts for global type declarations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-23 00:58:59 +08:00

89 lines
2.5 KiB
TypeScript

import { AccessLevel, Inject, SingletonProto } from '@eggjs/tegg';
import type { ScopeRepository } from '../../repository/ScopeRepository.ts';
import { AbstractService } from '../../common/AbstractService.ts';
import { Scope } from '../entity/Scope.ts';
import type { PageOptions, PageResult } from '../util/EntityUtil.ts';
export interface CreateScopeCmd extends Pick<Scope, 'name' | 'registryId'> {
operatorId?: string;
}
export interface UpdateRegistryCmd
extends Pick<Scope, 'name' | 'scopeId' | 'registryId'> {
operatorId?: string;
}
export interface RemoveScopeCmd {
scopeId: string;
operatorId?: string;
}
export interface RemoveScopeByRegistryIdCmd {
registryId: string;
operatorId?: string;
}
@SingletonProto({
accessLevel: AccessLevel.PUBLIC,
})
export class ScopeManagerService extends AbstractService {
@Inject()
private readonly scopeRepository: ScopeRepository;
async findByName(name: string): Promise<Scope | null> {
const scope = await this.scopeRepository.findByName(name);
return scope;
}
async countByRegistryId(registryId: string): Promise<number> {
const count = await this.scopeRepository.countByRegistryId(registryId);
return count;
}
async createScope(createCmd: CreateScopeCmd): Promise<Scope> {
const { name, registryId, operatorId } = createCmd;
this.logger.info(
'[ScopeManagerService.CreateScope:prepare] operatorId: %s, createCmd: %s',
operatorId,
createCmd
);
const scope = Scope.create({
name,
registryId,
});
await this.scopeRepository.saveScope(scope);
return scope;
}
async listScopes(page: PageOptions): Promise<PageResult<Scope>> {
return await this.scopeRepository.listScopes(page);
}
async listScopesByRegistryId(
registryId: string,
page: PageOptions
): Promise<PageResult<Scope>> {
return await this.scopeRepository.listScopesByRegistryId(registryId, page);
}
async removeByRegistryId(
removeCmd: RemoveScopeByRegistryIdCmd
): Promise<void> {
const { registryId, operatorId } = removeCmd;
this.logger.info(
'[ScopeManagerService.remove:prepare] operatorId: %s, registryId: %s',
operatorId,
registryId
);
return await this.scopeRepository.removeScopeByRegistryId(registryId);
}
async remove(removeCmd: RemoveScopeCmd): Promise<void> {
const { scopeId, operatorId } = removeCmd;
this.logger.info(
'[ScopeManagerService.remove:prepare] operatorId: %s, scopeId: %s',
operatorId,
scopeId
);
return await this.scopeRepository.removeScope(scopeId);
}
}