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:
Mir Arif Hasan
2023-04-06 20:24:10 +06:00
committed by GitHub
parent ffc08227dd
commit 696cf8490b
14 changed files with 22 additions and 72 deletions

View File

@@ -1,4 +1,4 @@
import { ObjectType, ID, Field, ResolveField } from '@nestjs/graphql';
import { ObjectType } from '@nestjs/graphql';
@ObjectType()
export class Admin {}

View File

@@ -38,7 +38,9 @@ export class AdminResolver {
private adminService: AdminService,
private readonly pubsub: PubSubService,
) {}
// Query
/* Query */
@Query(() => Admin, {
description: 'Gives details of the admin executing this query',
})
@@ -229,7 +231,8 @@ export class AdminResolver {
return this.adminService.getTeamRequestsCount();
}
// Mutations
/* Mutations */
@Mutation(() => InvitedUser, {
description: 'Invite a user to the infra using email',
})

View File

@@ -20,6 +20,7 @@ export class ChangeUserRoleInTeamArgs {
})
newRole: TeamMemberRole;
}
@ArgsType()
export class AddUserToTeamArgs {
@Field(() => ID, {

View File

@@ -5,7 +5,6 @@ import * as TO from 'fp-ts/TaskOption';
import * as E from 'fp-ts/Either';
import { PrismaService } from 'src/prisma/prisma.service';
import {
SHORTCODE_ALREADY_EXISTS,
SHORTCODE_INVALID_JSON,
SHORTCODE_NOT_FOUND,
} from 'src/errors';

View File

@@ -1,7 +1,6 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { GqlExecutionContext } from '@nestjs/graphql';
import { User } from '../../user/user.model';
import { TeamCollectionService } from '../team-collection.service';
import { TeamService } from '../../team/team.service';
import { TeamMemberRole } from '../../team/team.model';

View File

@@ -415,48 +415,4 @@ export class TeamCollectionResolver {
) {
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,
// );
// }
// }
}

View File

@@ -1,8 +1,6 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { Team } from '../team/team.model';
import { TeamCollection } from './team-collection.model';
// import { FirebaseService } from '../firebase/firebase.service';
import {
TEAM_COLL_SHORT_TITLE,
TEAM_COLL_INVALID_JSON,

View File

@@ -8,7 +8,6 @@ import {
getAnnotatedRequiredRoles,
getGqlArg,
getUserFromGQLContext,
namedTrace,
throwErr,
} from 'src/utils';
import { TeamEnvironmentsService } from './team-environments.service';

View File

@@ -3,7 +3,6 @@ import * as T from 'fp-ts/Task';
import * as O from 'fp-ts/Option';
import * as TO from 'fp-ts/TaskOption';
import * as TE from 'fp-ts/TaskEither';
import * as E from 'fp-ts/Either';
import { pipe, flow, constVoid } from 'fp-ts/function';
import { PrismaService } from 'src/prisma/prisma.service';
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 { TeamService } from 'src/team/team.service';
import {
TEAM_INVITATION_NOT_FOUND,
TEAM_INVITE_ALREADY_MEMBER,
TEAM_INVITE_EMAIL_DO_NOT_MATCH,
TEAM_INVITE_MEMBER_HAS_INVITE,

View File

@@ -3,7 +3,6 @@ import { Reflector } from '@nestjs/core';
import { TeamService } from '../team.service';
import { TeamMemberRole } from '../team.model';
import { GqlExecutionContext } from '@nestjs/graphql';
import { User } from '../../user/user.model';
import {
TEAM_NOT_REQUIRED_ROLE,
BUG_AUTH_NO_USER_CTX,

View File

@@ -12,7 +12,6 @@ import {
TEAM_INVALID_ID_OR_USER,
TEAM_MEMBER_NOT_FOUND,
USER_IS_OWNER,
TEAMS_NOT_FOUND,
} from '../errors';
import { PubSubService } from '../pubsub/pubsub.service';
import { flow, pipe } from 'fp-ts/function';
@@ -294,7 +293,6 @@ export class TeamService implements UserDataHandler, OnModuleInit {
team: true,
},
});
return entries.map((entry) => entry.team);
}
}

View File

@@ -34,6 +34,8 @@ export class UserCollectionService {
private readonly pubsub: PubSubService,
) {}
TITLE_LENGTH = 3;
/**
* Typecast a database UserCollection to a UserCollection model
* @param userCollection database UserCollection
@@ -212,7 +214,7 @@ export class UserCollectionService {
parentUserCollectionID: string | null,
type: ReqType,
) {
const isTitleValid = isValidLength(title, 3);
const isTitleValid = isValidLength(title, this.TITLE_LENGTH);
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
// If creating a child collection
@@ -330,7 +332,7 @@ export class UserCollectionService {
userCollectionID: string,
userID: string,
) {
const isTitleValid = isValidLength(newTitle, 3);
const isTitleValid = isValidLength(newTitle, this.TITLE_LENGTH);
if (!isTitleValid) return E.left(USER_COLL_SHORT_TITLE);
// Check to see is the collection belongs to the user

View File

@@ -4,7 +4,6 @@ import { PubSubService } from 'src/pubsub/pubsub.service';
import { UserSettingsService } from './user-settings.service';
import { JSON_INVALID, USER_SETTINGS_NULL_SETTINGS } from 'src/errors';
import { UserSettings } from './user-settings.model';
import { User } from 'src/user/user.model';
import { AuthUser } from 'src/types/AuthUser';
const mockPrisma = mockDeep<PrismaService>();

View File

@@ -4,6 +4,7 @@ import { PubSubService } from 'src/pubsub/pubsub.service';
import { User } from 'src/user/user.model';
import * as E from 'fp-ts/Either';
import { stringToJson } from 'src/utils';
import { UserSettings as DbUserSettings } from '@prisma/client';
import { UserSettings } from './user-settings.model';
import {
USER_SETTINGS_ALREADY_EXISTS,
@@ -19,6 +20,13 @@ export class UserSettingsService {
private readonly pubsub: PubSubService,
) {}
private castToUserSettings(userSettings: DbUserSettings): UserSettings {
return {
...userSettings,
properties: JSON.stringify(userSettings.properties),
};
}
/**
* Fetch user settings for a given user
* @param user User object
@@ -30,10 +38,7 @@ export class UserSettingsService {
where: { userUid: user.uid },
});
const settings: UserSettings = {
...userSettings,
properties: JSON.stringify(userSettings.properties),
};
const settings = this.castToUserSettings(userSettings);
return E.right(settings);
} catch (e) {
@@ -61,10 +66,7 @@ export class UserSettingsService {
},
});
const settings: UserSettings = {
...userSettings,
properties: JSON.stringify(userSettings.properties),
};
const settings = this.castToUserSettings(userSettings);
// Publish subscription for user settings creation
await this.pubsub.publish(`user_settings/${user.uid}/created`, settings);
@@ -95,10 +97,7 @@ export class UserSettingsService {
},
});
const settings: UserSettings = {
...updatedUserSettings,
properties: JSON.stringify(updatedUserSettings.properties),
};
const settings = this.castToUserSettings(updatedUserSettings);
// Publish subscription for user settings update
await this.pubsub.publish(`user_settings/${user.uid}/updated`, settings);