Skip to content

Commit

Permalink
tip queries and mutations (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flip-Liquid authored Jul 12, 2023
1 parent ddc69c0 commit 9a904db
Show file tree
Hide file tree
Showing 161 changed files with 5,338 additions and 68 deletions.
12 changes: 1 addition & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,9 @@
"request": "launch",
"python": "${workspaceFolder}/apps/jobs/twitter-contribution/.venv/bin/python3.9",
"cwd": "${workspaceFolder}/apps/jobs/twitter-contribution/",
"program": "${workspaceFolder}/apps/jobs/twitter-contribution/bot/common/tasks/weekly_contributions.py",
"program": "${workspaceFolder}/apps/jobs/twitter-contribution/twitter_contribution/__main__.py",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/apps/jobs/twitter-contribution/.env"
},
{
"name": "Python: run twitter job tests",
"type": "python",
"request": "launch",
"python": "${workspaceFolder}/apps/kevin-malone/.venv/bin/python3",
"cwd": "${workspaceFolder}/apps/kevin-malone/",
"program": "${workspaceFolder}/apps/kevin-malone/bot/common/tasks/weekly_contributions.py",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/apps/kevin-malone/.env"
}
]
}
30 changes: 30 additions & 0 deletions apps/protocol-api/src/permissions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
updateGuildUserCustomInput,
updateGuildUserRecruitCustomInput,
getOrCreateActivityTypeInput,
createUserSplitContractInput,
updateUserSplitContractInput,
createSplitPaymentInput,
} from './inputs';

const AIRTABLE_API_TOKEN = process.env.AIRTABlE_API_TOKEN;
Expand Down Expand Up @@ -260,6 +263,8 @@ export const permissions = shield(
attestations: isAuthenticated,
listActivityTypesByUser: isAuthenticated,
getUser: or(isAuthenticated, hasToken),
getTotalUserSplitPaymentsSent: or(isAuthenticated, hasToken),
getTotalUserSplitPaymentsReceived: or(isAuthenticated, hasToken),
guild: or(isAuthenticated, hasToken),
guilds: or(isAuthenticated, hasToken),
guildUsers: or(isAuthenticated, hasToken),
Expand Down Expand Up @@ -365,6 +370,19 @@ export const permissions = shield(
updateUserOnChainAttestationInput,
isUsersAttestation,
), // user can only make their own attestations

// TODO: bring up split validations
createUserSplitContract: and(
isAuthenticated,
createUserSplitContractInput,
isUsers,
), // user can make their own split contract
updateUserSplitContract: and(
isAuthenticated,
updateUserSplitContractInput,
isUsers,
), // user can only update their own split contract
createSplitContractPayment: and(isAuthenticated, createSplitPaymentInput), // any user or non-user can make a payment to a split contract
updateUserOnChainContribution: and(
isAuthenticated,
updateUserOnChainContributionInput,
Expand Down Expand Up @@ -527,6 +545,18 @@ export const permissions = shield(
VerificationSetting: {
'*': or(isAuthenticated, hasToken),
},
SplitContract: {
'*': or(isAuthenticated, hasToken),
},
UserSplitContract: {
'*': or(isAuthenticated, hasToken),
},
UserSplitPayment: {
'*': or(isAuthenticated, hasToken),
},
SplitPayment: {
'*': or(isAuthenticated, hasToken),
},
},
{
fallbackRule: deny,
Expand Down
43 changes: 43 additions & 0 deletions apps/protocol-api/src/permissions/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,46 @@ export const updateOneVerificationSettingInput = inputRule()(
}),
{ abortEarly: false },
);

export const createUserSplitContractInput = inputRule()(
yup =>
yup.object({
data: yup.object({
user_id: yup.number().required(),
split_contract_address: yup.string().required(),
chain_db_id: yup.number().required(),
tx_hash: yup.string().required(),
}),
}),
{ abortEarly: false },
);

export const updateUserSplitContractInput = inputRule()(
yup =>
yup.object({
where: yup.object({
user_id: yup.number().required(),
user_split_contract_id: yup.number().required(),
}),
data: yup.object({
enabled: yup.boolean().required(),
}),
}),
{ abortEarly: false },
);

export const createSplitPaymentInput = inputRule()(
yup =>
yup.object({
data: yup.object({
recipient_user_id: yup.number().required(),
recipient_split_contract_id: yup.number().required(),
token_address: yup.string().required(),
amount: yup.number().required(),
tx_hash: yup.string().required(),
sender_address: yup.string().required(),
sender_user_id: yup.number(),
}),
}),
{ abortEarly: false },
);
170 changes: 135 additions & 35 deletions apps/protocol-api/src/prisma/generated/type-graphql/enhance.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as TypeGraphQL from "type-graphql";

export enum ContributionPaymentScalarFieldEnum {
id = "id",
createdAt = "createdAt",
updatedAt = "updatedAt",
contribution_id = "contribution_id",
split_payment_id = "split_payment_id",
type = "type"
}
TypeGraphQL.registerEnumType(ContributionPaymentScalarFieldEnum, {
name: "ContributionPaymentScalarFieldEnum",
description: undefined,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as TypeGraphQL from "type-graphql";

export enum ContributionPaymentType {
TIP = "TIP",
REPORT = "REPORT"
}
TypeGraphQL.registerEnumType(ContributionPaymentType, {
name: "ContributionPaymentType",
description: undefined,
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export { CategoryActivityScalarFieldEnum } from "./CategoryActivityScalarFieldEn
export { CategoryActivityTypeScalarFieldEnum } from "./CategoryActivityTypeScalarFieldEnum";
export { ChainScalarFieldEnum } from "./ChainScalarFieldEnum";
export { ChainTypeScalarFieldEnum } from "./ChainTypeScalarFieldEnum";
export { ContributionPaymentScalarFieldEnum } from "./ContributionPaymentScalarFieldEnum";
export { ContributionPaymentType } from "./ContributionPaymentType";
export { ContributionScalarFieldEnum } from "./ContributionScalarFieldEnum";
export { ContributionStatusScalarFieldEnum } from "./ContributionStatusScalarFieldEnum";
export { DiscordUserScalarFieldEnum } from "./DiscordUserScalarFieldEnum";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DecimalJSScalar } from "../scalars";
import { ActivityType } from "../models/ActivityType";
import { Attestation } from "../models/Attestation";
import { Chain } from "../models/Chain";
import { ContributionPayment } from "../models/ContributionPayment";
import { ContributionStatus } from "../models/ContributionStatus";
import { GuildContribution } from "../models/GuildContribution";
import { LinearIssue } from "../models/LinearIssue";
Expand Down Expand Up @@ -100,6 +101,8 @@ export class Contribution {
})
tx_hash?: string | null;

contribution_tip?: ContributionPayment[];

@TypeGraphQL.Field(_type => ContributionCount, {
nullable: true
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as TypeGraphQL from "type-graphql";
import * as GraphQLScalars from "graphql-scalars";
import { Prisma } from "@prisma/client";
import { DecimalJSScalar } from "../scalars";
import { Contribution } from "../models/Contribution";
import { SplitPayment } from "../models/SplitPayment";
import { ContributionPaymentType } from "../enums/ContributionPaymentType";

@TypeGraphQL.ObjectType("ContributionPayment", {
isAbstract: true
})
export class ContributionPayment {
@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: false
})
id!: number;

@TypeGraphQL.Field(_type => Date, {
nullable: false
})
createdAt!: Date;

@TypeGraphQL.Field(_type => Date, {
nullable: false
})
updatedAt!: Date;

@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: false
})
contribution_id!: number;

contribution?: Contribution;

@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: false
})
split_payment_id!: number;

