Skip to content

Commit

Permalink
Merge pull request #2166 from hashgraph/feature/2075
Browse files Browse the repository at this point in the history
Feature/2075
  • Loading branch information
Stepan-Kirjakov authored May 23, 2023
2 parents 62b6f90 + 66d8fca commit 1880fe6
Show file tree
Hide file tree
Showing 49 changed files with 2,311 additions and 280 deletions.
Binary file not shown.
Binary file not shown.
67 changes: 66 additions & 1 deletion common/src/database-modules/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
PolicyModule,
Tag,
TagCache,
Contract as ContractCollection
Contract as ContractCollection,
ExternalDocument
} from '../entity';
import { Binary } from 'bson';
import {
Expand Down Expand Up @@ -77,6 +78,7 @@ export class DatabaseServer {
this.classMap.set(SplitDocuments, 'SplitDocuments');
this.classMap.set(Tag, 'Tag');
this.classMap.set(TagCache, 'TagCache');
this.classMap.set(ExternalDocument, 'ExternalDocument');
}

/**
Expand Down Expand Up @@ -1361,6 +1363,69 @@ export class DatabaseServer {
});
}

/**
* Get External Topic
* @param policyId
* @param blockId
* @param userId
*
* @virtual
*/
public async getExternalTopic(
policyId: string,
blockId: string,
userId: string
): Promise<ExternalDocument> {
return await this.findOne(ExternalDocument, {
where: {
policyId: { $eq: policyId },
blockId: { $eq: blockId },
owner: { $eq: userId }
}
});
}

/**
* Create External Topic
* @param row
*
* @virtual
*/
public async createExternalTopic(row: any): Promise<ExternalDocument> {
const item = this.create(ExternalDocument, row);
return await this.save(ExternalDocument, item);
}

/**
* Update External Topic
* @param row
*
* @virtual
*/
public async updateExternalTopic(item: ExternalDocument): Promise<ExternalDocument> {
return await this.save(ExternalDocument, item);
}

/**
* Get Active External Topic
* @param policyId
* @param blockId
*
* @virtual
*/
public async getActiveExternalTopics(
policyId: string,
blockId: string
): Promise<ExternalDocument[]> {
return await this.find(ExternalDocument, {
where: {
policyId: { $eq: policyId },
blockId: { $eq: blockId },
active: { $eq: true }
}
});
}

/**
* Create tag
* @param tag
Expand Down
62 changes: 58 additions & 4 deletions common/src/entity/dry-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export class DryRun extends BaseEntity {
/**
* IRI
*/
@Property({ nullable: true, type: 'unknown'})
@Property({ nullable: true, type: 'unknown' })
iri?: any;

/**
Expand Down Expand Up @@ -551,6 +551,60 @@ export class DryRun extends BaseEntity {
@Property({ nullable: true })
sourceDocumentId?: ObjectId;

/**
* Document Topic Id
*/
@Property({ nullable: true, type: 'unknown' })
documentTopicId?: any;

/**
* Policy Topic Id
*/
@Property({ nullable: true, type: 'unknown' })
policyTopicId?: any;

/**
* Document Message
*/
@Property({ nullable: true, type: 'unknown' })
documentMessage?: any;

/**
* Policy Message
*/
@Property({ nullable: true, type: 'unknown' })
policyMessage?: any;

/**
* Policy Instance Message
*/
@Property({ nullable: true, type: 'unknown' })
policyInstanceMessage?: any;

/**
* Schemas
*/
@Property({ nullable: true, type: 'unknown' })
schemas?: any;

/**
* Schema Id
*/
@Property({ nullable: true, type: 'unknown' })
schemaId?: any;

/**
* Last Message
*/
@Property({ nullable: true, type: 'unknown' })
lastMessage?: any;

/**
* Last Update
*/
@Property({ nullable: true, type: 'unknown' })
lastUpdate?: any;

/**
* Default document values
*/
Expand Down Expand Up @@ -590,9 +644,9 @@ export class DryRun extends BaseEntity {
if (
(typeof fieldValue === 'string' &&
fieldValue.length <
(+process.env
.DOCUMENT_CACHE_FIELD_LIMIT ||
100)) ||
(+process.env
.DOCUMENT_CACHE_FIELD_LIMIT ||
100)) ||
typeof fieldValue === 'number'
) {
ObjSet(newDocument, field, fieldValue);
Expand Down
117 changes: 117 additions & 0 deletions common/src/entity/external-document.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { BeforeCreate, Entity, Property } from '@mikro-orm/core';
import { BaseEntity } from '../models';

/**
* Artifact collection
*/
@Entity()
export class ExternalDocument extends BaseEntity {
/**
* Block UUID
*/
@Property({ nullable: true })
blockId?: string;

/**
* Policy id
*/
@Property({
nullable: true,
index: true,
})
policyId?: string;

/**
* User
*/
@Property({ nullable: true })
owner?: string;

/**
* Document Topic Id
*/
@Property({ nullable: true })
documentTopicId?: string;

/**
* Policy Topic Id
*/
@Property({ nullable: true })
policyTopicId?: string;

/**
* Instance Topic Id
*/
@Property({ nullable: true })
instanceTopicId?: string;

/**
* Document Message
*/
@Property({ nullable: true, type: 'unknown' })
documentMessage?: any;

/**
* Policy Message
*/
@Property({ nullable: true, type: 'unknown' })
policyMessage?: any;

/**
* Policy Instance Message
*/
@Property({ nullable: true, type: 'unknown' })
policyInstanceMessage?: any;

/**
* Schemas
*/
@Property({ nullable: true, type: 'unknown' })
schemas?: any[];

/**
* Schema
*/
@Property({ nullable: true, type: 'unknown' })
schema?: any;

/**
* Schema Id
*/
@Property({ nullable: true })
schemaId?: string;

/**
* Status
*/
@Property({ nullable: true })
active?: boolean;

/**
* Last Message
*/
@Property({ nullable: true })
lastMessage?: string;

/**
* Last Update
*/
@Property({ nullable: true })
lastUpdate?: string;

/**
* Status
*/
@Property({ nullable: true })
status?: string;

/**
* Default document values
*/
@BeforeCreate()
setDefaults() {
this.lastMessage = this.lastMessage || '';
this.lastUpdate = this.lastUpdate || '';
this.active = this.active || false;
}
}
3 changes: 2 additions & 1 deletion common/src/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export * from './token';
export * from './topic';
export * from './vc-document';
export * from './vp-document';
export * from './theme';
export * from './theme';
export * from './external-document';
7 changes: 1 addition & 6 deletions common/src/entity/vc-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Property,
Enum,
BeforeCreate,
Unique,
OnLoad,
BeforeUpdate,
AfterDelete,
Expand All @@ -27,10 +26,6 @@ import ObjSet from 'lodash.set';
* VC documents collection
*/
@Entity()
@Unique({
properties: ['hash'],
options: { partialFilterExpression: { hash: { $type: 'string' } } },
})
export class VcDocument extends BaseEntity implements IVCDocument {
/**
* Document owner
Expand Down Expand Up @@ -64,7 +59,7 @@ export class VcDocument extends BaseEntity implements IVCDocument {
*/
@Property({
nullable: true,
// index: true
index: true
})
hash?: string;

Expand Down
Loading

0 comments on commit 1880fe6

Please sign in to comment.