feat(authorization): 添加审计查询方法支持查询已删除记录

- findAllByUserIdIncludeDeleted: 按用户ID查询所有记录(含已删除)
- findAllByAccountSequenceIncludeDeleted: 按账号序列查询所有记录(含已删除)
- findByIdIncludeDeleted: 按ID查询记录(含已删除)

确保撤销的授权记录可审计追溯

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-17 07:53:37 -08:00
parent 29df9955f9
commit d565bb91fa
2 changed files with 45 additions and 0 deletions

View File

@ -96,4 +96,24 @@ export interface IAuthorizationRoleRepository {
*
*/
findCommunityByName(communityName: string): Promise<AuthorizationRole | null>
// ============ 审计查询方法 (包含已软删除的记录) ============
/**
* ID查询所有授权记录/
*
*/
findAllByUserIdIncludeDeleted(userId: UserId): Promise<AuthorizationRole[]>
/**
* /
*
*/
findAllByAccountSequenceIncludeDeleted(accountSequence: string): Promise<AuthorizationRole[]>
/**
* ID查询授权记录
*
*/
findByIdIncludeDeleted(authorizationId: AuthorizationId): Promise<AuthorizationRole | null>
}

View File

@ -422,6 +422,31 @@ export class AuthorizationRoleRepositoryImpl implements IAuthorizationRoleReposi
return record ? this.toDomain(record) : null
}
// ============ 审计查询方法 (包含已软删除的记录) ============
async findAllByUserIdIncludeDeleted(userId: UserId): Promise<AuthorizationRole[]> {
const records = await this.prisma.authorizationRole.findMany({
where: { userId: userId.value },
orderBy: { createdAt: 'desc' },
})
return records.map((record) => this.toDomain(record))
}
async findAllByAccountSequenceIncludeDeleted(accountSequence: string): Promise<AuthorizationRole[]> {
const records = await this.prisma.authorizationRole.findMany({
where: { accountSequence: accountSequence },
orderBy: { createdAt: 'desc' },
})
return records.map((record) => this.toDomain(record))
}
async findByIdIncludeDeleted(authorizationId: AuthorizationId): Promise<AuthorizationRole | null> {
const record = await this.prisma.authorizationRole.findUnique({
where: { id: authorizationId.value },
})
return record ? this.toDomain(record) : null
}
private toDomain(record: any): AuthorizationRole {
const props: AuthorizationRoleProps = {
authorizationId: AuthorizationId.create(record.id),