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:
parent
29df9955f9
commit
d565bb91fa
|
|
@ -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>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in New Issue