Skip to content

Commit

Permalink
feat: update to need it change for sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Oct 4, 2023
1 parent 14bc993 commit 1277f53
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ dist
development.env
/config/local.js
package-lock.json
yalc.lock
yarn.lock
.vscode
tsconfig.build.
Expand Down
45 changes: 39 additions & 6 deletions src/subscriptions/subscriptions.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { BadRequestException, ForbiddenException, Injectable, Logger } from '@nestjs/common'
import { DDO, DDOError, DID, NFT1155Api, NFT721Api, Service } from '@nevermined-io/sdk'
import {
DDO,
DDOError,
DID,
NFT1155Api,
NFT721Api,
NeverminedNFT1155Type,
NeverminedNFT721Type,
QueryResult,
Service,
} from '@nevermined-io/sdk'
import { NeverminedService } from '../shared/nevermined/nvm.service'
import * as jose from 'jose'
import { ConfigService } from '../shared/config/config.service'
Expand Down Expand Up @@ -238,7 +248,7 @@ export class SubscriptionsService {
ercType: number,
): Promise<string> {
// get subscription DDO
const subscriptionDdo = await this.getSubscriptionDdo(contractAddress)
const subscriptionDdo = await this.getSubscriptionDdo(contractAddress, ercType)
// get duration
const duration = await this.nvmService.getDuration(subscriptionDdo)

Expand Down Expand Up @@ -275,15 +285,38 @@ export class SubscriptionsService {
* Get the subscription DDO
*
* @param contractAddress - The NFT-721 contract address for the subscription
* @param ercType - Type of erc contract
*
* @throws {@link BadRequestException}
* @returns {@link Promise<DDO>} The DDO for the subscription
*/
private async getSubscriptionDdo(contractAddress: string): Promise<DDO> {
private async getSubscriptionDdo(contractAddress: string, ercType?: number): Promise<DDO> {
// retrieve the subscription DDO
const result = await this.nvmService.nevermined.search.bySubscriptionContractAddress(
contractAddress,
)
let result: QueryResult
switch (ercType) {
case 721: {
result = await this.nvmService.nevermined.search.bySubscriptionContractAddress(
contractAddress,
NeverminedNFT721Type.nft721Subscription,
)
break
}
case 1155: {
result = await this.nvmService.nevermined.search.bySubscriptionContractAddress(
contractAddress,
NeverminedNFT1155Type.nft1155Credit,
)
break
}
default: {
result = await this.nvmService.nevermined.search.bySubscriptionContractAddress(
contractAddress,
undefined,
)
break
}
}

const ddo = result.results.pop()
if (!ddo) {
throw new BadRequestException(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1398,10 +1398,10 @@
snarkjs "^0.4.26"
web3-utils "^1.7.4"

"@nevermined-io/sdk@^2.0.0-rc11":
version "2.0.0-rc11"
resolved "https://registry.yarnpkg.com/@nevermined-io/sdk/-/sdk-2.0.0-rc11.tgz#e9157e10ffd5d1cf96eb6611092ff8e113de7bde"
integrity sha512-dgdZwiH2WL4aaH73T/7QId0O03/0BuInOVuPDE7c3D1S8LSOuT9CbjkIC2ff08LW5/ooPW6rSvaJFU8k7e+K4A==
"@nevermined-io/sdk@^2.0.0-rc12":
version "2.0.0-rc12"
resolved "https://registry.yarnpkg.com/@nevermined-io/sdk/-/sdk-2.0.0-rc12.tgz#dcc054a601a84c930d427912086b3e50a934c12b"
integrity sha512-FbAkjp8tUmvASSmtgEjINK/GoO4k2aw+CEJh2S8GBqOe+CSqDTiOGMecqpFSguv8CC7f1Uayix2xFuj9u6y25g==
dependencies:
"@apollo/client" "^3.7.16"
assert "^2.0.0"
Expand Down

0 comments on commit 1277f53

Please sign in to comment.