diff --git a/graphql/resolvers/Team.ts b/graphql/resolvers/Team.ts
deleted file mode 100644
index 34cd23689..000000000
--- a/graphql/resolvers/Team.ts
+++ /dev/null
@@ -1,403 +0,0 @@
-import { PrismaClient } from '@prisma/client';
-import { arg, nonNull, stringArg } from 'nexus';
-import { ObjectDefinitionBlock } from 'nexus/dist/core';
-
-import { connectionMap } from '../queries/connections';
-import { addCalclulatedGoalsFields, goalDeepQuery, goalsFilter, calcGoalsMeta } from '../queries/goals';
-import {
- SortOrder,
- SubscriptionToggleInput,
- Activity,
- Team,
- TeamCreateInput,
- TeamUpdateInput,
- TeamsInput,
- TeamDeleteInput,
- Goal,
- TeamGoalsInput,
- GoalsMetaOutput,
- TransferOwnershipInput,
-} from '../types';
-
-const goalsQuery = async (
- db: PrismaClient,
- activityId: string,
- data: {
- id: string;
- query: string;
- priority: string[];
- states: string[];
- tags: string[];
- estimates: string[];
- owner: string[];
- projects: number[];
- },
-) => {
- const uniqGoals = new Map();
-
- const [teamGoals, teamProjectsGoals] = await Promise.all([
- db.goal.findMany({
- ...goalsFilter(data, {
- AND: {
- team: {
- id: data.id,
- },
- },
- }),
- include: {
- ...goalDeepQuery,
- },
- }),
- db.goal.findMany({
- ...goalsFilter(data, {
- AND: {
- project: {
- teams: {
- some: {
- id: data.id,
- },
- },
- },
- },
- }),
- include: {
- ...goalDeepQuery,
- },
- }),
- ]);
-
- teamGoals.forEach((goal) => uniqGoals.set(goal.id, goal));
- teamProjectsGoals.forEach((goal) => uniqGoals.set(goal.id, goal));
-
- return Array.from(uniqGoals.values()).map((goal) => ({
- ...goal,
- ...addCalclulatedGoalsFields(goal, activityId),
- }));
-};
-
-export const query = (t: ObjectDefinitionBlock<'Query'>) => {
- t.list.field('teams', {
- type: Team,
- args: {
- data: nonNull(arg({ type: TeamsInput })),
- },
- resolve: async (_, { data }, { db, activity }) => {
- if (!activity) return null;
-
- const teams = await db.team.findMany({
- where: {
- title: data.title ?? undefined,
- },
- orderBy: {
- createdAt: 'asc',
- },
- include: {
- projects: true,
- activity: {
- include: {
- user: true,
- ghost: true,
- },
- },
- },
- });
-
- if (!teams.length) return [];
-
- return teams;
- },
- });
-
- t.field('team', {
- type: Team,
- args: {
- id: nonNull(stringArg()),
- },
- resolve: async (_, { id }, { db, activity }) => {
- if (!activity) return null;
-
- return db.team.findUnique({
- where: {
- id,
- },
- include: {
- projects: {
- include: {
- activity: {
- include: {
- user: true,
- ghost: true,
- },
- },
- },
- },
- watchers: true,
- stargizers: true,
- participants: {
- include: {
- user: true,
- ghost: true,
- },
- },
- activity: {
- include: {
- user: true,
- ghost: true,
- },
- },
- _count: {
- select: {
- projects: true,
- },
- },
- },
- });
- },
- });
-
- t.list.field('teamGoals', {
- type: Goal,
- args: {
- data: nonNull(arg({ type: TeamGoalsInput })),
- },
- resolve: async (_, { data }, { db, activity }) => {
- if (!activity) return null;
-
- return goalsQuery(db, activity.id, data);
- },
- });
-
- t.field('teamGoalsMeta', {
- type: GoalsMetaOutput,
- args: {
- data: nonNull(arg({ type: TeamGoalsInput })),
- },
- resolve: async (_, { data }, { db, activity }) => {
- if (!activity) return null;
-
- const allTeamGoals = await goalsQuery(db, activity.id, data);
-
- return calcGoalsMeta(allTeamGoals);
- },
- });
-
- t.list.field('teamCompletion', {
- type: Team,
- args: {
- sortBy: arg({ type: SortOrder }),
- query: nonNull(stringArg()),
- },
- resolve: async (_, { sortBy, query }, { db }) => {
- if (query === '') {
- return [];
- }
-
- return db.team.findMany({
- orderBy: { createdAt: sortBy || undefined },
- where: {
- title: {
- contains: query,
- mode: 'insensitive',
- },
- },
- include: {
- flow: true,
- activity: {
- include: {
- user: true,
- },
- },
- },
- });
- },
- });
-};
-
-export const mutation = (t: ObjectDefinitionBlock<'Mutation'>) => {
- t.field('updateTeam', {
- type: Team,
- args: {
- data: nonNull(arg({ type: TeamUpdateInput })),
- },
- resolve: async (_, { data: { id, parent, children, projects, ...data } }, { db, activity }) => {
- if (!activity) return null;
-
- if (parent) {
- try {
- await db.team.update({
- where: {
- id: parent,
- },
- data: {
- children: {
- connect: [{ id }],
- },
- },
- });
- } catch (error) {
- throw Error(`${error}`);
- }
- }
-
- const team = await db.team.findUnique({
- where: { id },
- include: {
- projects: true,
- },
- });
-
- if (!team) return null;
-
- const projectsToConnect = projects.filter(
- (projectId) => !team.projects.some((project) => project.id === projectId),
- );
- const projectsToDisconnect = team.projects.filter((project) => !projects.includes(project.id));
-
- try {
- return db.team.update({
- where: { id },
- data: {
- ...data,
- children: {
- connect: children?.map((child) => ({ id: child })),
- },
- projects: {
- connect: projectsToConnect.map((id) => ({ id })),
- disconnect: projectsToDisconnect.map((project) => ({ id: project.id })),
- },
- },
- include: {
- projects: true,
- },
- });
-
- // await mailServer.sendMail({
- // from: `"Fred Foo 👻" <${process.env.MAIL_USER}>`,
- // to: 'bar@example.com, baz@example.com',
- // subject: 'Hello ✔',
- // text: `new post '${title}'`,
- // html: `new post ${title}`,
- // });
- } catch (error) {
- throw Error(`${error}`);
- }
- },
- });
-
- t.field('deleteTeam', {
- type: Team,
- args: {
- data: nonNull(arg({ type: TeamDeleteInput })),
- },
- resolve: async (_, { data: { id } }, { db, activity }) => {
- if (!activity) return null;
-
- try {
- return db.team.delete({
- where: { id },
- });
-
- // await mailServer.sendMail({
- // from: `"Fred Foo 👻" <${process.env.MAIL_USER}>`,
- // to: 'bar@example.com, baz@example.com',
- // subject: 'Hello ✔',
- // text: `new post '${title}'`,
- // html: `new post ${title}`,
- // });
- } catch (error) {
- throw Error(`${error}`);
- }
- },
- });
-
- t.field('toggleTeamWatcher', {
- type: Activity,
- args: {
- data: nonNull(arg({ type: SubscriptionToggleInput })),
- },
- resolve: async (_, { data: { id, direction } }, { db, activity }) => {
- if (!activity) return null;
-
- const connection = { id: Number(id) };
-
- try {
- return db.activity.update({
- where: { id: activity.id },
- data: {
- teamWatchers: { [connectionMap[String(direction)]]: connection },
- },
- });
-
- // await mailServer.sendMail({
- // from: `"Fred Foo 👻" <${process.env.MAIL_USER}>`,
- // to: 'bar@example.com, baz@example.com',
- // subject: 'Hello ✔',
- // text: `new post '${title}'`,
- // html: `new post ${title}`,
- // });
- } catch (error) {
- throw Error(`${error}`);
- }
- },
- });
-
- t.field('toggleTeamStargizer', {
- type: Activity,
- args: {
- data: nonNull(arg({ type: SubscriptionToggleInput })),
- },
- resolve: async (_, { data: { id, direction } }, { db, activity }) => {
- if (!activity) return null;
-
- const connection = { id: Number(id) };
-
- try {
- return db.activity.update({
- where: { id: activity.id },
- data: {
- teamStargizers: { [connectionMap[String(direction)]]: connection },
- },
- });
-
- // await mailServer.sendMail({
- // from: `"Fred Foo 👻" <${process.env.MAIL_USER}>`,
- // to: 'bar@example.com, baz@example.com',
- // subject: 'Hello ✔',
- // text: `new post '${title}'`,
- // html: `new post ${title}`,
- // });
- } catch (error) {
- throw Error(`${error}`);
- }
- },
- });
-
- t.field('transferTeamOwnership', {
- type: Team,
- args: {
- data: nonNull(arg({ type: TransferOwnershipInput })),
- },
- resolve: async (_, { data: { id, activityId } }, { db, activity }) => {
- if (!activity) return null;
-
- try {
- return db.team.update({
- where: { id },
- data: {
- activityId,
- },
- });
-
- // await mailServer.sendMail({
- // from: `"Fred Foo 👻" <${process.env.MAIL_USER}>`,
- // to: 'bar@example.com, baz@example.com',
- // subject: 'Hello ✔',
- // text: `new post '${title}'`,
- // html: `new post ${title}`,
- // });
- } catch (error) {
- throw Error(`${error}`);
- }
- },
- });
-};
diff --git a/graphql/schema.graphql b/graphql/schema.graphql
index 9a4824acc..cbd08df37 100644
--- a/graphql/schema.graphql
+++ b/graphql/schema.graphql
@@ -205,7 +205,6 @@ type Mutation {
createTag(description: String, title: String!): Tag
deleteComment(data: CommentDeleteInput!): Comment
deleteProject(data: ProjectDelete!): Project
- deleteTeam(data: TeamDelete!): Team
toggleGoalArchive(data: GoalArchiveInput!): Activity
toggleGoalDependency(toggle: GoalDependencyToggleInput!): Goal
toggleGoalStargizer(data: SubscriptionToggleInput!): Activity
@@ -213,15 +212,11 @@ type Mutation {
toggleProjectStargizer(data: SubscriptionToggleInput!): Activity
toggleProjectWatcher(data: SubscriptionToggleInput!): Activity
toggleReaction(data: ReactionToggleInput!): Reaction
- toggleTeamStargizer(data: SubscriptionToggleInput!): Activity
- toggleTeamWatcher(data: SubscriptionToggleInput!): Activity
transferProjectOwnership(data: TransferOwnershipInput!): Project
- transferTeamOwnership(data: TransferOwnershipInput!): Team
updateComment(data: CommentUpdateInput!): Comment
updateGoal(data: GoalUpdateInput!): Goal
updateProject(data: ProjectUpdateInput!): Project
updateSettings(data: SettingsUpdateInput!): Settings
- updateTeam(data: TeamUpdateInput!): Team
updateUser(data: UserUpdateInput!): User
usersInvites(input: UserInvitesInput!): [Ghost]
}
@@ -293,18 +288,13 @@ type Query {
goal(id: String!): Goal
goalComment(goalId: String!): [Comment]
goalDependencyKind: [String]
- project(id: String!): Project
+ project(id: String!, team: Boolean): Project
projectCompletion(query: String!, sortBy: SortOrder): [Project]
projectGoals(data: ProjectGoalsInput!): [Goal]
projectGoalsMeta(data: ProjectGoalsInput!): GoalsMetaOutput
- projects: [Project]
+ projects(team: Boolean): [Project]
settings: Settings
tagCompletion(query: String!, sortBy: SortOrder): [Tag]
- team(id: String!): Team
- teamCompletion(query: String!, sortBy: SortOrder): [Team]
- teamGoals(data: TeamGoalsInput!): [Goal]
- teamGoalsMeta(data: TeamGoalsInput!): GoalsMetaOutput
- teams(data: TeamsInput!): [Team]
userGoals(data: UserGoalsInput!): [Goal]
userGoalsMeta(data: UserGoalsInput!): GoalsMetaOutput
users(sortBy: SortOrder): [User]
diff --git a/graphql/schema.ts b/graphql/schema.ts
index a9a88292b..0fbbb6959 100644
--- a/graphql/schema.ts
+++ b/graphql/schema.ts
@@ -10,7 +10,6 @@ import * as Tag from './resolvers/Tag';
import * as Settings from './resolvers/Settings';
import * as Reaction from './resolvers/Reaction';
import * as Comment from './resolvers/Comment';
-import * as Team from './resolvers/Team';
const Query = queryType({
definition(t) {
@@ -22,7 +21,6 @@ const Query = queryType({
Settings.query(t);
Reaction.query(t);
Comment.query(t);
- Team.query(t);
},
});
@@ -36,7 +34,6 @@ const Mutation = mutationType({
Settings.mutation(t);
Reaction.mutation(t);
Comment.mutation(t);
- Team.mutation(t);
},
});