Skip to content

Commit cf651c8

Browse files
committed
Add budget attestations
1 parent 93ec4de commit cf651c8

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- CreateTable
2+
CREATE TABLE "UserBudgetAttestation" (
3+
"user_id" INTEGER NOT NULL,
4+
"attestation_id" TEXT NOT NULL,
5+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
7+
8+
CONSTRAINT "UserBudgetAttestation_pkey" PRIMARY KEY ("user_id")
9+
);
10+
11+
-- CreateIndex
12+
CREATE UNIQUE INDEX "UserBudgetAttestation_attestation_id_key" ON "UserBudgetAttestation"("attestation_id");
13+
14+
-- AddForeignKey
15+
ALTER TABLE "UserBudgetAttestation" ADD CONSTRAINT "UserBudgetAttestation_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ generator client {
99
}
1010

1111
model User {
12-
id Int @id @default(autoincrement())
13-
budget Int @default(2000000) // 2M In OP
14-
address String @unique()
15-
smartaddress String? @unique()
16-
ballotSuccess Int? @map("ballot_success")
17-
opAddress String? @unique() @map("op_address")
18-
createdAt DateTime @default(now()) @map("created_at")
19-
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
12+
id Int @id @default(autoincrement())
13+
budget Int @default(2000000) // 2M In OP
14+
address String @unique()
15+
smartaddress String? @unique()
16+
ballotSuccess Int? @map("ballot_success")
17+
opAddress String? @unique() @map("op_address")
18+
createdAt DateTime @default(now()) @map("created_at")
19+
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2020
identity Json? // Ideally should be unique except {} and null values but Prisma doesn't support partial
2121
// unique constraints
2222
badges Json?
@@ -29,6 +29,7 @@ model User {
2929
finishedCollection UserCollectionFinish[]
3030
shares Share[]
3131
attestations UserAttestation[]
32+
budgetAttestations UserBudgetAttestation[]
3233
projectStars ProjectStar[]
3334
cois ProjectCoI[]
3435
}
@@ -212,6 +213,16 @@ model UserAttestation {
212213
@@id([userId, collectionId])
213214
}
214215

216+
model UserBudgetAttestation {
217+
userId Int @map("user_id")
218+
attestationId String @unique() @map("attestation_id")
219+
createdAt DateTime @default(now()) @map("created_at")
220+
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
221+
user User @relation(fields: [userId], references: [id])
222+
223+
@@id([userId])
224+
}
225+
215226
enum DelegationPlatform {
216227
FARCASTER
217228
TWITTER

src/flow/flow.controller.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,11 +1106,27 @@ export class FlowController {
11061106
@Req() { userId }: AuthedReq,
11071107
@Body() { collectionId, attestationId }: AttestationDto,
11081108
) {
1109+
if (collectionId === -1) {
1110+
await this.prismaService.userBudgetAttestation.upsert({
1111+
where: {
1112+
userId: userId,
1113+
},
1114+
create: {
1115+
userId: userId,
1116+
attestationId,
1117+
},
1118+
update: {
1119+
attestationId,
1120+
},
1121+
});
1122+
1123+
return 'Success';
1124+
}
11091125
// collectionId = -1 is for the budget attestation
1110-
const isFinished =
1111-
collectionId > 0
1112-
? await this.flowService.isCollectionFinished(userId, collectionId)
1113-
: true;
1126+
const isFinished = await this.flowService.isCollectionFinished(
1127+
userId,
1128+
collectionId,
1129+
);
11141130

11151131
if (!isFinished)
11161132
throw new ForbiddenException(

0 commit comments

Comments
 (0)