Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/domain/validation/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as z from 'zod';

export { ProposalLinkSchema } from './schemas/ProposalLink.schema';
export { LinkSchema } from './schemas/Link.schema';
export { BillingDetailsSchema } from './schemas/BillingDetails.schema';
export { ProposalImageSchema } from './schemas/ProposalImage.schema';
export { ProposalFileSchema } from './schemas/ProposalFile.schema';
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/domain/validation/schemas/Link.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as z from 'zod';

export const LinkSchema = z.object({
title: z.string()
.nonempty(),

url: z.string()
.nonempty()
.url()
});
16 changes: 14 additions & 2 deletions packages/core/src/services/commons/command/createCommonCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FundingType, Common, CommonMemberRole, EventType } from '@prisma/client

import { prisma } from '@toolkits';
import { eventService } from '@services';
import { LinkSchema } from '@validation';

import { createCommonMemberCommand } from './createCommonMemberCommand';
import { addCommonMemberRoleCommand } from './addCommonMemberRoleCommand';
Expand Down Expand Up @@ -32,7 +33,15 @@ const schema = z.object({
.max(100000),

founderId: z.string()
.nonempty()
.nonempty(),

links: z.array(LinkSchema)
.nullable()
.optional(),

rules: z.array(LinkSchema)
.nullable()
.optional(),
});

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

fundingType: command.fundingType,
fundingMinimumAmount: command.fundingMinimumAmount
fundingMinimumAmount: command.fundingMinimumAmount,
links: command.links,
rules: command.rules,
byline: command.byline,
}
});

