Skip to content

Commit 3f6f3f0

Browse files
Merge pull request #479 from daostack/CM-401-migration-to-graphql
WEB: Migration to Postgress from Firebase
2 parents 7ee0567 + 49cd421 commit 3f6f3f0

File tree

58 files changed

+7095
-703
lines changed

Some content is hidden

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

58 files changed

+7095
-703
lines changed

packages/core/src/domain/validation/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as z from 'zod';
22
import { allPermissions } from './permissions';
33

44
export { ProposalLinkSchema } from './schemas/ProposalLink.schema';
5+
export { LinkSchema } from './schemas/Link.schema';
56
export { BillingDetailsSchema } from './schemas/BillingDetails.schema';
67
export { ProposalImageSchema } from './schemas/ProposalImage.schema';
78
export { ProposalFileSchema } from './schemas/ProposalFile.schema';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as z from 'zod';
2+
3+
export const LinkSchema = z.object({
4+
title: z.string()
5+
.nonempty(),
6+
7+
url: z.string()
8+
.nonempty()
9+
.url()
10+
});

packages/core/src/services/commons/command/createCommonCommand.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FundingType, Common, CommonMemberRole, EventType } from '@prisma/client
33

44
import { prisma } from '@toolkits';
55
import { eventService } from '@services';
6+
import { LinkSchema } from '@validation';
67

78
import { createCommonMemberCommand } from './createCommonMemberCommand';
89
import { addCommonMemberRoleCommand } from './addCommonMemberRoleCommand';
@@ -32,7 +33,15 @@ const schema = z.object({
3233
.max(100000),
3334

3435
founderId: z.string()
35-
.nonempty()
36+
.nonempty(),
37+
38+
links: z.array(LinkSchema)
39+
.nullable()
40+
.optional(),
41+
42+
rules: z.array(LinkSchema)
43+
.nullable()
44+
.optional(),
3645
});
3746

3847
export const createCommonCommand = async (command: z.infer<typeof schema>): Promise<Common> => {
@@ -46,7 +55,10 @@ export const createCommonCommand = async (command: z.infer<typeof schema>): Prom
4655
image: command.image,
4756

4857
fundingType: command.fundingType,
49-
fundingMinimumAmount: command.fundingMinimumAmount
58+
fundingMinimumAmount: command.fundingMinimumAmount,
59+
links: command.links,
60+
rules: command.rules,
61+
byline: command.byline,
5062
}
5163
});
5264

