Skip to content

Commit 661b132

Browse files
feat: 🎸 Return newly created nft collection when creating one
1 parent 375297a commit 661b132

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* istanbul ignore file */
2+
import { ApiPropertyOptional } from '@nestjs/swagger';
3+
import { NftCollection } from '@polymeshassociation/polymesh-sdk/types';
4+
5+
import { FromEntity } from '~/common/decorators/transformation';
6+
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
7+
8+
export class CreatedNftCollectionModel extends TransactionQueueModel {
9+
@ApiPropertyOptional({
10+
description: 'The newly created NFT collection ID',
11+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
12+
})
13+
@FromEntity()
14+
readonly collection: NftCollection;
15+
16+
constructor(model: CreatedNftCollectionModel) {
17+
const { transactions, details, ...rest } = model;
18+
super({ transactions, details });
19+
20+
Object.assign(this, rest);
21+
}
22+
}

‎src/nfts/nfts.controller.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
22
import { ApiGoneResponse, ApiOkResponse, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
3+
import { NftCollection } from '@polymeshassociation/polymesh-sdk/types';
34

45
import { AssetParamsDto } from '~/assets/dto/asset-params.dto';
6+
import { CreatedNftCollectionModel } from '~/assets/models/created-nft-collection.model';
57
import { ApiArrayResponse, ApiTransactionResponse } from '~/common/decorators/';
68
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
7-
import { handleServiceResult, TransactionResponseModel } from '~/common/utils';
9+
import { handleServiceResult, TransactionResolver, TransactionResponseModel } from '~/common/utils';
810
import { CreateNftCollectionDto } from '~/nfts/dto/create-nft-collection.dto';
911
import { IssueNftDto } from '~/nfts/dto/issue-nft.dto';
1012
import { NftParamsDto } from '~/nfts/dto/nft-params.dto';
@@ -70,7 +72,7 @@ export class NftsController {
7072
description: 'This endpoint allows for the creation of NFT collections',
7173
})
7274
@ApiTransactionResponse({
73-
description: 'Details about the transaction',
75+
description: 'Details about the transaction along with newly created nft collection',
7476
type: TransactionQueueModel,
7577
})
7678
@ApiGoneResponse({
@@ -82,7 +84,18 @@ export class NftsController {
8284
): Promise<TransactionResponseModel> {
8385
const result = await this.nftService.createNftCollection(params);
8486

85-
return handleServiceResult(result);
87+
const resolver: TransactionResolver<NftCollection> = ({
88+
result: collection,
89+
transactions,
90+
details,
91+
}) =>
92+
new CreatedNftCollectionModel({
93+
collection,
94+
transactions,
95+
details,
96+
});
97+
98+
return handleServiceResult(result, resolver);
8699
}
87100

88101
@ApiOperation({

0 commit comments

Comments
 (0)