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

Master #178

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
ls ${{ github.workspace }}
- name: Install and prepare
run: |
docker-compose -f docker-compose.e2e.yml up -d
docker compose -f docker-compose.e2e.yml up -d
npm install
- name: Run tests
run: |
Expand Down
82 changes: 44 additions & 38 deletions src/activities/entities/activity-route.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,68 @@ import {
ManyToOne,
Index,
} from 'typeorm';
import { ObjectType, Field } from '@nestjs/graphql';
import { ObjectType, Field, registerEnumType } from '@nestjs/graphql';
import { Route } from '../../crags/entities/route.entity';
import { Activity } from './activity.entity';
import { Pitch } from '../../crags/entities/pitch.entity';
import { User } from '../../users/entities/user.entity';

export enum AscentType {
ONSIGHT = 'onsight',
FLASH = 'flash',
REDPOINT = 'redpoint',
REPEAT = 'repeat',
ALLFREE = 'allfree',
AID = 'aid',
ATTEMPT = 'attempt',
T_ONSIGHT = 't_onsight',
T_FLASH = 't_flash',
T_REDPOINT = 't_redpoint',
T_REPEAT = 't_repeat',
T_ALLFREE = 't_allfree',
T_AID = 't_aid',
T_ATTEMPT = 't_attempt',
TICK = 'tick',
onsight = 'onsight',
flash = 'flash',
redpoint = 'redpoint',
repeat = 'repeat',
allfree = 'allfree',
aid = 'aid',
attempt = 'attempt',
t_onsight = 't_onsight',
t_flash = 't_flash',
t_redpoint = 't_redpoint',
t_repeat = 't_repeat',
t_allfree = 't_allfree',
t_aid = 't_aid',
t_attempt = 't_attempt',
tick = 'tick',
}
registerEnumType(AscentType, {
name: 'AscentType',
});

export const tickAscentTypes = new Set([
AscentType.ONSIGHT,
AscentType.FLASH,
AscentType.REDPOINT,
AscentType.REPEAT,
AscentType.onsight,
AscentType.flash,
AscentType.redpoint,
AscentType.repeat,
]);

export const firstTickAscentTypes = new Set([
AscentType.ONSIGHT,
AscentType.FLASH,
AscentType.REDPOINT,
AscentType.onsight,
AscentType.flash,
AscentType.redpoint,
]);

export const trTickAscentTypes = new Set([
AscentType.T_ONSIGHT,
AscentType.T_FLASH,
AscentType.T_REDPOINT,
AscentType.T_REPEAT,
AscentType.t_onsight,
AscentType.t_flash,
AscentType.t_redpoint,
AscentType.t_repeat,
]);

export const firstTrTickAscentTypes = new Set([
AscentType.T_ONSIGHT,
AscentType.T_FLASH,
AscentType.T_REDPOINT,
AscentType.t_onsight,
AscentType.t_flash,
AscentType.t_redpoint,
]);

export enum PublishType {
PUBLIC = 'public',
CLUB = 'club',
LOG = 'log',
PRIVATE = 'private',
public = 'public',
club = 'club',
log = 'log',
private = 'private',
}
registerEnumType(PublishType, {
name: 'PublishType',
});

