/
auditLogRecordProvider.ts
80 lines (67 loc) Β· 3.85 KB
/
auditLogRecordProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Copyright (c) Microsoft.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
import { IEntityMetadata, EntityMetadataBase, IEntityMetadataBaseOptions } from '../../lib/entityMetadataProvider/entityMetadata';
import { AuditLogRecord, AuditLogRecordQueryUndoCandidatesByThirdPartyId, AuditLogRecordQueryRecordsByActorThirdPartyId, AuditLogRecordQueryRecordsByUserThirdPartyId, AuditLogRecordQueryRecordsByRepositoryId, AuditLogRecordQueryRecordsByTeamId } from './auditLogRecord';
import { EntityImplementation } from './auditLogRecord';
const thisProviderType = EntityImplementation.Type;
export interface IAuditLogRecordProviderCreateOptions extends IEntityMetadataBaseOptions {
}
export interface IAuditLogRecordProvider {
initialize(): Promise<void>;
getRecord(recordId: string): Promise<AuditLogRecord>;
insertRecord(record: AuditLogRecord): Promise<string>;
queryAuditLogForActorThirdPartyId(id: string): Promise<AuditLogRecord[]>;
queryAuditLogForUserThirdPartyId(id: string): Promise<AuditLogRecord[]>;
queryAuditLogForThirdPartyIdUndoOperations(id: string): Promise<AuditLogRecord[]>;
queryAuditLogForRepositoryOperations(repositoryId: string): Promise<AuditLogRecord[]>;
queryAuditLogForTeamOperations(teamId: string): Promise<AuditLogRecord[]>;
}
export class AuditLogRecordProvider extends EntityMetadataBase implements IAuditLogRecordProvider {
constructor(options: IAuditLogRecordProviderCreateOptions) {
super(options);
EntityImplementation.EnsureDefinitions();
}
async getRecord(recordId: string): Promise<AuditLogRecord> {
this.ensureHelpers(thisProviderType);
let metadata: IEntityMetadata = null;
metadata = await this._entities.getMetadata(thisProviderType, recordId);
return this.deserialize<AuditLogRecord>(thisProviderType, metadata);
}
async insertRecord(record: AuditLogRecord): Promise<string> {
const entity = this.serialize(thisProviderType, record);
await this._entities.setMetadata(entity);
return entity.entityId;
}
async queryAuditLogForRepositoryOperations(repositoryId: string): Promise<AuditLogRecord[]> {
const query = new AuditLogRecordQueryRecordsByRepositoryId(repositoryId);
const metadatas = await this._entities.fixedQueryMetadata(thisProviderType, query);
const results = this.deserializeArray<AuditLogRecord>(thisProviderType, metadatas);
return results;
}
async queryAuditLogForTeamOperations(teamId: string): Promise<AuditLogRecord[]> {
const query = new AuditLogRecordQueryRecordsByTeamId(teamId);
const metadatas = await this._entities.fixedQueryMetadata(thisProviderType, query);
const results = this.deserializeArray<AuditLogRecord>(thisProviderType, metadatas);
return results;
}
async queryAuditLogForActorThirdPartyId(thirdPartyId: string): Promise<AuditLogRecord[]> {
const query = new AuditLogRecordQueryRecordsByActorThirdPartyId(thirdPartyId);
const metadatas = await this._entities.fixedQueryMetadata(thisProviderType, query);
const results = this.deserializeArray<AuditLogRecord>(thisProviderType, metadatas);
return results;
}
async queryAuditLogForUserThirdPartyId(thirdPartyId: string): Promise<AuditLogRecord[]> {
const query = new AuditLogRecordQueryRecordsByUserThirdPartyId(thirdPartyId);
const metadatas = await this._entities.fixedQueryMetadata(thisProviderType, query);
const results = this.deserializeArray<AuditLogRecord>(thisProviderType, metadatas);
return results;
}
async queryAuditLogForThirdPartyIdUndoOperations(thirdPartyId: string): Promise<AuditLogRecord[]> {
const query = new AuditLogRecordQueryUndoCandidatesByThirdPartyId(thirdPartyId);
const metadatas = await this._entities.fixedQueryMetadata(thisProviderType, query);
const results = this.deserializeArray<AuditLogRecord>(thisProviderType, metadatas);
return results;
}
}