Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log pitches #145

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions src/activities/dtos/create-activity-route-pitch.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { InputType, Field, Int } from '@nestjs/graphql';
import { AscentType, PublishType } from '../entities/activity-route.entity';

@InputType()
export class CreateActivityRoutePitchInput {
@Field()
pitchId: string;

@Field(() => Int)
position: number;

@Field()
ascentType: AscentType;

@Field()
publish: PublishType;
}
9 changes: 7 additions & 2 deletions src/activities/dtos/create-activity-route.input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InputType, Field, Int, Float } from '@nestjs/graphql';
import { IsOptional } from 'class-validator';
import { AscentType, PublishType } from '../entities/activity-route.entity';
import { CreateActivityRoutePitchInput } from './create-activity-route-pitch.input';

@InputType()
export class CreateActivityRouteInput {
Expand Down Expand Up @@ -28,11 +29,15 @@ export class CreateActivityRouteInput {
@IsOptional()
position: number;

@Field(type => Float, { nullable: true })
@Field((type) => Float, { nullable: true })
@IsOptional()
votedDifficulty: number;

@Field(type => Int, { nullable: true })
@Field((type) => Int, { nullable: true })
@IsOptional()
votedStarRating: number;

@Field(() => [CreateActivityRoutePitchInput], { nullable: true })
@IsOptional()
pitches: CreateActivityRoutePitchInput[];
}
11 changes: 5 additions & 6 deletions src/activities/entities/activity-route.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ export class ActivityRoute extends BaseEntity {
legacy: string;

// TODO: if we decided that every activity route belongs to an activity, this can become non nullable
@ManyToOne(
() => Activity,
activity => activity.routes,
{ nullable: true },
)
@ManyToOne(() => Activity, (activity) => activity.routes, { nullable: true })
@Field(() => Activity, { nullable: true })
activity: Promise<Activity>;
@Column({ nullable: true })
Expand All @@ -107,8 +103,11 @@ export class ActivityRoute extends BaseEntity {
routeId: string;

@ManyToOne(() => Pitch, { nullable: true })
@Field(type => Pitch, { nullable: true })
@Field((type) => Pitch, { nullable: true })
pitch: Promise<Route>;
@Column({ nullable: true })
@Field({ nullable: true })
pitchId: string;

@Column({
type: 'enum',
Expand Down
20 changes: 20 additions & 0 deletions src/activities/services/activity-routes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { RoutesTouches } from '../utils/routes-touches.class';
import { FindRoutesTouchesInput } from '../dtos/find-routes-touches.input';
import { SideEffect } from '../utils/side-effect.class';
import { setBuilderCache } from '../../core/utils/entity-cache/entity-cache-helpers';
import { CreateActivityRoutePitchInput } from '../dtos/create-activity-route-pitch.input';

@Injectable()
export class ActivityRoutesService {
Expand Down Expand Up @@ -197,9 +198,28 @@ export class ActivityRoutesService {
activityRoute.activity = Promise.resolve(activity);
}

for (const pitch of routeIn.pitches ?? []) {
await this.savePitch(queryRunner, activityRoute, pitch);
}

return queryRunner.manager.save(activityRoute);
}

private async savePitch(
queryRunner: QueryRunner,
activityRoute: ActivityRoute,
pitch: CreateActivityRoutePitchInput,
) {
const activityRoutePitch = new ActivityRoute();
queryRunner.manager.merge(ActivityRoute, activityRoutePitch, activityRoute);

activityRoutePitch.pitchId = pitch.pitchId;
activityRoutePitch.ascentType = pitch.ascentType;
activityRoutePitch.publish = pitch.publish;

return queryRunner.manager.save(activityRoutePitch);
}

private isTick(ascentType: AscentType) {
return tickAscentTypes.has(ascentType);
}
Expand Down