/**
* Has Triggers:
Expand Down Expand Up @@ -109,17 +115,17 @@ export class ActivityRoute extends BaseEntity {
@Column({
type: 'enum',
enum: AscentType,
default: AscentType.REDPOINT,
default: AscentType.redpoint,
})
@Field()
@Field((type) => AscentType)
ascentType: AscentType;

@Column({
type: 'enum',
enum: PublishType,
default: PublishType.PRIVATE,
default: PublishType.private,
})
@Field()
@Field((type) => PublishType)
publish: PublishType;

@Column({ nullable: true })
Expand Down
1 change: 0 additions & 1 deletion src/activities/resolvers/activity-routes.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export class ActivityRoutesResolver {
return this.activityRoutesService.getStats(input, currentUser);
}


@UseGuards(UserAuthGuard)
@Query(() => [ActivityRoute])
myCragSummary(
Expand Down
4 changes: 1 addition & 3 deletions src/activities/services/activities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ export class ActivitiesService {
params: FindActivitiesInput = {},
currentUser: User = null,
): Promise<StatsActivities[]> {

const builder = this.activitiesRepository
.createQueryBuilder('ac')
.select('EXTRACT(YEAR FROM ac.date)', 'year')
Expand Down Expand Up @@ -247,7 +246,6 @@ export class ActivitiesService {
} as StatsActivities;
});
return myStats;

}

async find(params: FindActivitiesInput = {}): Promise<Activity[]> {
Expand Down Expand Up @@ -326,7 +324,7 @@ export class ActivitiesService {
ActivityRoute,
'ar',
'ar.activity_id = a.id AND (ar."publish" IN (:...publish))',
{ publish: ['log', 'public'] },
{ publish: ['public'] },
);

// Allow/disallow based on publishStatus of contained activity routes
Expand Down
26 changes: 13 additions & 13 deletions src/activities/services/activity-routes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,46 +247,46 @@ export class ActivityRoutesService {
// boulders cannot be onsighted at all
if (routeTypeId === 'boulder') {
if (
ascentType === AscentType.ONSIGHT ||
ascentType === AscentType.T_ONSIGHT
ascentType === AscentType.onsight ||
ascentType === AscentType.t_onsight
)
return false;
}

// already tried routes cannot be onsighted or flashed
if (routeTried) {
if (
ascentType === AscentType.ONSIGHT ||
ascentType === AscentType.T_ONSIGHT ||
ascentType === AscentType.FLASH ||
ascentType === AscentType.T_FLASH
ascentType === AscentType.onsight ||
ascentType === AscentType.t_onsight ||
ascentType === AscentType.flash ||
ascentType === AscentType.t_flash
)
return false;
}

// already ticked routes cannot be redpointed (flash, sight included above)
if (routeTicked) {
if (
ascentType === AscentType.REDPOINT ||
ascentType === AscentType.T_REDPOINT
ascentType === AscentType.redpoint ||
ascentType === AscentType.t_redpoint
)
return false;
}

// routes one already 'ticked' on toprope cannot be tr redpointed
if (routeTrTicked) {
if (ascentType === AscentType.T_REDPOINT) {
if (ascentType === AscentType.t_redpoint) {
return false;
}
}

// routes not ticked before cannot be repeated
if (ascentType === AscentType.REPEAT && !routeTicked) {
if (ascentType === AscentType.repeat && !routeTicked) {
return false;
}

// routes not ticked (real or tr) before cannot be toprope repeated
if (ascentType === AscentType.T_REPEAT && !(routeTicked || routeTrTicked)) {
if (ascentType === AscentType.t_repeat && !(routeTicked || routeTrTicked)) {
return false;
}

Expand Down Expand Up @@ -646,7 +646,7 @@ export class ActivityRoutesService {
if (!currentUser) {
// Allow showing only public ascents to guests
builder.andWhere('ar."publish" IN (:...publish)', {
publish: ['log', 'public'],
publish: ['public'],
});

// Allow showing only published routes (no drafts or in_reviews)
Expand All @@ -657,7 +657,7 @@ export class ActivityRoutesService {
'(ar.user_id = :userId OR ar."publish" IN (:...publish))',
{
userId: currentUser.id,
publish: ['log', 'public'],
publish: ['public'],
},
);
// TODO: should also allow showing club ascents
Expand Down
8 changes: 8 additions & 0 deletions src/crags/crags.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ import { RouteEvent } from './entities/route-event.entity';
import { Parking } from './entities/parking.entity';
import { ParkingsService } from './services/parkings.service';
import { AreaLoader } from './loaders/area.loader';
import { ActivityRoutesService } from '../activities/services/activity-routes.service';
import { ActivitiesModule } from '../activities/activities.module';
import { ClubMember } from '../users/entities/club-member.entity';
import { Club } from '../users/entities/club.entity';
import { env } from 'process';

@Module({
Expand Down Expand Up @@ -99,7 +103,10 @@ import { env } from 'process';
IceFallProperty,
StarRatingVote,
Parking,
Club,
ClubMember,
]),
forwardRef(() => ActivitiesModule),
forwardRef(() => AuditModule),
BullModule.registerQueue({
name: 'summary',
Expand Down Expand Up @@ -150,6 +157,7 @@ import { env } from 'process';
CragLoader,
RouteLoader,
ParkingsService,
ActivityRoutesService,
],
controllers: [UploadController],
exports: [
Expand Down
9 changes: 9 additions & 0 deletions src/crags/dtos/find-difficulty-votes.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { InputType, Field } from '@nestjs/graphql';
import { IsOptional } from 'class-validator';

@InputType()
export class FindDifficultyVotesInput {
@Field({ nullable: true })
@IsOptional()
userId?: string;
}
9 changes: 9 additions & 0 deletions src/crags/dtos/find-star-rating-votes.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { InputType, Field } from '@nestjs/graphql';
import { IsOptional } from 'class-validator';

@InputType()
export class FindStarRatingVotesInput {
@Field({ nullable: true })
@IsOptional()
userId?: string;
}
32 changes: 16 additions & 16 deletions src/crags/entities/crag.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ export enum CragType {
}

export enum Orientation {
NORTH = 'north',
NORTHEAST = 'northeast',
EAST = 'east',
SOUTHEAST = 'southeast',
SOUTH = 'south',
SOUTHWEST = 'southwest',
WEST = 'west',
NORTHWEST = 'northwest',
north = 'north',
northeast = 'northeast',
east = 'east',
southeast = 'southeast',
south = 'south',
southwest = 'southwest',
west = 'west',
northwest = 'northwest',
}
registerEnumType(Orientation, {
name: 'Orientation',
});

export enum WallAngle {
SLAB = 'slab',
VERTICAL = 'vertical',
OVERHANG = 'overhang',
ROOF = 'roof',
slab = 'slab',
vertical = 'vertical',
overhang = 'overhang',
roof = 'roof',
}
registerEnumType(WallAngle, {
name: 'WallAngle',
});

export enum Season {
SPRING = 'spring',
SUMMER = 'summer',
AUTUMN = 'autumn',
WINTER = 'winter',
spring = 'spring',
summer = 'summer',
autumn = 'autumn',
winter = 'winter',
}
registerEnumType(Season, {
name: 'Season',
Expand Down
Loading
Loading