Skip to content

Commit fbb8992

Browse files
Merge pull request #282 from daostack/backend/main
New backend [WIP]
2 parents cde415b + 130c498 commit fbb8992

File tree

192 files changed

+7281
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+7281
-117
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,14 @@ build
559559

560560
# vercel
561561
.vercel
562+
563+
564+
packages/core/src/domain/constants/secrets/*
565+
566+
567+
.env
568+
.env.staging
569+
.env.production
570+
571+
**/secrets/*
572+

.run/GraphQL.run.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="GraphQL" type="js.build_tools.npm">
3+
<package-json value="$PROJECT_DIR$/packages/graphql/package.json" />
4+
<command value="run" />
5+
<scripts>
6+
<script value="dev" />
7+
</scripts>
8+
<node-interpreter value="project" />
9+
<envs />
10+
<method v="2" />
11+
</configuration>
12+
</component>

.run/Worker.run.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Worker" type="js.build_tools.npm">
3+
<package-json value="$PROJECT_DIR$/packages/worker/package.json" />
4+
<command value="run" />
5+
<scripts>
6+
<script value="dev" />
7+
</scripts>
8+
<node-interpreter value="project" />
9+
<envs />
10+
<method v="2" />
11+
</configuration>
12+
</component>

packages/core/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.env
2+
.env.staging
3+
.env.production
4+
5+
**/secrets/*
6+

packages/core/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@common/core",
3+
"version": "1.9.10-rc.0",
4+
"author": "Alexander Ivanov @alexander2001i",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"dev": "yarn compile:watch",
8+
"compile": "tsc -p tsconfig.json && yarn fix:paths",
9+
"compile:watch": "tsc-watch --onSuccess \"yarn fix:paths\"",
10+
"fix:paths": "tscpaths -p tsconfig.json -s ./src -o ./dist"
11+
},
12+
"devDependencies": {
13+
"@types/request-ip": "^0.0.35",
14+
"@types/uuid": "^8.3.0",
15+
"prisma": "^2.20.1",
16+
"ts-node-dev": "^1.1.6",
17+
"tsc-watch": "^4.2.9",
18+
"tscpaths": "^0.0.9",
19+
"typescript": "^4.2.3"
20+
},
21+
"dependencies": {
22+
"@common/queues": "^1.9.10-rc.0",
23+
"@prisma/client": "^2.20.1",
24+
"axios": "^0.21.1",
25+
"date-fns": "^2.19.0",
26+
"dotenv": "^8.2.0",
27+
"firebase-admin": "9.5.0",
28+
"tsconfig-paths": "^3.9.0",
29+
"winston": "^3.3.3",
30+
"winston-slack-webhook-transport": "^2.0.1",
31+
"zod": "^1.11.13"
32+
}
33+
}
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
-- CreateEnum
2+
CREATE TYPE "FundingType" AS ENUM ('OneTime', 'Monthly');
3+
4+
-- CreateEnum
5+
CREATE TYPE "CommonMemberRole" AS ENUM ('Founder');
6+
7+
-- CreateEnum
8+
CREATE TYPE "FundingState" AS ENUM ('NotEligible', 'AwaitingApproval', 'Pending', 'Completed', 'Confirmed');
9+
10+
-- CreateEnum
11+
CREATE TYPE "ProposalType" AS ENUM ('FundingRequest', 'JoinRequest');
12+
13+
-- CreateEnum
14+
CREATE TYPE "ProposalState" AS ENUM ('Countdown', 'Finalizing', 'Rejected', 'Accepted');
15+
16+
-- CreateEnum
17+
CREATE TYPE "ProposalPaymentState" AS ENUM ('NotAttempted', 'Pending', 'Successful', 'Unsuccessful');
18+
19+
-- CreateEnum
20+
CREATE TYPE "VoteOutcome" AS ENUM ('Approve', 'Condemn');
21+
22+
-- CreateEnum
23+
CREATE TYPE "PaymentType" AS ENUM ('OneTimePayment', 'SubscriptionInitialPayment', 'SubscriptionSequentialPayment');
24+
25+
-- CreateEnum
26+
CREATE TYPE "PaymentCircleStatus" AS ENUM ('pending', 'failed', 'confirmed', 'paid');
27+
28+
-- CreateEnum
29+
CREATE TYPE "PaymentStatus" AS ENUM ('NotAttempted', 'Pending', 'Successful', 'Unsuccessful');
30+
31+
-- CreateEnum
32+
CREATE TYPE "CardNetwork" AS ENUM ('VISA', 'MASTERCARD');
33+
34+
-- CreateEnum
35+
CREATE TYPE "EventType" AS ENUM ('CommonCreated', 'CommonMemberCreated', 'CommonMemberRoleAdded', 'CommonMemberRoleRemoved', 'JoinRequestCreated', 'JoinRequestAccepted', 'JoinRequestRejected', 'FundingRequestCreated', 'FundingRequestAccepted', 'FundingRequestRejected', 'CardCreated', 'CardCvvVerificationPassed', 'CardCvvVerificationFailed', 'PaymentCreated', 'PaymentSucceeded', 'PaymentFailed', 'ProposalMajorityReached', 'ProposalExpired', 'VoteCreated', 'UserCreated');
36+
37+
-- CreateTable
38+
CREATE TABLE "User" (
39+
"id" TEXT NOT NULL,
40+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
41+
"updatedAt" TIMESTAMP(3) NOT NULL,
42+
"firstName" TEXT NOT NULL,
43+
"lastName" TEXT NOT NULL,
44+
"email" TEXT NOT NULL,
45+
"emailVerified" BOOLEAN NOT NULL DEFAULT false,
46+
47+
PRIMARY KEY ("id")
48+
);
49+
50+
-- CreateTable
51+
CREATE TABLE "Common" (
52+
"id" TEXT NOT NULL,
53+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
54+
"updatedAt" TIMESTAMP(3) NOT NULL,
55+
"name" TEXT NOT NULL,
56+
"balance" INTEGER NOT NULL DEFAULT 0,
57+
"raised" INTEGER NOT NULL DEFAULT 0,
58+
"whitelisted" BOOLEAN NOT NULL DEFAULT false,
59+
"fundingType" "FundingType" NOT NULL,
60+
"fundingCooldown" TIMESTAMP(3) NOT NULL,
61+
"fundingMinimumAmount" INTEGER NOT NULL,
62+
63+
PRIMARY KEY ("id")
64+
);
65+
66+
-- CreateTable
67+
CREATE TABLE "CommonMember" (
68+
"id" TEXT NOT NULL,
69+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
70+
"updatedAt" TIMESTAMP(3) NOT NULL,
71+
"roles" "CommonMemberRole"[],
72+
"commonId" TEXT NOT NULL,
73+
"userId" TEXT NOT NULL,
74+
75+
PRIMARY KEY ("id")
76+
);
77+
78+
-- CreateTable
79+
CREATE TABLE "JoinProposal" (
80+
"id" TEXT NOT NULL,
81+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
82+
"updatedAt" TIMESTAMP(3) NOT NULL,
83+
"funding" INTEGER NOT NULL,
84+
"fundingType" "FundingType" NOT NULL,
85+
"paymentState" "ProposalPaymentState" NOT NULL DEFAULT E'NotAttempted',
86+
"cardId" TEXT NOT NULL,
87+
"subscriptionId" TEXT,
88+
89+
PRIMARY KEY ("id")
90+
);
91+
92+
-- CreateTable
93+
CREATE TABLE "FundingProposal" (
94+
"id" TEXT NOT NULL,
95+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
96+
"updatedAt" TIMESTAMP(3) NOT NULL,
97+
"amount" INTEGER NOT NULL,
98+
"fundingState" "FundingState" NOT NULL DEFAULT E'NotEligible',
99+
100+
PRIMARY KEY ("id")
101+
);
102+
103+
-- CreateTable
104+
CREATE TABLE "Proposal" (
105+
"id" TEXT NOT NULL,
106+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
107+
"updatedAt" TIMESTAMP(3) NOT NULL,
108+
"expiresAt" TIMESTAMP(3) NOT NULL,
109+
"title" TEXT,
110+
"description" TEXT,
111+
"link" JSONB,
112+
"files" JSONB,
113+
"images" JSONB,
114+
"ipAddress" TEXT,
115+
"type" "ProposalType" NOT NULL,
116+
"state" "ProposalState" NOT NULL DEFAULT E'Countdown',
117+
"votesFor" INTEGER NOT NULL DEFAULT 0,
118+
"votesAgainst" INTEGER NOT NULL DEFAULT 0,
119+
"joinId" TEXT,
120+
"fundingId" TEXT,
121+
"userId" TEXT NOT NULL,
122+
"commonId" TEXT NOT NULL,
123+
"commonMemberId" TEXT,
124+
125+
PRIMARY KEY ("id")
126+
);
127+
128+
-- CreateTable
129+
CREATE TABLE "Subscription" (
130+
"id" TEXT NOT NULL,
131+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
132+
"updatedAt" TIMESTAMP(3) NOT NULL,
133+
"cardId" TEXT NOT NULL,
134+
"userId" TEXT NOT NULL,
135+
"commonId" TEXT NOT NULL,
136+
137+
PRIMARY KEY ("id")
138+
);
139+
140+
-- CreateTable
141+
CREATE TABLE "Vote" (
142+
"id" TEXT NOT NULL,
143+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
144+
"updatedAt" TIMESTAMP(3) NOT NULL,
145+
"outcome" "VoteOutcome" NOT NULL,
146+
"commonMemberId" TEXT NOT NULL,
147+
"proposalId" TEXT NOT NULL,
148+
149+
PRIMARY KEY ("id")
150+
);
151+
152+
-- CreateTable
153+
CREATE TABLE "Payment" (
154+
"id" TEXT NOT NULL,
155+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
156+
"updatedAt" TIMESTAMP(3) NOT NULL,
157+
"processed" BOOLEAN NOT NULL DEFAULT false,
158+
"processedError" BOOLEAN NOT NULL DEFAULT false,
159+
"type" "PaymentType" NOT NULL,
160+
"status" "PaymentStatus" NOT NULL DEFAULT E'NotAttempted',
161+
"circlePaymentStatus" "PaymentCircleStatus",
162+
"circlePaymentId" TEXT,
163+
"amount" INTEGER NOT NULL,
164+
"subscriptionId" TEXT,
165+
"joinId" TEXT NOT NULL,
166+
"userId" TEXT NOT NULL,
167+
"commonId" TEXT NOT NULL,
168+
"cardId" TEXT NOT NULL,
169+
170+
PRIMARY KEY ("id")
171+
);
172+
173+
-- CreateTable
174+
CREATE TABLE "Card" (
175+
"id" TEXT NOT NULL,
176+
"circleCardId" TEXT NOT NULL,
177+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
178+
"updatedAt" TIMESTAMP(3) NOT NULL,
179+
"digits" TEXT NOT NULL,
180+
"network" "CardNetwork" NOT NULL,
181+
"cvvCheck" TEXT NOT NULL,
182+
"avsCheck" TEXT NOT NULL,
183+
"userId" TEXT NOT NULL,
184+
185+
PRIMARY KEY ("id")
186+
);
187+
188+
-- CreateTable
189+
CREATE TABLE "CardBillingDetail" (
190+
"id" TEXT NOT NULL,
191+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
192+
"updatedAt" TIMESTAMP(3) NOT NULL,
193+
"name" TEXT NOT NULL,
194+
"line1" TEXT NOT NULL,
195+
"line2" TEXT,
196+
"city" TEXT NOT NULL,
197+
"country" TEXT NOT NULL,
198+
"district" TEXT,
199+
"postalCode" TEXT NOT NULL,
200+
"cardId" TEXT NOT NULL,
201+
202+
PRIMARY KEY ("id")
203+
);
204+
205+
-- CreateTable
206+
CREATE TABLE "Event" (
207+
"id" TEXT NOT NULL,
208+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
209+
"updatedAt" TIMESTAMP(3) NOT NULL,
210+
"type" "EventType" NOT NULL,
211+
"payload" JSONB,
212+
"commonId" TEXT,
213+
"userId" TEXT,
214+
215+
PRIMARY KEY ("id")
216+
);
217+
218+
-- CreateIndex
219+
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email");
220+
221+
-- CreateIndex
222+
CREATE UNIQUE INDEX "CommonMember.userId_commonId_unique" ON "CommonMember"("userId", "commonId");
223+
224+
-- CreateIndex
225+
CREATE UNIQUE INDEX "Proposal.joinId_unique" ON "Proposal"("joinId");
226+
227+
-- CreateIndex
228+
CREATE UNIQUE INDEX "Proposal.fundingId_unique" ON "Proposal"("fundingId");
229+
230+
-- CreateIndex
231+
CREATE UNIQUE INDEX "Vote.commonMemberId_proposalId_unique" ON "Vote"("commonMemberId", "proposalId");
232+
233+
-- CreateIndex
234+
CREATE UNIQUE INDEX "CardBillingDetail_cardId_unique" ON "CardBillingDetail"("cardId");
235+
236+
-- AddForeignKey
237+
ALTER TABLE "CommonMember" ADD FOREIGN KEY ("commonId") REFERENCES "Common"("id") ON DELETE CASCADE ON UPDATE CASCADE;
238+
239+
-- AddForeignKey
240+
ALTER TABLE "CommonMember" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
241+
242+
-- AddForeignKey
243+
ALTER TABLE "JoinProposal" ADD FOREIGN KEY ("cardId") REFERENCES "Card"("id") ON DELETE CASCADE ON UPDATE CASCADE;
244+
245+
-- AddForeignKey
246+
ALTER TABLE "JoinProposal" ADD FOREIGN KEY ("subscriptionId") REFERENCES "Subscription"("id") ON DELETE SET NULL ON UPDATE CASCADE;
247+
248+
-- AddForeignKey
249+
ALTER TABLE "Proposal" ADD FOREIGN KEY ("joinId") REFERENCES "JoinProposal"("id") ON DELETE SET NULL ON UPDATE CASCADE;
250+
251+
-- AddForeignKey
252+
ALTER TABLE "Proposal" ADD FOREIGN KEY ("fundingId") REFERENCES "FundingProposal"("id") ON DELETE SET NULL ON UPDATE CASCADE;
253+
254+
-- AddForeignKey
255+
ALTER TABLE "Proposal" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
256+
257+
-- AddForeignKey
258+
ALTER TABLE "Proposal" ADD FOREIGN KEY ("commonId") REFERENCES "Common"("id") ON DELETE CASCADE ON UPDATE CASCADE;
259+
260+
-- AddForeignKey
261+
ALTER TABLE "Proposal" ADD FOREIGN KEY ("commonMemberId") REFERENCES "CommonMember"("id") ON DELETE SET NULL ON UPDATE CASCADE;
262+
263+
-- AddForeignKey
264+
ALTER TABLE "Subscription" ADD FOREIGN KEY ("cardId") REFERENCES "Card"("id") ON DELETE CASCADE ON UPDATE CASCADE;
265+
266+
-- AddForeignKey
267+
ALTER TABLE "Subscription" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
268+
269+
-- AddForeignKey
270+
ALTER TABLE "Subscription" ADD FOREIGN KEY ("commonId") REFERENCES "Common"("id") ON DELETE CASCADE ON UPDATE CASCADE;
271+
272+
-- AddForeignKey
273+
ALTER TABLE "Vote" ADD FOREIGN KEY ("proposalId") REFERENCES "Proposal"("id") ON DELETE CASCADE ON UPDATE CASCADE;
274+
275+
-- AddForeignKey
276+
ALTER TABLE "Vote" ADD FOREIGN KEY ("commonMemberId") REFERENCES "CommonMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;
277+
278+
-- AddForeignKey
279+
ALTER TABLE "Payment" ADD FOREIGN KEY ("cardId") REFERENCES "Card"("id") ON DELETE CASCADE ON UPDATE CASCADE;
280+
281+
-- AddForeignKey
282+
ALTER TABLE "Payment" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
283+
284+
-- AddForeignKey
285+
ALTER TABLE "Payment" ADD FOREIGN KEY ("commonId") REFERENCES "Common"("id") ON DELETE CASCADE ON UPDATE CASCADE;
286+
287+
-- AddForeignKey
288+
ALTER TABLE "Payment" ADD FOREIGN KEY ("joinId") REFERENCES "JoinProposal"("id") ON DELETE CASCADE ON UPDATE CASCADE;
289+
290+
-- AddForeignKey
291+
ALTER TABLE "Payment" ADD FOREIGN KEY ("subscriptionId") REFERENCES "Subscription"("id") ON DELETE SET NULL ON UPDATE CASCADE;
292+
293+
-- AddForeignKey
294+
ALTER TABLE "Card" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
295+
296+
-- AddForeignKey
297+
ALTER TABLE "CardBillingDetail" ADD FOREIGN KEY ("cardId") REFERENCES "Card"("id") ON DELETE CASCADE ON UPDATE CASCADE;
298+
299+
-- AddForeignKey
300+
ALTER TABLE "Event" ADD FOREIGN KEY ("commonId") REFERENCES "Common"("id") ON DELETE SET NULL ON UPDATE CASCADE;
301+
302+
-- AddForeignKey
303+
ALTER TABLE "Event" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "FundingState" ADD VALUE 'Eligible';

0 commit comments

Comments
 (0)