Skip to content

Commit

Permalink
Load "Member" membership status id.
Browse files Browse the repository at this point in the history
Instead of passing the membership status id directly.
  • Loading branch information
amrro committed Mar 2, 2023
1 parent c7d31e3 commit e308e58
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/guild-import-job/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ const main = async () => {
const importId = importedGuild.id;

try {
const membershipStatus = await govrn.guildMembershipStatus.get({
where: { name: 'Member' },
});
const membershipStatusId = membershipStatus.id;

await Promise.all(
roles.map(async role => {
console.log(
Expand Down Expand Up @@ -123,9 +128,9 @@ const main = async () => {

await govrn.guild.user.createMany({
data: dbUsers.map(u => ({
membership_status_id: 2,
guild_id: guildId,
user_id: u.id,
membership_status_id: membershipStatusId,
})),
skipDuplicates: true,
});
Expand Down
1 change: 1 addition & 0 deletions apps/protocol-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const permissions = shield(
guilds: or(isAuthenticated, hasToken),
guildUsers: or(isAuthenticated, hasToken),
guildImports: or(isAuthenticated, hasToken),
guildMembershipStatus: hasToken,
listUserByAddress: isAuthenticated,
getContributionCountByDateForUserInRange: or(isAuthenticated, hasToken),
getDaoContributionCountByUser: or(isAuthenticated, hasToken),
Expand Down
9 changes: 9 additions & 0 deletions libs/protocol-client/src/lib/client/membership_status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseClient } from './base';
import { GuildMembershipStatusQueryVariables } from '@govrn/protocol-client';

export class GuildMembershipStatus extends BaseClient {
public async get(args: GuildMembershipStatusQueryVariables) {
const membershipStatus = await this.sdk.guildMembershipStatus(args);
return membershipStatus.result;
}
}
14 changes: 14 additions & 0 deletions libs/protocol-client/src/lib/graphql/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,20 @@ query listGuildImports(
}
}

# MembershipStatus
fragment MembershipStatusFragment on GuildMembershipStatus {
id
createdAt
updatedAt
name
}

query guildMembershipStatus($where: GuildMembershipStatusWhereUniqueInput!) {
result: guildMembershipStatus(where: $where) {
...MembershipStatusFragment
}
}

# Twitter
fragment TwitterTweetFragment on TwitterTweet {
id
Expand Down
3 changes: 3 additions & 0 deletions libs/protocol-client/src/lib/protocol-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Twitter } from './client/twitter';
import { User } from './client/user';
import { GraphQLClient } from 'graphql-request';
import { Chain } from './client/chain';
import { GuildMembershipStatus } from "./client/membership_status";

export { cursorPagination } from './client/pagination';

Expand All @@ -21,6 +22,7 @@ export class GovrnProtocol {
contribution: Contribution;
jobRun: JobRun;
guild: Guild;
guildMembershipStatus: GuildMembershipStatus;
linear: Linear;
twitter: Twitter;
user: User;
Expand All @@ -47,6 +49,7 @@ export class GovrnProtocol {
this.twitter = new Twitter(this.client);
this.jobRun = new JobRun(this.client);
this.guild = new Guild(this.client);
this.guildMembershipStatus = new GuildMembershipStatus(this.client);
this.custom = new Custom(this.client);
}
}
27 changes: 27 additions & 0 deletions libs/protocol-client/src/lib/protocol-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18320,6 +18320,15 @@ export type ListGuildImportsQueryVariables = Exact<{

export type ListGuildImportsQuery = { result: Array<{ id: number, createdAt: string | Date, updatedAt: string | Date, guild_id: number, integration_type_id: number, authentication_token: string, guild: { id: number, name?: string | null }, integration_type: { id: number, name: string }, import_status: { id: number, createdAt: string | Date, updatedAt: string | Date, name: string }, users: Array<{ user_id: number }> }> };

export type MembershipStatusFragmentFragment = { id: number, createdAt: string | Date, updatedAt: string | Date, name: string };

export type GuildMembershipStatusQueryVariables = Exact<{
where: GuildMembershipStatusWhereUniqueInput;
}>;


export type GuildMembershipStatusQuery = { result?: { id: number, createdAt: string | Date, updatedAt: string | Date, name: string } | null };

export type TwitterTweetFragmentFragment = { id: number, updatedAt: string | Date, createdAt: string | Date, text: string, twitter_tweet_id: number, twitter_user?: { id: number, name?: string | null, createdAt: string | Date, updatedAt: string | Date, username: string } | null, twitter_tweet_contributions: Array<{ id: number, updatedAt: string | Date, createdAt: string | Date, contribution: { date_of_engagement: string | Date, date_of_submission: string | Date, details?: string | null, id: number, name: string, proof?: string | null, updatedAt: string | Date, on_chain_id?: number | null, tx_hash?: string | null, activity_type: { active: boolean, createdAt: string | Date, id: number, name: string, updatedAt: string | Date }, chain?: { chain_id: string } | null, status: { createdAt: string | Date, id: number, name: string, updatedAt: string | Date }, user: { address: string, createdAt: string | Date, display_name?: string | null, full_name?: string | null, id: number, name?: string | null, updatedAt: string | Date }, attestations: Array<{ id: number, user_id: number, date_of_attestation: string | Date, attestation_status?: { id: number, name: string } | null, user: { name?: string | null, address: string, id: number } }>, guilds: Array<{ id: number, guild_id: number, guild: { id: number, name?: string | null } }> } }> };

export type TwitterTweetContributionFragmentFragment = { id: number, updatedAt: string | Date, createdAt: string | Date, contribution: { date_of_engagement: string | Date, date_of_submission: string | Date, details?: string | null, id: number, name: string, proof?: string | null, updatedAt: string | Date, on_chain_id?: number | null, tx_hash?: string | null, activity_type: { active: boolean, createdAt: string | Date, id: number, name: string, updatedAt: string | Date }, chain?: { chain_id: string } | null, status: { createdAt: string | Date, id: number, name: string, updatedAt: string | Date }, user: { address: string, createdAt: string | Date, display_name?: string | null, full_name?: string | null, id: number, name?: string | null, updatedAt: string | Date }, attestations: Array<{ id: number, user_id: number, date_of_attestation: string | Date, attestation_status?: { id: number, name: string } | null, user: { name?: string | null, address: string, id: number } }>, guilds: Array<{ id: number, guild_id: number, guild: { id: number, name?: string | null } }> } };
Expand Down Expand Up @@ -18791,6 +18800,14 @@ export const GuildUserFragmentFragmentDoc = gql`
}
}
`;
export const MembershipStatusFragmentFragmentDoc = gql`
fragment MembershipStatusFragment on GuildMembershipStatus {
id
createdAt
updatedAt
name
}
`;
export const ContributionFragmentFragmentDoc = gql`
fragment ContributionFragment on Contribution {
activity_type {
Expand Down Expand Up @@ -19217,6 +19234,13 @@ export const ListGuildImportsDocument = gql`
}
}
${GuildImportFragmentFragmentDoc}`;
export const GuildMembershipStatusDocument = gql`
query guildMembershipStatus($where: GuildMembershipStatusWhereUniqueInput!) {
result: guildMembershipStatus(where: $where) {
...MembershipStatusFragment
}
}
${MembershipStatusFragmentFragmentDoc}`;
export const BulkCreateTwitterTweetDocument = gql`
mutation bulkCreateTwitterTweet($data: [TwitterTweetCreateManyInput!]!, $skipDuplicates: Boolean!) {
createManyTwitterTweet(data: $data, skipDuplicates: $skipDuplicates) {
Expand Down Expand Up @@ -19648,6 +19672,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
listGuildImports(variables?: ListGuildImportsQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<ListGuildImportsQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<ListGuildImportsQuery>(ListGuildImportsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'listGuildImports', 'query');
},
guildMembershipStatus(variables: GuildMembershipStatusQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GuildMembershipStatusQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GuildMembershipStatusQuery>(GuildMembershipStatusDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'guildMembershipStatus', 'query');
},
bulkCreateTwitterTweet(variables: BulkCreateTwitterTweetMutationVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<BulkCreateTwitterTweetMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<BulkCreateTwitterTweetMutation>(BulkCreateTwitterTweetDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'bulkCreateTwitterTweet', 'mutation');
},
Expand Down

0 comments on commit e308e58

Please sign in to comment.