packages/graphql/src/generated/nexus-typegen.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export interface NexusGenInputs {
7171
name: string; // String!
7272
postalCode: string; // String!
7373
}
74+
CommonLinkInput: { // input type
75+
title: string; // String!
76+
url: string; // String!
77+
}
7478
CommonMemberOrderByInput: { // input type
7579
createdAt: NexusGenEnums['SortOrder']; // SortOrder!
7680
}
@@ -91,7 +95,9 @@ export interface NexusGenInputs {
9195
fundingMinimumAmount: number; // Int!
9296
fundingType: NexusGenEnums['FundingType']; // FundingType!
9397
image: string; // String!
98+
links?: NexusGenInputs['CommonLinkInput'][] | null; // [CommonLinkInput!]
9499
name: string; // String!
100+
rules?: NexusGenInputs['CommonLinkInput'][] | null; // [CommonLinkInput!]
95101
}
96102
CreateDiscussionInput: { // input type
97103
commonId: string; // ID!
@@ -165,6 +171,11 @@ export interface NexusGenInputs {
165171
createdAt?: NexusGenEnums['SortOrder'] | null; // SortOrder
166172
updatedAt?: NexusGenEnums['SortOrder'] | null; // SortOrder
167173
}
174+
DiscussionWhereInput: { // input type
175+
commonId?: NexusGenScalars['UUID'] | null; // UUID
176+
commonMemberId?: NexusGenScalars['UUID'] | null; // UUID
177+
userId?: string | null; // ID
178+
}
168179
EventOrderByInput: { // input type
169180
createdAt?: NexusGenEnums['SortOrder'] | null; // SortOrder
170181
type?: NexusGenEnums['SortOrder'] | null; // SortOrder
@@ -332,8 +343,10 @@ export interface NexusGenObjects {
332343
fundingType: NexusGenEnums['FundingType']; // FundingType!
333344
id: string; // ID!
334345
image: string; // String!
346+
links?: NexusGenScalars['JSON'] | null; // JSON
335347
name: string; // String!
336348
raised: number; // Int!
349+
rules?: NexusGenScalars['JSON'] | null; // JSON
337350
updatedAt: NexusGenScalars['DateTime']; // DateTime!
338351
whitelisted: boolean; // Boolean!
339352
}
@@ -364,6 +377,7 @@ export interface NexusGenObjects {
364377
topic: string; // String!
365378
type: NexusGenEnums['DiscussionType']; // DiscussionType!
366379
updatedAt: NexusGenScalars['DateTime']; // DateTime!
380+
userId: string; // String!
367381
}
368382
DiscussionMessage: { // root type
369383
createdAt: NexusGenScalars['DateTime']; // DateTime!
@@ -372,6 +386,7 @@ export interface NexusGenObjects {
372386
message: string; // String!
373387
type: NexusGenEnums['DiscussionMessageType']; // DiscussionMessageType!
374388
updatedAt: NexusGenScalars['DateTime']; // DateTime!
389+
userId: string; // String!
375390
}
376391
DiscussionSubscription: { // root type
377392
createdAt: NexusGenScalars['DateTime']; // DateTime!
@@ -570,11 +585,13 @@ export interface NexusGenFieldTypes {
570585
fundingType: NexusGenEnums['FundingType']; // FundingType!
571586
id: string; // ID!
572587
image: string; // String!
588+
links: NexusGenScalars['JSON'] | null; // JSON
573589
members: Array<NexusGenRootTypes['CommonMember'] | null>; // [CommonMember]!
574590
name: string; // String!
575591
proposals: NexusGenRootTypes['Proposal'][]; // [Proposal!]!
576592
raised: number; // Int!
577593
reports: NexusGenRootTypes['Report'][]; // [Report!]!
594+
rules: NexusGenScalars['JSON'] | null; // JSON
578595
updatedAt: NexusGenScalars['DateTime']; // DateTime!
579596
whitelisted: boolean; // Boolean!
580597
}
@@ -607,18 +624,22 @@ export interface NexusGenFieldTypes {
607624
id: NexusGenScalars['UUID']; // UUID!
608625
latestMessage: NexusGenScalars['DateTime']; // DateTime!
609626
messages: NexusGenRootTypes['DiscussionMessage'][]; // [DiscussionMessage!]!
627+
owner: NexusGenRootTypes['User'] | null; // User
610628
topic: string; // String!
611629
type: NexusGenEnums['DiscussionType']; // DiscussionType!
612630
updatedAt: NexusGenScalars['DateTime']; // DateTime!
631+
userId: string; // String!
613632
}
614633
DiscussionMessage: { // field return type
615634
createdAt: NexusGenScalars['DateTime']; // DateTime!
616635
flag: NexusGenEnums['DiscussionMessageFlag']; // DiscussionMessageFlag!
617636
id: NexusGenScalars['UUID']; // UUID!
618637
message: string; // String!
638+
owner: NexusGenRootTypes['User']; // User!
619639
reports: NexusGenRootTypes['Report'][]; // [Report!]!
620640
type: NexusGenEnums['DiscussionMessageType']; // DiscussionMessageType!
621641
updatedAt: NexusGenScalars['DateTime']; // DateTime!
642+
userId: string; // String!
622643
}
623644
DiscussionSubscription: { // field return type
624645
createdAt: NexusGenScalars['DateTime']; // DateTime!
@@ -775,6 +796,7 @@ export interface NexusGenFieldTypes {
775796
common: NexusGenRootTypes['Common'] | null; // Common
776797
commons: Array<NexusGenRootTypes['Common'] | null> | null; // [Common]
777798
discussion: NexusGenRootTypes['Discussion'] | null; // Discussion
799+
discussions: Array<NexusGenRootTypes['Discussion'] | null> | null; // [Discussion]
778800
events: Array<NexusGenRootTypes['Event'] | null> | null; // [Event]
779801
generateUserAuthToken: string; // String!
780802
getStatistics: Array<NexusGenRootTypes['Statistic'] | null> | null; // [Statistic]
@@ -889,11 +911,13 @@ export interface NexusGenFieldTypeNames {
889911
fundingType: 'FundingType'
890912
id: 'ID'
891913
image: 'String'
914+
links: 'JSON'
892915
members: 'CommonMember'
893916
name: 'String'
894917
proposals: 'Proposal'
895918
raised: 'Int'
896919
reports: 'Report'
920+
rules: 'JSON'
897921
updatedAt: 'DateTime'
898922
whitelisted: 'Boolean'
899923
}
@@ -926,18 +950,22 @@ export interface NexusGenFieldTypeNames {
926950
id: 'UUID'
927951
latestMessage: 'DateTime'
928952
messages: 'DiscussionMessage'
953+
owner: 'User'
929954
topic: 'String'
930955
type: 'DiscussionType'
931956
updatedAt: 'DateTime'
957+
userId: 'String'
932958
}
933959
DiscussionMessage: { // field return type name
934960
createdAt: 'DateTime'
935961
flag: 'DiscussionMessageFlag'
936962
id: 'UUID'
937963
message: 'String'
964+
owner: 'User'
938965
reports: 'Report'
939966
type: 'DiscussionMessageType'
940967
updatedAt: 'DateTime'
968+
userId: 'String'
941969
}
942970
DiscussionSubscription: { // field return type name
943971
createdAt: 'DateTime'
@@ -1094,6 +1122,7 @@ export interface NexusGenFieldTypeNames {
10941122
common: 'Common'
10951123
commons: 'Common'
10961124
discussion: 'Discussion'
1125+
discussions: 'Discussion'
10971126
events: 'Event'
10981127
generateUserAuthToken: 'String'
10991128
getStatistics: 'Statistic'
@@ -1315,6 +1344,10 @@ export interface NexusGenArgTypes {
13151344
discussion: { // args
13161345
id: string; // ID!
13171346
}
1347+
discussions: { // args
1348+
paginate?: NexusGenInputs['PaginateInput'] | null; // PaginateInput
1349+
where?: NexusGenInputs['DiscussionWhereInput'] | null; // DiscussionWhereInput
1350+
}
13181351
events: { // args
13191352
paginate?: NexusGenInputs['PaginateInput'] | null; // PaginateInput
13201353
}

packages/graphql/src/generated/schema.graphql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Common {
6464
"""The main identifier of the item"""
6565
id: ID!
6666
image: String!
67+
links: JSON
6768
members(orderBy: CommonMemberOrderByInput, skip: Int, take: Int): [CommonMember]!
6869

6970
"""The name of the common as provided"""
@@ -73,6 +74,7 @@ type Common {
7374
"""The total amount of money that the common has raised. In cents"""
7475
raised: Int!
7576
reports(where: ReportWhereInput = {status: {in: [Active]}}): [Report!]!
77+
rules: JSON
7678

7779
"""The date, at which the item was last modified"""
7880
updatedAt: DateTime!
@@ -81,6 +83,11 @@ type Common {
8183
whitelisted: Boolean!
8284
}
8385

86+
input CommonLinkInput {
87+
title: String!
88+
url: String!
89+
}
90+
8491
type CommonMember implements BaseEntity {
8592
common: Common
8693
commonId: ID!
@@ -150,7 +157,9 @@ input CreateCommonInput {
150157
fundingMinimumAmount: Int!
151158
fundingType: FundingType!
152159
image: String!
160+
links: [CommonLinkInput!]
153161
name: String!
162+
rules: [CommonLinkInput!]
154163
}
155164

156165
input CreateDiscussionInput {
@@ -258,12 +267,16 @@ type Discussion implements BaseEntity {
258267
latestMessage: DateTime!
259268
messages(orderBy: DiscussionMessagesOrderByInput = {createdAt: asc}, skip: Int = 0, take: Int = 10): [DiscussionMessage!]!
260269

270+
"""The discussion creator"""
271+
owner: User
272+
261273
"""What this discussion is about"""
262274
topic: String!
263275
type: DiscussionType!
264276

265277
"""The date, at which the item was last modified"""
266278
updatedAt: DateTime!
279+
userId: String!
267280
}
268281

269282
type DiscussionMessage implements BaseEntity {
@@ -274,11 +287,13 @@ type DiscussionMessage implements BaseEntity {
274287
"""The main identifier of the item"""
275288
id: UUID!
276289
message: String!
290+
owner: User!
277291
reports: [Report!]!
278292
type: DiscussionMessageType!
279293

280294
"""The date, at which the item was last modified"""
281295
updatedAt: DateTime!
296+
userId: String!
282297
}
283298

284299
enum DiscussionMessageFlag {
@@ -327,6 +342,12 @@ enum DiscussionType {
327342
ProposalDiscussion
328343
}
329344

345+
input DiscussionWhereInput {
346+
commonId: UUID
347+
commonMemberId: UUID
348+
userId: ID
349+
}
350+
330351
type Event {
331352
"""The ID of the common, for whom the event was created"""
332353
commonId: ID
@@ -765,6 +786,7 @@ type Query {
765786
common(where: CommonWhereUniqueInput!): Common
766787
commons(paginate: PaginateInput): [Common]
767788
discussion(id: ID!): Discussion
789+
discussions(paginate: PaginateInput, where: DiscussionWhereInput): [Discussion]
768790
events(paginate: PaginateInput): [Event]
769791
generateUserAuthToken(authId: String!): String!
770792
getStatistics(where: StatisticsWhereInput): [Statistic]

packages/graphql/src/schema/Types/Common/Mutations/CreateCommon.mutation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export const CreateCommonInput = inputObjectType({
1818
t.string('action');
1919
t.string('byline');
2020
t.string('description');
21+
t.list.nonNull.field('links', {
22+
type: 'CommonLinkInput'
23+
});
24+
t.list.nonNull.field('rules', {
25+
type: 'CommonLinkInput'
26+
});
2127
}
2228
});
2329

packages/graphql/src/schema/Types/Common/Types/Common.type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const CommonType = objectType({
3131
description: 'The total amount of money that the common has raised. In cents'
3232
});
3333

34+
t.json('links');
35+
t.json('rules');
36+
3437
t.nonNull.string('image');
3538
t.string('description');
3639
t.string('action');

packages/graphql/src/schema/Types/Common/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { CommonActiveProposalsExtension } from './Extensions/CommonActiveProposa
1616

1717
import { CommonType } from './Types/Common.type';
1818
import { CommonWhereUniqueInput } from './Inputs/CommonWhereUnique.input';
19+
import { CommonLinkInput } from './Inputs/CommonLink.input';
20+
1921

2022
export const CommonTypes = [
2123
CommonType,
@@ -31,6 +33,7 @@ export const CommonTypes = [
3133
WhitelistCommonMutation,
3234

3335
CommonWhereUniqueInput,
36+
CommonLinkInput,
3437

3538
CommonEventsExtension,
3639
CommonReportsExtension,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { inputObjectType } from 'nexus';
2+
3+
export const CommonLinkInput = inputObjectType({
4+
name: 'CommonLinkInput',
5+
definition(t) {
6+
t.nonNull.string('title');
7+
t.nonNull.string('url');
8+
}
9+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { extendType } from 'nexus';
2+
import { prisma } from '@common/core';
3+
4+
export const DiscussionMessageOwnerExtension = extendType({
5+
type: 'DiscussionMessage',
6+
definition(t) {
7+
t.nonNull.field('owner', {
8+
type: 'User',
9+
resolve: (root) => {
10+
return prisma.user.findUnique({
11+
where: {
12+
id: root.userId
13+
}
14+
});
15+
}
16+
});
17+
}
18+
});

0 commit comments

Comments
 (0)