Insert to database
This commit is contained in:
parent
3aea58a015
commit
707b9c68a0
1 changed files with 22 additions and 7 deletions
|
@ -13,21 +13,36 @@ export class AssetAudit implements EntitySubscriberInterface<AssetEntity> {
|
|||
this.assetEntity = entity;
|
||||
}
|
||||
|
||||
afterInsert(event: InsertEvent<AssetEntity>): void | Promise<any> {
|
||||
console.log('AFTER ENTITY INSERTED: ', event.entity);
|
||||
async afterInsert(event: InsertEvent<AssetEntity>): Promise<any> {
|
||||
const auditRepository = event.manager.getRepository(AuditEntity);
|
||||
const auditEntity = this.getAssetAudit(DatabaseAction.CREATE);
|
||||
|
||||
await auditRepository.save(auditEntity);
|
||||
}
|
||||
|
||||
afterRemove(event: RemoveEvent<AssetEntity>): void | Promise<any> {
|
||||
console.log('AFTER ENTITY WITH ID ' + event.entityId + ' REMOVED: ', event.entity);
|
||||
async afterRemove(event: RemoveEvent<AssetEntity>): Promise<any> {
|
||||
const auditRepository = event.manager.getRepository(AuditEntity);
|
||||
const auditEntity = this.getAssetAudit(DatabaseAction.DELETE);
|
||||
|
||||
await auditRepository.save(auditEntity);
|
||||
}
|
||||
|
||||
async afterUpdate(event: UpdateEvent<AssetEntity>): Promise<any> {
|
||||
const audit = event.manager.getRepository(AuditEntity);
|
||||
const auditRepository = event.manager.getRepository(AuditEntity);
|
||||
const auditEntity = this.getAssetAudit(DatabaseAction.UPDATE);
|
||||
|
||||
await auditRepository.save(auditEntity);
|
||||
}
|
||||
|
||||
private getAssetAudit(action: DatabaseAction): AuditEntity {
|
||||
const auditEntity = new AuditEntity();
|
||||
|
||||
auditEntity.action = DatabaseAction.UPDATE;
|
||||
auditEntity.action = action;
|
||||
auditEntity.entityType = EntityType.ASSET;
|
||||
auditEntity.entityId = this.assetEntity.id;
|
||||
auditEntity.ownerId = this.assetEntity.ownerId;
|
||||
auditEntity.userId = this.assetEntity.ownerId;
|
||||
|
||||
console.log('AFTER ENTITY UPDATED: ', this.assetEntity.isFavorite);
|
||||
return auditEntity;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue