Skip to content

Commit

Permalink
clean up relation names for scout models (#5109)
Browse files Browse the repository at this point in the history
* clean up relation names for scout models

* fix more types

* fix more types

* fix test

* fix it
  • Loading branch information
mattcasey authored Dec 5, 2024
1 parent aa3c487 commit b2ba2ab
Show file tree
Hide file tree
Showing 38 changed files with 117 additions and 113 deletions.
6 changes: 3 additions & 3 deletions apps/scoutgame/lib/scouts/getTopScouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export async function getTopScouts({ limit }: { limit: number }): Promise<TopSco
avatar: true,
nftPurchaseEvents: {
where: {
builderNFT: {
builderNft: {
season: currentSeason
}
},
select: {
builderNFT: {
builderNft: {
select: {
builderId: true
}
Expand All @@ -63,7 +63,7 @@ export async function getTopScouts({ limit }: { limit: number }): Promise<TopSco
return topScouts
.map((scout) => {
const buildersScouted = Array.from(
new Set(scout.user.nftPurchaseEvents.map((event) => event.builderNFT.builderId))
new Set(scout.user.nftPurchaseEvents.map((event) => event.builderNft.builderId))
).length;
const nftsHeld = scout.user.userSeasonStats[0]?.nftsPurchased || 0;
const allTimePoints = scout.user.userAllTimeStats[0]?.pointsEarnedAsScout || 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { log } from "@charmverse/core/log";
import { prisma } from "@charmverse/core/prisma-client";
import { prettyPrint } from "@packages/utils/strings";

import { log } from '@charmverse/core/log';
import { prisma } from '@charmverse/core/prisma-client';
import { prettyPrint } from '@packages/utils/strings';

async function detectDuplicateRecordings() {
const duplicatePurchaseEvents = await prisma.nFTPurchaseEvent.groupBy({
by: 'txHash',
_count: true,
}).then(events => events.filter(ev => ev._count > 1));
const duplicatePurchaseEvents = await prisma.nFTPurchaseEvent
.groupBy({
by: 'txHash',
_count: true
})
.then((events) => events.filter((ev) => ev._count > 1));

if (!duplicatePurchaseEvents.length) {
log.info(`No duplicate events found`);
Expand All @@ -17,7 +18,7 @@ async function detectDuplicateRecordings() {
const sourceEvents = await prisma.nFTPurchaseEvent.findMany({
where: {
txHash: {
in: duplicatePurchaseEvents.map(ev => ev.txHash),
in: duplicatePurchaseEvents.map((ev) => ev.txHash),
mode: 'insensitive'
}
},
Expand All @@ -30,18 +31,20 @@ async function detectDuplicateRecordings() {
paidInPoints: true,
pointsValue: true,
txHash: true,
builderNFT: {
builderNft: {
select: {
tokenId: true
}
}
}
});

const eventsWithSource = duplicatePurchaseEvents.map(ev => ({...ev, sourceEvents: sourceEvents.filter(source => source.txHash.toLowerCase() === ev.txHash.toLowerCase())}));
const eventsWithSource = duplicatePurchaseEvents.map((ev) => ({
...ev,
sourceEvents: sourceEvents.filter((source) => source.txHash.toLowerCase() === ev.txHash.toLowerCase())
}));

log.info(`Detected ${eventsWithSource.length} duplicated tx hashes `)
log.info(`Detected ${eventsWithSource.length} duplicated tx hashes `);

return eventsWithSource;

}
2 changes: 1 addition & 1 deletion apps/scoutgamecron/src/scripts/createBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function createBuilder({ fid, githubLogin }: { fid: number; githubLogin: s
farcasterId: fid,
farcasterName: username,
referralCode: username + Math.random().toString().replace('.', '').slice(0, 6),
githubUser: githubUserDB
githubUsers: githubUserDB
? { connect: { id: githubUserDB.id } }
: {
create: {
Expand Down
2 changes: 1 addition & 1 deletion apps/scoutgamecron/src/scripts/createBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function createBuilders() {
builderStatus: 'applied',
farcasterId: fid,
farcasterName: username,
githubUser: {
githubUsers: {
create: {
id: githubUser.data.id,
login,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function deleteBuilderAndRedistributePoints({ builderPath }: { builderPath

const nftPurchaseEvents = await prisma.nFTPurchaseEvent.findMany({
where: {
builderNFT: {
builderNft: {
season: currentSeason,
builder: {
path: builderPath
Expand Down Expand Up @@ -64,7 +64,7 @@ async function deleteBuilderAndRedistributePoints({ builderPath }: { builderPath
points,
description: `You received a ${points} point gift from Scout Game`,
claimed: true,
earnedAs: 'scout',
earnedAs: 'scout'
});
await prisma.userSeasonStats.update({
where: {
Expand Down
10 changes: 5 additions & 5 deletions apps/scoutgamecron/src/scripts/processBuilderActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ const windowStart = DateTime.fromISO('2024-10-28', { zone: 'utc' }).toJSDate();
// return;
const builder = await prisma.scout.findFirstOrThrow({
where: { path: 'mdqst' },
include: { githubUser: true }
include: { githubUsers: true }
});

await deleteBuilderEvents(builder.id, builder.githubUser[0]!.id);
await deleteBuilderEvents(builder.id, builder.githubUsers[0]!.id);
await processBuilderActivity({
builderId: builder.id,
githubUser: builder.githubUser[0]!,
githubUser: builder.githubUsers[0]!,
createdAfter: windowStart,
season: currentSeason
});
return;
console.log('Getting builder activity');
const w = await prisma.scout.findFirst({
where: { path: 'mdqst' },
include: { githubUser: true }
include: { githubUsers: true }
});

const { commits, pullRequests } = await getBuilderActivity({
login: 'mdqst',
githubUserId: w?.githubUser[0]?.id,
githubUserId: w?.githubUsers[0]?.id,
after: DateTime.fromISO('2024-10-28', { zone: 'utc' }).toJSDate()
});
console.log(commits.length);
Expand Down
4 changes: 2 additions & 2 deletions apps/scoutgamecron/src/scripts/seeder/generateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ export async function generateBuilder({ index }: { index: number }) {
agreedToTermsAt: new Date(),
onboardedAt: new Date(),
referralCode: randomString(),
scoutWallet: {
wallets: {
create: {
address: faker.finance.ethereumAddress()
}
},
farcasterId: faker.number.int({ min: 1, max: 5000000 }) + index,
farcasterName: path,
builderStatus,
githubUser: {
githubUsers: {
create: githubUser
},
builderNfts:
Expand Down
2 changes: 1 addition & 1 deletion apps/scoutgamecron/src/scripts/seeder/generateScout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function generateScout({ index }: { index: number }) {
referralCode: randomString(),
agreedToTermsAt: new Date(),
onboardedAt: new Date(),
scoutWallet: {
wallets: {
create: {
address: faker.finance.ethereumAddress()
}
Expand Down
16 changes: 9 additions & 7 deletions apps/scoutgamecron/src/scripts/seeder/generateSeedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { claimPoints } from '@packages/scoutgame/points/claimPoints';
import { getWeekFromDate, currentSeason } from '@packages/scoutgame/dates';
import { getBuildersLeaderboard } from '@packages/scoutgame/builders/getBuildersLeaderboard';
import { DateTime } from 'luxon';
import {findOrCreateFarcasterUser} from '@packages/scoutgame/users/findOrCreateFarcasterUser';
import { findOrCreateFarcasterUser } from '@packages/scoutgame/users/findOrCreateFarcasterUser';

import { processScoutPointsPayout } from '../../tasks/processGemsPayout/processScoutPointsPayout';
import { updateBuildersRank } from '@packages/scoutgame/builders/updateBuildersRank';
Expand Down Expand Up @@ -41,7 +41,7 @@ function assignBuildersToScout(builders: BuilderInfo[]) {
type MinMaxRange = {
min: number;
max: number;
}
};

const defaultBuildersRange: MinMaxRange = {
min: 10,
Expand All @@ -51,7 +51,11 @@ const defaultBuildersRange: MinMaxRange = {
/**
* @fidToGenerate - Utility for including your own user id in the generated data
*/
export async function generateSeedData({buildersRange = defaultBuildersRange, includeFid}: {buildersRange?: MinMaxRange; includeFid?: number} = {buildersRange: defaultBuildersRange}) {
export async function generateSeedData(
{ buildersRange = defaultBuildersRange, includeFid }: { buildersRange?: MinMaxRange; includeFid?: number } = {
buildersRange: defaultBuildersRange
}
) {
// Total number of users that are builders (should be less than totalUsers)
const totalBuilders = faker.number.int(buildersRange);
// Total number of github repos
Expand Down Expand Up @@ -91,7 +95,7 @@ export async function generateSeedData({buildersRange = defaultBuildersRange, in
if (includeFid) {
const scout = await findOrCreateFarcasterUser({
fid: includeFid
})
});

const assignedToMe = assignBuildersToScout(builders);

Expand Down Expand Up @@ -124,7 +128,6 @@ export async function generateSeedData({buildersRange = defaultBuildersRange, in
});
}


// Go through each day of the past two weeks
const startDate = DateTime.now().minus({ weeks: 2 });
const endDate = DateTime.now();
Expand Down Expand Up @@ -210,5 +213,4 @@ export async function generateSeedData({buildersRange = defaultBuildersRange, in
});
}


// generateSeedData({buildersRange: {max: 5, min: 5}, includeFid: 4339}).then(console.log)
// generateSeedData({buildersRange: {max: 5, min: 5}, includeFid: 4339}).then(console.log)
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async function clearNfts() {
await prisma.builderNft.deleteMany({
where: {
builder: {
githubUser: {
githubUsers: {
some: {
login: {
in: Object.keys(devUsers)
Expand Down
10 changes: 5 additions & 5 deletions apps/scoutgamecron/src/tasks/processBuilderActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function processAllBuilderActivity(
select: {
createdAt: true,
id: true,
githubUser: {
githubUsers: {
select: {
events: {
take: 1,
Expand All @@ -51,18 +51,18 @@ export async function processAllBuilderActivity(

for (const builder of builders) {
// If the builder was created less than and hr and has no existing events
const newBuilder = builder.createdAt > new Date(Date.now() - 60 * 60 * 1000) && !builder.githubUser[0]?.events[0];
const newBuilder = builder.createdAt > new Date(Date.now() - 60 * 60 * 1000) && !builder.githubUsers[0]?.events[0];

if (newBuilder) {
log.info(`Detected new builder. Pulling in github data for this season`, {
userId: builder.id,
githubUserId: builder.githubUser[0]?.id
githubUserId: builder.githubUsers[0]?.id
});
}

await processBuilderActivity({
builderId: builder.id,
githubUser: builder.githubUser[0]!,
githubUser: builder.githubUsers[0]!,
createdAfter: newBuilder ? getDateFromISOWeek(getCurrentWeek()).toJSDate() : createdAfter,
season
});
Expand All @@ -72,7 +72,7 @@ export async function processAllBuilderActivity(
lastId: builder.id, // log last id in case we want to start in the middle of the process
builders: builders
.slice(builders.indexOf(builder), builders.indexOf(builder) + 10)
.map((b) => b.githubUser[0].login)
.map((b) => b.githubUsers[0].login)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function recordClosedPullRequest({
}) {
const builder = await prisma.scout.findFirst({
where: {
githubUser: {
githubUsers: {
some: {
id: pullRequest.author.id
}
Expand Down Expand Up @@ -87,7 +87,7 @@ export async function recordClosedPullRequest({

const nftPurchaseEvents = await prisma.nFTPurchaseEvent.findMany({
where: {
builderNFT: {
builderNft: {
season,
builderId: builder.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function recordCommit({ commit, season }: { commit: RequiredCommitF
// It's a new event, we can record notification
const nftPurchaseEvents = await prisma.nFTPurchaseEvent.findMany({
where: {
builderNFT: {
builderNft: {
season,
builderId: githubUser.builderId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export async function recordMergedPullRequest({
// It's a new event, we can record notification
const nftPurchaseEvents = await prisma.nFTPurchaseEvent.findMany({
where: {
builderNFT: {
builderNft: {
season,
builderId: githubUser.builderId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function updateTalentMoxieProfiles() {
},
farcasterId: true,
id: true,
scoutWallet: {
wallets: {
select: {
address: true
}
Expand All @@ -39,7 +39,7 @@ export async function updateTalentMoxieProfiles() {
// If the builder has a talent profile, use the wallet address, otherwise use the scout wallet
wallets: builder.talentProfile
? [builder.talentProfile.address]
: builder.scoutWallet.map((wallet) => wallet.address)
: builder.wallets.map((wallet) => wallet.address)
});
updatedTalentProfiles += 1;
} catch (error) {
Expand Down
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"@bangle.dev/pm-commands": "^0.31.6",
"@bangle.dev/utils": "^0.31.6",
"@beam-australia/react-env": "^3.1.1",
"@charmverse/core": "^0.98.1",
"@charmverse/core": "^0.98.2-rc-scout-wallets.0",
"@column-resizer/core": "^1.0.2",
"@datadog/browser-logs": "^4.42.2",
"@datadog/browser-rum": "^4.42.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function PublicScoutProfile({ publicUser }: { publicUser: BasicUser
<PublicScoutProfileContainer
scout={{
...scout,
githubLogin: scout.githubUser[0]?.login
githubLogin: scout.githubUsers[0]?.login
}}
allTimePoints={allTimePoints}
seasonPoints={seasonPoints}
Expand Down
Loading

0 comments on commit b2ba2ab

Please sign in to comment.