refactor: removing unused import, commented codes, improved cursor query (#69)
* chore: refactor code in some modules * refactor: getTeamsOfUser functino * chore: remove unused import * chore: revert some changes
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ObjectType, ID, Field, ResolveField } from '@nestjs/graphql';
|
import { ObjectType } from '@nestjs/graphql';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Admin {}
|
export class Admin {}
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ export class AdminResolver {
|
|||||||
private adminService: AdminService,
|
private adminService: AdminService,
|
||||||
private readonly pubsub: PubSubService,
|
private readonly pubsub: PubSubService,
|
||||||
) {}
|
) {}
|
||||||
// Query
|
|
||||||
|
/* Query */
|
||||||
|
|
||||||
@Query(() => Admin, {
|
@Query(() => Admin, {
|
||||||
description: 'Gives details of the admin executing this query',
|
description: 'Gives details of the admin executing this query',
|
||||||
})
|
})
|
||||||
@@ -229,7 +231,8 @@ export class AdminResolver {
|
|||||||
return this.adminService.getTeamRequestsCount();
|
return this.adminService.getTeamRequestsCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mutations
|
/* Mutations */
|
||||||
|
|
||||||
@Mutation(() => InvitedUser, {
|
@Mutation(() => InvitedUser, {
|
||||||
description: 'Invite a user to the infra using email',
|
description: 'Invite a user to the infra using email',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export class ChangeUserRoleInTeamArgs {
|
|||||||
})
|
})
|
||||||
newRole: TeamMemberRole;
|
newRole: TeamMemberRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgsType()
|
@ArgsType()
|
||||||
export class AddUserToTeamArgs {
|
export class AddUserToTeamArgs {
|
||||||
@Field(() => ID, {
|
@Field(() => ID, {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import * as TO from 'fp-ts/TaskOption';
|
|||||||
import * as E from 'fp-ts/Either';
|
import * as E from 'fp-ts/Either';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import {
|
import {
|
||||||
SHORTCODE_ALREADY_EXISTS,
|
|
||||||
SHORTCODE_INVALID_JSON,
|
SHORTCODE_INVALID_JSON,
|
||||||
SHORTCODE_NOT_FOUND,
|
SHORTCODE_NOT_FOUND,
|
||||||
} from 'src/errors';
|
} from 'src/errors';
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||||
import { User } from '../../user/user.model';
|
|
||||||
import { TeamCollectionService } from '../team-collection.service';
|
import { TeamCollectionService } from '../team-collection.service';
|
||||||
import { TeamService } from '../../team/team.service';
|
import { TeamService } from '../../team/team.service';
|
||||||
import { TeamMemberRole } from '../../team/team.model';
|
import { TeamMemberRole } from '../../team/team.model';
|
||||||
|
|||||||
@@ -415,48 +415,4 @@ export class TeamCollectionResolver {
|
|||||||
) {
|
) {
|
||||||
return this.pubsub.asyncIterator(`team_coll/${teamID}/coll_order_updated`);
|
return this.pubsub.asyncIterator(`team_coll/${teamID}/coll_order_updated`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Mutation(() => TeamCollection, {
|
|
||||||
// description: 'Import collection from user firestore',
|
|
||||||
// })
|
|
||||||
// @UseGuards(GqlAuthGuard, GqlTeamMemberGuard)
|
|
||||||
// @RequiresTeamRole(TeamMemberRole.OWNER, TeamMemberRole.EDITOR)
|
|
||||||
// importCollectionFromUserFirestore(
|
|
||||||
// @Args({
|
|
||||||
// name: 'teamID',
|
|
||||||
// type: () => ID,
|
|
||||||
// description: 'ID of the team to add to',
|
|
||||||
// })
|
|
||||||
// teamID: string,
|
|
||||||
// @Args({
|
|
||||||
// name: 'fbCollectionPath',
|
|
||||||
// description:
|
|
||||||
// 'slash separated array indicies path to the target collection',
|
|
||||||
// })
|
|
||||||
// fbCollectionPath: string,
|
|
||||||
// @GqlUser() user: User,
|
|
||||||
// @Args({
|
|
||||||
// name: 'parentCollectionID',
|
|
||||||
// type: () => ID,
|
|
||||||
// description:
|
|
||||||
// 'ID to the collection which is going to be parent to the result (null if root)',
|
|
||||||
// nullable: true,
|
|
||||||
// })
|
|
||||||
// parentCollectionID?: string
|
|
||||||
// ): Promise<TeamCollection> {
|
|
||||||
// if (parentCollectionID) {
|
|
||||||
// return this.teamCollectionService.importCollectionFromFirestore(
|
|
||||||
// user.uid,
|
|
||||||
// fbCollectionPath,
|
|
||||||
// teamID,
|
|
||||||
// parentCollectionID,
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// return this.teamCollectionService.importCollectionFromFirestore(
|
|
||||||
// user.uid,
|
|
||||||
// fbCollectionPath,
|
|
||||||
// teamID,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { Team } from '../team/team.model';
|
|
||||||
import { TeamCollection } from './team-collection.model';
|
import { TeamCollection } from './team-collection.model';
|
||||||
// import { FirebaseService } from '../firebase/firebase.service';
|
|
||||||
import {
|
import {
|
||||||
TEAM_COLL_SHORT_TITLE,
|
TEAM_COLL_SHORT_TITLE,
|
||||||
TEAM_COLL_INVALID_JSON,
|
TEAM_COLL_INVALID_JSON,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
getAnnotatedRequiredRoles,
|
getAnnotatedRequiredRoles,
|
||||||
getGqlArg,
|
getGqlArg,
|
||||||
getUserFromGQLContext,
|
getUserFromGQLContext,
|
||||||
namedTrace,
|
|
||||||
throwErr,
|
throwErr,
|
||||||
} from 'src/utils';
|
} from 'src/utils';
|
||||||
import { TeamEnvironmentsService } from './team-environments.service';
|
import { TeamEnvironmentsService } from './team-environments.service';
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import * as T from 'fp-ts/Task';
|
|||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
import * as TO from 'fp-ts/TaskOption';
|
import * as TO from 'fp-ts/TaskOption';
|
||||||
import * as TE from 'fp-ts/TaskEither';
|
import * as TE from 'fp-ts/TaskEither';
|
||||||
import * as E from 'fp-ts/Either';
|
|
||||||
import { pipe, flow, constVoid } from 'fp-ts/function';
|
import { pipe, flow, constVoid } from 'fp-ts/function';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import { Team, TeamMemberRole } from 'src/team/team.model';
|
import { Team, TeamMemberRole } from 'src/team/team.model';
|
||||||
@@ -11,7 +10,6 @@ import { Email } from 'src/types/Email';
|
|||||||
import { User } from 'src/user/user.model';
|
import { User } from 'src/user/user.model';
|
||||||
import { TeamService } from 'src/team/team.service';
|
import { TeamService } from 'src/team/team.service';
|
||||||
import {
|
import {
|
||||||
TEAM_INVITATION_NOT_FOUND,
|
|
||||||
TEAM_INVITE_ALREADY_MEMBER,
|
TEAM_INVITE_ALREADY_MEMBER,
|
||||||
TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
TEAM_INVITE_EMAIL_DO_NOT_MATCH,
|
||||||
TEAM_INVITE_MEMBER_HAS_INVITE,
|
TEAM_INVITE_MEMBER_HAS_INVITE,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Reflector } from '@nestjs/core';
|
|||||||
import { TeamService } from '../team.service';
|
import { TeamService } from '../team.service';
|
||||||
import { TeamMemberRole } from '../team.model';
|
import { TeamMemberRole } from '../team.model';
|
||||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||||
import { User } from '../../user/user.model';
|
|
||||||
import {
|
import {
|
||||||
TEAM_NOT_REQUIRED_ROLE,
|
TEAM_NOT_REQUIRED_ROLE,
|
||||||
BUG_AUTH_NO_USER_CTX,
|
BUG_AUTH_NO_USER_CTX,
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
TEAM_INVALID_ID_OR_USER,
|
TEAM_INVALID_ID_OR_USER,
|
||||||
TEAM_MEMBER_NOT_FOUND,
|
TEAM_MEMBER_NOT_FOUND,
|
||||||
USER_IS_OWNER,
|
USER_IS_OWNER,
|
||||||
TEAMS_NOT_FOUND,
|
|
||||||
} from '../errors';
|
} from '../errors';
|
||||||
import { PubSubService } from '../pubsub/pubsub.service';
|
import { PubSubService } from '../pubsub/pubsub.service';
|
||||||
import { flow, pipe } from 'fp-ts/function';
|
import { flow, pipe } from 'fp-ts/function';
|
||||||
@@ -294,7 +293,6 @@ export class TeamService implements UserDataHandler, OnModuleInit {
|
|||||||
team: true,
|
team: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return entries.map((entry) => entry.team);
|
return entries.map((entry) => entry.team);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ export class UserCollectionService {
|
|||||||
private readonly pubsub: PubSubService,
|
private readonly pubsub: PubSubService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
TITLE_LENGTH = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Typecast a database UserCollection to a UserCollection model
|
* Typecast a database UserCollection to a UserCollection model
|
||||||
* @param userCollection database UserCollection
|
* @param userCollection database UserCollection
|
||||||
@@ -212,7 +214,7 @@ export class UserCollectionService {
|
|||||||
parentUserCollectionID: string | null,
|
parentUserCollectionID: string | null,
|
||||||
type: ReqType,
|
type: ReqType,
|
||||||
) {
|
) {
|
||||||
const isTitleValid = isValidLength(title, 3);
|
const isTitleValid = isValidLength(title, this.TITLE_LENGTH);
|
||||||
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
|
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
|
||||||
|
|
||||||
// If creating a child collection
|
// If creating a child collection
|
||||||
@@ -330,7 +332,7 @@ export class UserCollectionService {
|
|||||||
userCollectionID: string,
|
userCollectionID: string,
|
||||||
userID: string,
|
userID: string,
|
||||||
) {
|
) {
|
||||||
const isTitleValid = isValidLength(newTitle, 3);
|
const isTitleValid = isValidLength(newTitle, this.TITLE_LENGTH);
|
||||||
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
|
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
|
||||||
|
|
||||||
// Check to see is the collection belongs to the user
|
// Check to see is the collection belongs to the user
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { PubSubService } from 'src/pubsub/pubsub.service';
|
|||||||
import { UserSettingsService } from './user-settings.service';
|
import { UserSettingsService } from './user-settings.service';
|
||||||
import { JSON_INVALID, USER_SETTINGS_NULL_SETTINGS } from 'src/errors';
|
import { JSON_INVALID, USER_SETTINGS_NULL_SETTINGS } from 'src/errors';
|
||||||
import { UserSettings } from './user-settings.model';
|
import { UserSettings } from './user-settings.model';
|
||||||
import { User } from 'src/user/user.model';
|
|
||||||
import { AuthUser } from 'src/types/AuthUser';
|
import { AuthUser } from 'src/types/AuthUser';
|
||||||
|
|
||||||
const mockPrisma = mockDeep<PrismaService>();
|
const mockPrisma = mockDeep<PrismaService>();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { PubSubService } from 'src/pubsub/pubsub.service';
|
|||||||
import { User } from 'src/user/user.model';
|
import { User } from 'src/user/user.model';
|
||||||
import * as E from 'fp-ts/Either';
|
import * as E from 'fp-ts/Either';
|
||||||
import { stringToJson } from 'src/utils';
|
import { stringToJson } from 'src/utils';
|
||||||
|
import { UserSettings as DbUserSettings } from '@prisma/client';
|
||||||
import { UserSettings } from './user-settings.model';
|
import { UserSettings } from './user-settings.model';
|
||||||
import {
|
import {
|
||||||
USER_SETTINGS_ALREADY_EXISTS,
|
USER_SETTINGS_ALREADY_EXISTS,
|
||||||
@@ -19,6 +20,13 @@ export class UserSettingsService {
|
|||||||
private readonly pubsub: PubSubService,
|
private readonly pubsub: PubSubService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
private castToUserSettings(userSettings: DbUserSettings): UserSettings {
|
||||||
|
return {
|
||||||
|
...userSettings,
|
||||||
|
properties: JSON.stringify(userSettings.properties),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch user settings for a given user
|
* Fetch user settings for a given user
|
||||||
* @param user User object
|
* @param user User object
|
||||||
@@ -30,10 +38,7 @@ export class UserSettingsService {
|
|||||||
where: { userUid: user.uid },
|
where: { userUid: user.uid },
|
||||||
});
|
});
|
||||||
|
|
||||||
const settings: UserSettings = {
|
const settings = this.castToUserSettings(userSettings);
|
||||||
...userSettings,
|
|
||||||
properties: JSON.stringify(userSettings.properties),
|
|
||||||
};
|
|
||||||
|
|
||||||
return E.right(settings);
|
return E.right(settings);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -61,10 +66,7 @@ export class UserSettingsService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const settings: UserSettings = {
|
const settings = this.castToUserSettings(userSettings);
|
||||||
...userSettings,
|
|
||||||
properties: JSON.stringify(userSettings.properties),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Publish subscription for user settings creation
|
// Publish subscription for user settings creation
|
||||||
await this.pubsub.publish(`user_settings/${user.uid}/created`, settings);
|
await this.pubsub.publish(`user_settings/${user.uid}/created`, settings);
|
||||||
@@ -95,10 +97,7 @@ export class UserSettingsService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const settings: UserSettings = {
|
const settings = this.castToUserSettings(updatedUserSettings);
|
||||||
...updatedUserSettings,
|
|
||||||
properties: JSON.stringify(updatedUserSettings.properties),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Publish subscription for user settings update
|
// Publish subscription for user settings update
|
||||||
await this.pubsub.publish(`user_settings/${user.uid}/updated`, settings);
|
await this.pubsub.publish(`user_settings/${user.uid}/updated`, settings);
|
||||||
|
|||||||
Reference in New Issue
Block a user