Expand Down
33 changes: 33 additions & 0 deletions packages/graphql/src/generated/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export interface NexusGenInputs {
name: string; // String!
postalCode: string; // String!
}
CommonLinkInput: { // input type
title: string; // String!
url: string; // String!
}
CommonMemberOrderByInput: { // input type
createdAt: NexusGenEnums['SortOrder']; // SortOrder!
}
Expand All @@ -90,7 +94,9 @@ export interface NexusGenInputs {
fundingMinimumAmount: number; // Int!
fundingType: NexusGenEnums['FundingType']; // FundingType!
image: string; // String!
links?: NexusGenInputs['CommonLinkInput'][] | null; // [CommonLinkInput!]
name: string; // String!
rules?: NexusGenInputs['CommonLinkInput'][] | null; // [CommonLinkInput!]
}
CreateDiscussionInput: { // input type
commonId: string; // ID!
Expand Down Expand Up @@ -155,6 +161,11 @@ export interface NexusGenInputs {
createdAt?: NexusGenEnums['SortOrder'] | null; // SortOrder
updatedAt?: NexusGenEnums['SortOrder'] | null; // SortOrder
}
DiscussionWhereInput: { // input type
commonId?: NexusGenScalars['UUID'] | null; // UUID
commonMemberId?: NexusGenScalars['UUID'] | null; // UUID
userId?: string | null; // ID
}
EventOrderByInput: { // input type
createdAt?: NexusGenEnums['SortOrder'] | null; // SortOrder
type?: NexusGenEnums['SortOrder'] | null; // SortOrder
Expand Down Expand Up @@ -304,8 +315,10 @@ export interface NexusGenObjects {
fundingType: NexusGenEnums['FundingType']; // FundingType!
id: string; // ID!
image: string; // String!
links?: NexusGenScalars['JSON'] | null; // JSON
name: string; // String!
raised: number; // Int!
rules?: NexusGenScalars['JSON'] | null; // JSON
updatedAt: NexusGenScalars['DateTime']; // DateTime!
whitelisted: boolean; // Boolean!
}
Expand Down Expand Up @@ -336,6 +349,7 @@ export interface NexusGenObjects {
topic: string; // String!
type: NexusGenEnums['DiscussionType']; // DiscussionType!
updatedAt: NexusGenScalars['DateTime']; // DateTime!
userId: string; // String!
}
DiscussionMessage: { // root type
createdAt: NexusGenScalars['DateTime']; // DateTime!
Expand All @@ -344,6 +358,7 @@ export interface NexusGenObjects {
message: string; // String!
type: NexusGenEnums['DiscussionMessageType']; // DiscussionMessageType!
updatedAt: NexusGenScalars['DateTime']; // DateTime!
userId: string; // String!
}
DiscussionSubscription: { // root type
createdAt: NexusGenScalars['DateTime']; // DateTime!
Expand Down Expand Up @@ -531,11 +546,13 @@ export interface NexusGenFieldTypes {
fundingType: NexusGenEnums['FundingType']; // FundingType!
id: string; // ID!
image: string; // String!
links: NexusGenScalars['JSON'] | null; // JSON
members: Array<NexusGenRootTypes['CommonMember'] | null>; // [CommonMember]!
name: string; // String!
proposals: NexusGenRootTypes['Proposal'][]; // [Proposal!]!
raised: number; // Int!
reports: NexusGenRootTypes['Report'][]; // [Report!]!
rules: NexusGenScalars['JSON'] | null; // JSON
updatedAt: NexusGenScalars['DateTime']; // DateTime!
whitelisted: boolean; // Boolean!
}
Expand Down Expand Up @@ -568,18 +585,22 @@ export interface NexusGenFieldTypes {
id: NexusGenScalars['UUID']; // UUID!
latestMessage: NexusGenScalars['DateTime']; // DateTime!
messages: NexusGenRootTypes['DiscussionMessage'][]; // [DiscussionMessage!]!
owner: NexusGenRootTypes['User'] | null; // User
topic: string; // String!
type: NexusGenEnums['DiscussionType']; // DiscussionType!
updatedAt: NexusGenScalars['DateTime']; // DateTime!
userId: string; // String!
}
DiscussionMessage: { // field return type
createdAt: NexusGenScalars['DateTime']; // DateTime!
flag: NexusGenEnums['DiscussionMessageFlag']; // DiscussionMessageFlag!
id: NexusGenScalars['UUID']; // UUID!
message: string; // String!
owner: NexusGenRootTypes['User']; // User!
reports: NexusGenRootTypes['Report'][]; // [Report!]!
type: NexusGenEnums['DiscussionMessageType']; // DiscussionMessageType!
updatedAt: NexusGenScalars['DateTime']; // DateTime!
userId: string; // String!
}
DiscussionSubscription: { // field return type
createdAt: NexusGenScalars['DateTime']; // DateTime!
Expand Down Expand Up @@ -715,6 +736,7 @@ export interface NexusGenFieldTypes {
common: NexusGenRootTypes['Common'] | null; // Common
commons: Array<NexusGenRootTypes['Common'] | null> | null; // [Common]
discussion: NexusGenRootTypes['Discussion'] | null; // Discussion
discussions: Array<NexusGenRootTypes['Discussion'] | null> | null; // [Discussion]
events: Array<NexusGenRootTypes['Event'] | null> | null; // [Event]
generateUserAuthToken: string; // String!
getStatistics: Array<NexusGenRootTypes['Statistic'] | null> | null; // [Statistic]
Expand Down Expand Up @@ -826,11 +848,13 @@ export interface NexusGenFieldTypeNames {
fundingType: 'FundingType'
id: 'ID'
image: 'String'
links: 'JSON'
members: 'CommonMember'
name: 'String'
proposals: 'Proposal'
raised: 'Int'
reports: 'Report'
rules: 'JSON'
updatedAt: 'DateTime'
whitelisted: 'Boolean'
}
Expand Down Expand Up @@ -863,18 +887,22 @@ export interface NexusGenFieldTypeNames {
id: 'UUID'
latestMessage: 'DateTime'
messages: 'DiscussionMessage'
owner: 'User'
topic: 'String'
type: 'DiscussionType'
updatedAt: 'DateTime'
userId: 'String'
}
DiscussionMessage: { // field return type name
createdAt: 'DateTime'
flag: 'DiscussionMessageFlag'
id: 'UUID'
message: 'String'
owner: 'User'
reports: 'Report'
type: 'DiscussionMessageType'
updatedAt: 'DateTime'
userId: 'String'
}
DiscussionSubscription: { // field return type name
createdAt: 'DateTime'
Expand Down Expand Up @@ -1010,6 +1038,7 @@ export interface NexusGenFieldTypeNames {
common: 'Common'
commons: 'Common'
discussion: 'Discussion'
discussions: 'Discussion'
events: 'Event'
generateUserAuthToken: 'String'
getStatistics: 'Statistic'
Expand Down Expand Up @@ -1219,6 +1248,10 @@ export interface NexusGenArgTypes {
discussion: { // args
id: string; // ID!
}
discussions: { // args
paginate?: NexusGenInputs['PaginateInput'] | null; // PaginateInput
where?: NexusGenInputs['DiscussionWhereInput'] | null; // DiscussionWhereInput
}
events: { // args
paginate?: NexusGenInputs['PaginateInput'] | null; // PaginateInput
}
Expand Down
22 changes: 22 additions & 0 deletions packages/graphql/src/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Common {
"""The main identifier of the item"""
id: ID!
image: String!
links: JSON
members(orderBy: CommonMemberOrderByInput, skip: Int, take: Int): [CommonMember]!

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

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

input CommonLinkInput {
title: String!
url: String!
}

type CommonMember implements BaseEntity {
common: Common
commonId: ID!
Expand Down Expand Up @@ -150,7 +157,9 @@ input CreateCommonInput {
fundingMinimumAmount: Int!
fundingType: FundingType!
image: String!
links: [CommonLinkInput!]
name: String!
rules: [CommonLinkInput!]
}

input CreateDiscussionInput {
Expand Down Expand Up @@ -248,12 +257,16 @@ type Discussion implements BaseEntity {
latestMessage: DateTime!
messages(orderBy: DiscussionMessagesOrderByInput = {createdAt: asc}, skip: Int = 0, take: Int = 10): [DiscussionMessage!]!

"""The discussion creator"""
owner: User

"""What this discussion is about"""
topic: String!
type: DiscussionType!

"""The date, at which the item was last modified"""
updatedAt: DateTime!
userId: String!
}

type DiscussionMessage implements BaseEntity {
Expand All @@ -264,11 +277,13 @@ type DiscussionMessage implements BaseEntity {
"""The main identifier of the item"""
id: UUID!
message: String!
owner: User!
reports: [Report!]!
type: DiscussionMessageType!

"""The date, at which the item was last modified"""
updatedAt: DateTime!
userId: String!
}

enum DiscussionMessageFlag {
Expand Down Expand Up @@ -317,6 +332,12 @@ enum DiscussionType {
ProposalDiscussion
}

input DiscussionWhereInput {
commonId: UUID
commonMemberId: UUID
userId: ID
}

type Event {
"""The ID of the common, for whom the event was created"""
commonId: ID
Expand Down Expand Up @@ -721,6 +742,7 @@ type Query {
common(where: CommonWhereUniqueInput!): Common
commons(paginate: PaginateInput): [Common]
discussion(id: ID!): Discussion
discussions(paginate: PaginateInput, where: DiscussionWhereInput): [Discussion]
events(paginate: PaginateInput): [Event]
generateUserAuthToken(authId: String!): String!
getStatistics(where: StatisticsWhereInput): [Statistic]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const CreateCommonInput = inputObjectType({
t.string('action');
t.string('byline');
t.string('description');
t.list.nonNull.field('links', {
type: 'CommonLinkInput'
});
t.list.nonNull.field('rules', {
type: 'CommonLinkInput'
});
}
});

Expand Down
3 changes: 3 additions & 0 deletions packages/graphql/src/schema/Types/Common/Types/Common.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const CommonType = objectType({
description: 'The total amount of money that the common has raised. In cents'
});

t.json('links');
t.json('rules');

t.nonNull.string('image');
t.string('description');
t.string('action');
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql/src/schema/Types/Common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { CommonActiveProposalsExtension } from './Extensions/CommonActiveProposa

import { CommonType } from './Types/Common.type';
import { CommonWhereUniqueInput } from './Inputs/CommonWhereUnique.input';
import { CommonLinkInput } from './Inputs/CommonLink.input';


export const CommonTypes = [
CommonType,
Expand All @@ -31,6 +33,7 @@ export const CommonTypes = [
WhitelistCommonMutation,

CommonWhereUniqueInput,
CommonLinkInput,

CommonEventsExtension,
CommonReportsExtension,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { inputObjectType } from 'nexus';

export const CommonLinkInput = inputObjectType({
name: 'CommonLinkInput',
definition(t) {
t.nonNull.string('title');
t.nonNull.string('url');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { extendType } from 'nexus';
import { prisma } from '@common/core';

export const DiscussionMessageOwnerExtension = extendType({
type: 'DiscussionMessage',
definition(t) {
t.nonNull.field('owner', {
type: 'User',
resolve: (root) => {
return prisma.user.findUnique({
where: {
id: root.userId
}
});
}
});
}
});
Loading