generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.ts
62 lines (54 loc) · 1.61 KB
/
index.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
import { BaseAsset } from '~/api/entities/Asset/Base/BaseAsset';
import { Context, Namespace, setAssetDocuments } from '~/internal';
import {
AssetDocument,
PaginationOptions,
ProcedureMethod,
ResultSet,
SetAssetDocumentsParams,
} from '~/types';
import { documentToAssetDocument, stringToTicker } from '~/utils/conversion';
import { createProcedureMethod, requestPaginated } from '~/utils/internal';
/**
* Handles all Asset Document related functionality
*/
export class Documents extends Namespace<BaseAsset> {
/**
* @hidden
*/
constructor(parent: BaseAsset, context: Context) {
super(parent, context);
const { ticker } = parent;
this.set = createProcedureMethod(
{ getProcedureAndArgs: args => [setAssetDocuments, { ticker, ...args }] },
context
);
}
/**
* Assign a new list of documents to the Asset by replacing the existing list of documents with the ones passed in the parameters
*/
public set: ProcedureMethod<SetAssetDocumentsParams, void>;
/**
* Retrieve all documents linked to the Asset
*
* @note supports pagination
*/
public async get(paginationOpts?: PaginationOptions): Promise<ResultSet<AssetDocument>> {
const {
context: {
polymeshApi: { query },
},
context,
parent: { ticker },
} = this;
const { entries, lastKey: next } = await requestPaginated(query.asset.assetDocuments, {
arg: stringToTicker(ticker, context),
paginationOpts,
});
const data: AssetDocument[] = entries.map(([, doc]) => documentToAssetDocument(doc.unwrap()));
return {
data,
next,
};
}
}