|
1 | 1 | import { Injectable, NotFoundException } from '@nestjs/common'; |
2 | 2 | import { InjectRepository } from '@nestjs/typeorm'; |
3 | | -import { Repository } from 'typeorm'; |
| 3 | +import { Repository, In } from 'typeorm'; |
4 | 4 | import { Identity } from './identity.entity'; |
5 | 5 | import { CreateIdentityDto } from './dto/create-identity.dto'; |
6 | 6 | import { UpdateIdentityDto } from './dto/update-identity.dto'; |
@@ -61,12 +61,47 @@ export class IdentityService { |
61 | 61 | return await this.identityRepository.save(identity); |
62 | 62 | } |
63 | 63 |
|
64 | | - async revoke(id: string): Promise<Identity> { |
| 64 | + async revoke(id: string, reason?: string): Promise<Identity> { |
65 | 65 | const identity = await this.findOne(id); |
66 | 66 | identity.revoked = true; |
| 67 | + if (reason) identity.revocationReason = reason; |
67 | 68 | return await this.identityRepository.save(identity); |
68 | 69 | } |
69 | 70 |
|
| 71 | + async bulkRevoke(ids: string[], reason?: string): Promise<Identity[]> { |
| 72 | + const identities = await this.identityRepository.find({ |
| 73 | + where: { id: In(ids) }, |
| 74 | + }); |
| 75 | + for (const identity of identities) { |
| 76 | + identity.revoked = true; |
| 77 | + if (reason) identity.revocationReason = reason; |
| 78 | + } |
| 79 | + return await this.identityRepository.save(identities); |
| 80 | + } |
| 81 | + |
| 82 | + async getRevocationList(pagination?: PaginateIdentityDto): Promise<PaginatedResult<Identity>> { |
| 83 | + const page = pagination?.page ?? 1; |
| 84 | + const limit = pagination?.limit ?? 20; |
| 85 | + const skip = (page - 1) * limit; |
| 86 | + |
| 87 | + const [data, total] = await this.identityRepository.findAndCount({ |
| 88 | + where: { revoked: true }, |
| 89 | + order: { updatedAt: 'DESC' }, |
| 90 | + skip, |
| 91 | + take: limit, |
| 92 | + }); |
| 93 | + |
| 94 | + return { data, total, page, lastPage: Math.ceil(total / limit) }; |
| 95 | + } |
| 96 | + |
| 97 | + async getRevocationStatus(id: string): Promise<{ revoked: boolean; reason: string | null }> { |
| 98 | + const identity = await this.findOne(id); |
| 99 | + return { |
| 100 | + revoked: identity.revoked, |
| 101 | + reason: identity.revocationReason || null, |
| 102 | + }; |
| 103 | + } |
| 104 | + |
70 | 105 | async remove(id: string): Promise<void> { |
71 | 106 | const identity = await this.findOne(id); |
72 | 107 | await this.identityRepository.remove(identity); |
|
0 commit comments