split_payment?: SplitPayment;

@TypeGraphQL.Field(_type => ContributionPaymentType, {
nullable: false
})
type!: "TIP" | "REPORT";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import * as TypeGraphQL from "type-graphql";
import * as GraphQLScalars from "graphql-scalars";
import { Prisma } from "@prisma/client";
import { DecimalJSScalar } from "../scalars";
import { ContributionPayment } from "../models/ContributionPayment";
import { SplitContract } from "../models/SplitContract";
import { User } from "../models/User";
import { SplitPaymentCount } from "../resolvers/outputs/SplitPaymentCount";

@TypeGraphQL.ObjectType("SplitPayment", {
isAbstract: true
Expand Down Expand Up @@ -62,4 +64,11 @@ export class SplitPayment {
split_contract_id!: number;

split_contract?: SplitContract;

contribution_payments?: ContributionPayment[];

@TypeGraphQL.Field(_type => SplitPaymentCount, {
nullable: true
})
_count?: SplitPaymentCount | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { CategoryActivityType } from "./CategoryActivityType";
export { Chain } from "./Chain";
export { ChainType } from "./ChainType";
export { Contribution } from "./Contribution";
export { ContributionPayment } from "./ContributionPayment";
export { ContributionStatus } from "./ContributionStatus";
export { DiscordUser } from "./DiscordUser";
export { Guild } from "./Guild";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as TypeGraphQL from "type-graphql";
import { GraphQLResolveInfo } from "graphql";
import { AggregateContributionPaymentArgs } from "./args/AggregateContributionPaymentArgs";
import { ContributionPayment } from "../../../models/ContributionPayment";
import { AggregateContributionPayment } from "../../outputs/AggregateContributionPayment";
import { transformInfoIntoPrismaArgs, getPrismaFromContext, transformCountFieldIntoSelectRelationsCount } from "../../../helpers";

@TypeGraphQL.Resolver(_of => ContributionPayment)
export class AggregateContributionPaymentResolver {
@TypeGraphQL.Query(_returns => AggregateContributionPayment, {
nullable: false
})
async aggregateContributionPayment(@TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo, @TypeGraphQL.Args() args: AggregateContributionPaymentArgs): Promise<AggregateContributionPayment> {
return getPrismaFromContext(ctx).contributionPayment.aggregate({
...args,
...transformInfoIntoPrismaArgs(info),
});
}
}
Loading

0 comments on commit 9a904db

Please sign in to comment.