Skip to content

Commit

Permalink
Refactor MrCrypto model fields (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSintimbrean authored Nov 18, 2023
1 parent 44654c5 commit 49037d0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ model MrCrypto {
attHeadwear String
attEyes String
attMoustache String
totalScore Float
ranking Int
rarityScore Float
rarityRanking Int
Transfers Transfer[]
E7LTokensLinked E7LToken[]
Expand Down
22 changes: 19 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
enum AscendDescentByEnum {
asc
desc
}

enum Background {
Blue
Brown
Expand Down Expand Up @@ -160,7 +165,7 @@ enum Headwear {

type Holder {
address: String!
mrCryptosOwned: [MrCrypto!]!
mrCryptosOwned(first: Int! = 100, order: MrCryptoOrderBy! = {by: tokenId, type: desc}, skip: Int! = 0): [MrCrypto!]!
numberOfMrCryptos: Int!
}

Expand Down Expand Up @@ -192,8 +197,8 @@ type MrCrypto {
imageURL: String!
metadata: String!
moustache: String!
ranking: Int!
score: Float!
rarityRanking: Int!
rarityScore: Float!
tokenId: Int!
type: String!
}
Expand All @@ -207,7 +212,18 @@ input MrCryptoFilter {
type: Type
}

input MrCryptoOrderBy {
by: MrCryptoOrderByEnum! = tokenId
type: AscendDescentByEnum! = desc
}

enum MrCryptoOrderByEnum {
rarityRanking
tokenId
}

type Mutation {
addE7lCollection(contractAddress: String!, deployedBlock: Int!, imageURL: String!, name: String!): E7L!
startIndexationManually: String!
}

Expand Down
4 changes: 2 additions & 2 deletions src/indexer/mrcrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ async function updateOrCreateMrCrypto(
attMoustache: metadata[tokenId].attributes.Moustache,
attType: metadata[tokenId].attributes.Type,
metadataURL: `https://apinft.racksmafia.com/api/${tokenId}.json`,
totalScore: metadata[tokenId].total_score,
ranking: metadata[tokenId].ranking,
rarityScore: metadata[tokenId].total_score,
rarityRanking: metadata[tokenId].ranking,
lastTransferBlock: block,
Owner: {
connectOrCreate: {
Expand Down
36 changes: 35 additions & 1 deletion src/schema/holder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
import { builder } from "@/builder";
import { prisma } from "@/db";

const AscendDescentEnum = builder.enumType("AscendDescentByEnum", {
values: ["asc", "desc"] as const,
});

const MrCryptoOrderByEnum = builder.enumType("MrCryptoOrderByEnum", {
values: ["rarityRanking", "tokenId"] as const,
});

builder.prismaObject("Holder", {
fields: (t) => ({
address: t.exposeString("address"),
mrCryptosOwned: t.relation("MrCryptosOwned", {
query: { orderBy: { tokenId: "asc" } },
args: {
first: t.arg.int({ required: true, defaultValue: 100 }),
skip: t.arg.int({ required: true, defaultValue: 0 }),
order: t.arg({
required: true,
defaultValue: { type: "desc", by: "tokenId" },
type: builder.inputType("MrCryptoOrderBy", {
fields: (t) => ({
type: t.field({
type: AscendDescentEnum,
required: true,
defaultValue: "desc",
}),
by: t.field({
type: MrCryptoOrderByEnum,
required: true,
defaultValue: "tokenId",
}),
}),
}),
}),
},
query: (args) => ({
orderBy: { [args.order.by]: args.order.type },
take: args.first,
skip: args.skip,
}),
}),
numberOfMrCryptos: t.field({
select: {
Expand Down
4 changes: 2 additions & 2 deletions src/schema/mr-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ builder.prismaObject("MrCrypto", {
eyes: t.exposeString("attEyes"),
headwear: t.exposeString("attHeadwear"),
moustache: t.exposeString("attMoustache"),
score: t.exposeFloat("totalScore"),
ranking: t.exposeInt("ranking"),
rarityRanking: t.exposeInt("rarityRanking"),
rarityScore: t.exposeFloat("rarityScore"),
type: t.exposeString("attType"),
}),
});
Expand Down

0 comments on commit 49037d0

Please sign in to comment.