diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 692726f..a2eb6a4 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -49,7 +49,7 @@ jobs: - name: Build & Push Docker image uses: docker/build-push-action@v4 with: - context: /packages/server + context: ./packages/server push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/packages/server/src/collection/collection.model.ts b/packages/server/src/collection/collection.model.ts index 9ddc8dc..ebd1433 100644 --- a/packages/server/src/collection/collection.model.ts +++ b/packages/server/src/collection/collection.model.ts @@ -1,6 +1,8 @@ import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; import mongoose, { Document } from 'mongoose'; import { ObjectType, Field, ID, Directive } from '@nestjs/graphql'; +import { Participant } from '../participant/participant.model' +import { Shares } from '../share/share.model' @Schema() @ObjectType() @@ -52,10 +54,18 @@ export class Collection { @Prop( {type: mongoose.Schema.Types.Date} ) @Field(() => Date) lastOpenedAt: Date; - + @Prop() @Field({ nullable: true }) deletedAt: Date + + @Prop() + @Field(() => [Participant]) + participants: Participant[] + + @Prop() + @Field(() => [Shares]) + Shares: Shares[] } export type CollectionDocument = Collection & Document; diff --git a/packages/server/src/collection/collection.module.ts b/packages/server/src/collection/collection.module.ts index 7531aad..b8d2a8e 100644 --- a/packages/server/src/collection/collection.module.ts +++ b/packages/server/src/collection/collection.module.ts @@ -3,9 +3,14 @@ import { MongooseModule } from '@nestjs/mongoose'; import { Collection, CollectionSchema } from './collection.model' import { CollectionService } from './collection.service' import { CollectionResolver } from './collection.resolver'; +import { ParticipantModule } from '../participant/participant.module' +import { ShareModule } from '../share/share.module' @Module({ - imports: [MongooseModule.forFeature([{ name: Collection.name, schema: CollectionSchema}])], + imports: [ + ShareModule, + ParticipantModule, + MongooseModule.forFeature([{ name: Collection.name, schema: CollectionSchema}])], providers: [CollectionService, CollectionResolver], exports: [CollectionService] }) diff --git a/packages/server/src/collection/collection.resolver.ts b/packages/server/src/collection/collection.resolver.ts index 7d17e4a..e04724d 100644 --- a/packages/server/src/collection/collection.resolver.ts +++ b/packages/server/src/collection/collection.resolver.ts @@ -1,13 +1,21 @@ -import { Resolver, Query, Mutation, ResolveReference, Args } from '@nestjs/graphql'; +import { Resolver, Query, Mutation, ResolveReference, ResolveField, Parent, Args } from '@nestjs/graphql'; import { Collection } from './collection.model'; import { CollectionService } from './collection.service'; import { BadRequestException } from '@nestjs/common'; import { CollectionType } from './collection.type' import { PageInfoInput, PaginatedCollections} from './collection.pageinfo' +import { Participant } from '../participant/participant.model' +import { ParticipantService } from '../participant/participant.service' +import { Shares } from '../share/share.model' +import { ShareService } from '../share/share.service' @Resolver(()=> Collection) export class CollectionResolver { - constructor(private readonly collectionService: CollectionService) {} + constructor( + private readonly participantService: ParticipantService, + private readonly collectionService: CollectionService, + private readonly shareService:ShareService + ) {} @Query(() => PaginatedCollections) async getAllCollections(@Args('input') input: PageInfoInput): Promise { @@ -33,6 +41,16 @@ export class CollectionResolver { return this.collectionService.delete(id); } + @ResolveField(() => [Participant]) + async participants(@Parent() collection: Collection): Promise { + return this.participantService.findByCollectionId(collection._id.toString()); + } + + @ResolveField(() => [Shares]) + async shares(@Parent() collection: Collection): Promise { + return this.shareService.getCollectionShares(collection._id.toString()); + } + @ResolveReference() async resolveReference(reference: { __typename: string; diff --git a/packages/server/src/participant/participant.model.ts b/packages/server/src/participant/participant.model.ts index 39b92ba..7b57b49 100644 --- a/packages/server/src/participant/participant.model.ts +++ b/packages/server/src/participant/participant.model.ts @@ -1,6 +1,7 @@ import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; import mongoose, { Document } from 'mongoose'; import { ObjectType, Field, ID, Directive } from '@nestjs/graphql'; +import { Shares } from '../share/share.model' @Schema() @ObjectType() @@ -23,6 +24,10 @@ export class Participant { @Prop() @Field({ nullable: true }) deletedAt: Date + + @Prop() + @Field(() => [Shares]) + Shares: Shares[] } export type ParticipantDocument = Participant & Document; diff --git a/packages/server/src/participant/participant.module.ts b/packages/server/src/participant/participant.module.ts index 1369136..a7377cf 100644 --- a/packages/server/src/participant/participant.module.ts +++ b/packages/server/src/participant/participant.module.ts @@ -4,9 +4,11 @@ import { Participant, ParticipantSchema } from './participant.model'; import { ParticipantService } from './participant.service'; import { ParticipantResolver } from './participant.resolver'; import { ParticipantController } from './particpant.controller'; +import { ShareModule } from '../share/share.module' @Module({ imports: [ + ShareModule, MongooseModule.forFeature([ { name: Participant.name, schema: ParticipantSchema }, ]), diff --git a/packages/server/src/participant/participant.resolver.ts b/packages/server/src/participant/participant.resolver.ts index 9b77188..6100dd2 100644 --- a/packages/server/src/participant/participant.resolver.ts +++ b/packages/server/src/participant/participant.resolver.ts @@ -2,7 +2,9 @@ import { Resolver, Query, ResolveReference, - Mutation, + Mutation, + ResolveField, + Parent, Args, } from '@nestjs/graphql'; import { Participant } from './participant.model'; @@ -10,10 +12,15 @@ import { ParticipantService } from './participant.service'; import { BadRequestException } from '@nestjs/common'; import { ParticipantsArgs } from '../dto/participants.input'; import { CreateParticipantDto } from '../dto/participant.dto'; +import { Shares } from '../share/share.model' +import { ShareService } from '../share/share.service' @Resolver(() => Participant) export class ParticipantResolver { - constructor(private readonly participantService: ParticipantService) {} + constructor( + private readonly participantService: ParticipantService, + private readonly shareService:ShareService + ) {} @Query(() => [Participant]) async participants(@Args() args: ParticipantsArgs): Promise { @@ -50,6 +57,11 @@ export class ParticipantResolver { return this.participantService.delete(id); } + @ResolveField(() => [Shares]) + async shares(@Parent() participant: Participant): Promise { + return this.shareService.getParticipantShares(participant._id.toString()); + } + @ResolveReference() async resolveReference(reference: { __typename: string; diff --git a/packages/server/src/participant/participant.service.ts b/packages/server/src/participant/participant.service.ts index f28d339..0dc1864 100644 --- a/packages/server/src/participant/participant.service.ts +++ b/packages/server/src/participant/participant.service.ts @@ -46,6 +46,12 @@ export class ParticipantService { .exec(); } + findByCollectionId(id: string): Promise { + return this.participantModel + .find({ collectionId: id, deletedAt: null }) + .exec(); + } + async delete(id: string) { const participantToDelete = await this.participantModel .findOneAndUpdate(new mongoose.Types.ObjectId(id), {