feat: rename comment thread into activity (#939)
* feat: rename commentThread into activity server * feat: rename commentThread into activity front * feat: migration only create tables feat: migration only create tables * Update activities * fix: rebase partial fix * fix: all rebase problems and drop activity target alter * fix: lint * Update migration * Update migration * Fix conflicts * Fix conflicts --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -3,7 +3,8 @@ import { Injectable } from '@nestjs/common';
|
||||
import { PureAbility, AbilityBuilder } from '@casl/ability';
|
||||
import { createPrismaAbility, PrismaQuery, Subjects } from '@casl/prisma';
|
||||
import {
|
||||
CommentThread,
|
||||
Attachment,
|
||||
Activity,
|
||||
Company,
|
||||
Comment,
|
||||
Person,
|
||||
@ -11,11 +12,10 @@ import {
|
||||
User,
|
||||
Workspace,
|
||||
WorkspaceMember,
|
||||
CommentThreadTarget,
|
||||
ActivityTarget,
|
||||
Pipeline,
|
||||
PipelineStage,
|
||||
PipelineProgress,
|
||||
Attachment,
|
||||
UserSettings,
|
||||
ViewField,
|
||||
} from '@prisma/client';
|
||||
@ -29,9 +29,9 @@ type SubjectsAbility = Subjects<{
|
||||
Company: Company;
|
||||
Person: Person;
|
||||
RefreshToken: RefreshToken;
|
||||
CommentThread: CommentThread;
|
||||
Activity: Activity;
|
||||
Comment: Comment;
|
||||
CommentThreadTarget: CommentThreadTarget;
|
||||
ActivityTarget: ActivityTarget;
|
||||
Pipeline: Pipeline;
|
||||
PipelineStage: PipelineStage;
|
||||
PipelineProgress: PipelineProgress;
|
||||
@ -86,11 +86,11 @@ export class AbilityFactory {
|
||||
// RefreshToken
|
||||
cannot(AbilityAction.Manage, 'RefreshToken');
|
||||
|
||||
// CommentThread
|
||||
can(AbilityAction.Read, 'CommentThread', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'CommentThread');
|
||||
can(AbilityAction.Update, 'CommentThread', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Delete, 'CommentThread', { workspaceId: workspace.id });
|
||||
// Activity
|
||||
can(AbilityAction.Read, 'Activity', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'Activity');
|
||||
can(AbilityAction.Update, 'Activity', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Delete, 'Activity', { workspaceId: workspace.id });
|
||||
|
||||
// Comment
|
||||
can(AbilityAction.Read, 'Comment', { workspaceId: workspace.id });
|
||||
@ -104,9 +104,9 @@ export class AbilityFactory {
|
||||
authorId: user.id,
|
||||
});
|
||||
|
||||
// CommentThreadTarget
|
||||
can(AbilityAction.Read, 'CommentThreadTarget');
|
||||
can(AbilityAction.Create, 'CommentThreadTarget');
|
||||
// ActivityTarget
|
||||
can(AbilityAction.Read, 'ActivityTarget');
|
||||
can(AbilityAction.Create, 'ActivityTarget');
|
||||
|
||||
// Attachment
|
||||
can(AbilityAction.Read, 'Attachment', { workspaceId: workspace.id });
|
||||
|
||||
@ -46,12 +46,12 @@ import {
|
||||
DeleteRefreshTokenAbilityHandler,
|
||||
} from './handlers/refresh-token.ability-handler';
|
||||
import {
|
||||
ManageCommentThreadAbilityHandler,
|
||||
ReadCommentThreadAbilityHandler,
|
||||
CreateCommentThreadAbilityHandler,
|
||||
UpdateCommentThreadAbilityHandler,
|
||||
DeleteCommentThreadAbilityHandler,
|
||||
} from './handlers/comment-thread.ability-handler';
|
||||
ManageActivityAbilityHandler,
|
||||
ReadActivityAbilityHandler,
|
||||
CreateActivityAbilityHandler,
|
||||
UpdateActivityAbilityHandler,
|
||||
DeleteActivityAbilityHandler,
|
||||
} from './handlers/activity.ability-handler';
|
||||
import {
|
||||
ManageCommentAbilityHandler,
|
||||
ReadCommentAbilityHandler,
|
||||
@ -60,12 +60,12 @@ import {
|
||||
DeleteCommentAbilityHandler,
|
||||
} from './handlers/comment.ability-handler';
|
||||
import {
|
||||
ManageCommentThreadTargetAbilityHandler,
|
||||
ReadCommentThreadTargetAbilityHandler,
|
||||
CreateCommentThreadTargetAbilityHandler,
|
||||
UpdateCommentThreadTargetAbilityHandler,
|
||||
DeleteCommentThreadTargetAbilityHandler,
|
||||
} from './handlers/comment-thread-target.ability-handler';
|
||||
ManageActivityTargetAbilityHandler,
|
||||
ReadActivityTargetAbilityHandler,
|
||||
CreateActivityTargetAbilityHandler,
|
||||
UpdateActivityTargetAbilityHandler,
|
||||
DeleteActivityTargetAbilityHandler,
|
||||
} from './handlers/activity-target.ability-handler';
|
||||
import {
|
||||
ManagePipelineAbilityHandler,
|
||||
ReadPipelineAbilityHandler,
|
||||
@ -140,24 +140,24 @@ import {
|
||||
CreateRefreshTokenAbilityHandler,
|
||||
UpdateRefreshTokenAbilityHandler,
|
||||
DeleteRefreshTokenAbilityHandler,
|
||||
// CommentThread
|
||||
ManageCommentThreadAbilityHandler,
|
||||
ReadCommentThreadAbilityHandler,
|
||||
CreateCommentThreadAbilityHandler,
|
||||
UpdateCommentThreadAbilityHandler,
|
||||
DeleteCommentThreadAbilityHandler,
|
||||
// Activity
|
||||
ManageActivityAbilityHandler,
|
||||
ReadActivityAbilityHandler,
|
||||
CreateActivityAbilityHandler,
|
||||
UpdateActivityAbilityHandler,
|
||||
DeleteActivityAbilityHandler,
|
||||
// Comment
|
||||
ManageCommentAbilityHandler,
|
||||
ReadCommentAbilityHandler,
|
||||
CreateCommentAbilityHandler,
|
||||
UpdateCommentAbilityHandler,
|
||||
DeleteCommentAbilityHandler,
|
||||
// CommentThreadTarget
|
||||
ManageCommentThreadTargetAbilityHandler,
|
||||
ReadCommentThreadTargetAbilityHandler,
|
||||
CreateCommentThreadTargetAbilityHandler,
|
||||
UpdateCommentThreadTargetAbilityHandler,
|
||||
DeleteCommentThreadTargetAbilityHandler,
|
||||
// ActivityTarget
|
||||
ManageActivityTargetAbilityHandler,
|
||||
ReadActivityTargetAbilityHandler,
|
||||
CreateActivityTargetAbilityHandler,
|
||||
UpdateActivityTargetAbilityHandler,
|
||||
DeleteActivityTargetAbilityHandler,
|
||||
//Attachment
|
||||
ManageAttachmentAbilityHandler,
|
||||
ReadAttachmentAbilityHandler,
|
||||
@ -224,24 +224,24 @@ import {
|
||||
CreateRefreshTokenAbilityHandler,
|
||||
UpdateRefreshTokenAbilityHandler,
|
||||
DeleteRefreshTokenAbilityHandler,
|
||||
// CommentThread
|
||||
ManageCommentThreadAbilityHandler,
|
||||
ReadCommentThreadAbilityHandler,
|
||||
CreateCommentThreadAbilityHandler,
|
||||
UpdateCommentThreadAbilityHandler,
|
||||
DeleteCommentThreadAbilityHandler,
|
||||
// Activity
|
||||
ManageActivityAbilityHandler,
|
||||
ReadActivityAbilityHandler,
|
||||
CreateActivityAbilityHandler,
|
||||
UpdateActivityAbilityHandler,
|
||||
DeleteActivityAbilityHandler,
|
||||
// Comment
|
||||
ManageCommentAbilityHandler,
|
||||
ReadCommentAbilityHandler,
|
||||
CreateCommentAbilityHandler,
|
||||
UpdateCommentAbilityHandler,
|
||||
DeleteCommentAbilityHandler,
|
||||
// CommentThreadTarget
|
||||
ManageCommentThreadTargetAbilityHandler,
|
||||
ReadCommentThreadTargetAbilityHandler,
|
||||
CreateCommentThreadTargetAbilityHandler,
|
||||
UpdateCommentThreadTargetAbilityHandler,
|
||||
DeleteCommentThreadTargetAbilityHandler,
|
||||
// ActivityTarget
|
||||
ManageActivityTargetAbilityHandler,
|
||||
ReadActivityTargetAbilityHandler,
|
||||
CreateActivityTargetAbilityHandler,
|
||||
UpdateActivityTargetAbilityHandler,
|
||||
DeleteActivityTargetAbilityHandler,
|
||||
//Attachment
|
||||
ManageAttachmentAbilityHandler,
|
||||
ReadAttachmentAbilityHandler,
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
import {
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { subject } from '@casl/ability';
|
||||
|
||||
import { IAbilityHandler } from 'src/ability/interfaces/ability-handler.interface';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { AbilityAction } from 'src/ability/ability.action';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { ActivityTargetWhereInput } from 'src/core/@generated/activity-target/activity-target-where.input';
|
||||
|
||||
class ActivityTargetArgs {
|
||||
where?: ActivityTargetWhereInput;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ManageActivityTargetAbilityHandler implements IAbilityHandler {
|
||||
async handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Manage, 'ActivityTarget');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ReadActivityTargetAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Read, 'ActivityTarget');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CreateActivityTargetAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Create, 'ActivityTarget');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateActivityTargetAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<ActivityTargetArgs>();
|
||||
const ActivityTarget = await this.prismaService.client.activityTarget.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(ActivityTarget, '', NotFoundException);
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Update,
|
||||
subject('ActivityTarget', ActivityTarget),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteActivityTargetAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<ActivityTargetArgs>();
|
||||
const ActivityTarget = await this.prismaService.client.activityTarget.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(ActivityTarget, '', NotFoundException);
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Delete,
|
||||
subject('ActivityTarget', ActivityTarget),
|
||||
);
|
||||
}
|
||||
}
|
||||
73
server/src/ability/handlers/activity.ability-handler.ts
Normal file
73
server/src/ability/handlers/activity.ability-handler.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import {
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { subject } from '@casl/ability';
|
||||
|
||||
import { IAbilityHandler } from 'src/ability/interfaces/ability-handler.interface';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { AbilityAction } from 'src/ability/ability.action';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { ActivityWhereInput } from 'src/core/@generated/activity/activity-where.input';
|
||||
|
||||
class ActivityArgs {
|
||||
where?: ActivityWhereInput;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ManageActivityAbilityHandler implements IAbilityHandler {
|
||||
async handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Manage, 'Activity');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ReadActivityAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Read, 'Activity');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CreateActivityAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Create, 'Activity');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateActivityAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<ActivityArgs>();
|
||||
const Activity = await this.prismaService.client.activity.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(Activity, '', NotFoundException);
|
||||
|
||||
return ability.can(AbilityAction.Update, subject('Activity', Activity));
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteActivityAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<ActivityArgs>();
|
||||
const Activity = await this.prismaService.client.activity.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(Activity, '', NotFoundException);
|
||||
|
||||
return ability.can(AbilityAction.Delete, subject('Activity', Activity));
|
||||
}
|
||||
}
|
||||
@ -42,16 +42,12 @@ export class CreateAttachmentAbilityHandler implements IAbilityHandler {
|
||||
const args = gqlContext.getArgs<AttachmentArgs>();
|
||||
assert(args.activityId, '', ForbiddenException);
|
||||
|
||||
const activity = await this.prismaService.client.commentThread.findUnique({
|
||||
const activity = await this.prismaService.client.activity.findUnique({
|
||||
where: { id: args.activityId },
|
||||
include: { workspace: true },
|
||||
});
|
||||
assert(activity, '', NotFoundException);
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Update,
|
||||
subject('Workspace', activity.workspace),
|
||||
);
|
||||
return ability.can(AbilityAction.Update, subject('Activity', activity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,118 +0,0 @@
|
||||
import {
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { subject } from '@casl/ability';
|
||||
|
||||
import { IAbilityHandler } from 'src/ability/interfaces/ability-handler.interface';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { AbilityAction } from 'src/ability/ability.action';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { CommentThreadTargetWhereInput } from 'src/core/@generated/comment-thread-target/comment-thread-target-where.input';
|
||||
import { relationAbilityChecker } from 'src/ability/ability.util';
|
||||
import { assert } from 'src/utils/assert';
|
||||
|
||||
class CommentThreadTargetArgs {
|
||||
where?: CommentThreadTargetWhereInput;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ManageCommentThreadTargetAbilityHandler
|
||||
implements IAbilityHandler
|
||||
{
|
||||
async handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Manage, 'CommentThreadTarget');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ReadCommentThreadTargetAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Read, 'CommentThreadTarget');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CreateCommentThreadTargetAbilityHandler
|
||||
implements IAbilityHandler
|
||||
{
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs();
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'CommentThreadTarget',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(AbilityAction.Create, 'CommentThreadTarget');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateCommentThreadTargetAbilityHandler
|
||||
implements IAbilityHandler
|
||||
{
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<CommentThreadTargetArgs>();
|
||||
const commentThreadTarget =
|
||||
await this.prismaService.client.commentThreadTarget.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(commentThreadTarget, '', NotFoundException);
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'CommentThreadTarget',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Update,
|
||||
subject('CommentThreadTarget', commentThreadTarget),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteCommentThreadTargetAbilityHandler
|
||||
implements IAbilityHandler
|
||||
{
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<CommentThreadTargetArgs>();
|
||||
const commentThreadTarget =
|
||||
await this.prismaService.client.commentThreadTarget.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(commentThreadTarget, '', NotFoundException);
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Delete,
|
||||
subject('CommentThreadTarget', commentThreadTarget),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
import {
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { subject } from '@casl/ability';
|
||||
|
||||
import { IAbilityHandler } from 'src/ability/interfaces/ability-handler.interface';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { AbilityAction } from 'src/ability/ability.action';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { CommentThreadWhereInput } from 'src/core/@generated/comment-thread/comment-thread-where.input';
|
||||
import { relationAbilityChecker } from 'src/ability/ability.util';
|
||||
import { assert } from 'src/utils/assert';
|
||||
|
||||
class CommentThreadArgs {
|
||||
where?: CommentThreadWhereInput;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ManageCommentThreadAbilityHandler implements IAbilityHandler {
|
||||
async handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Manage, 'CommentThread');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ReadCommentThreadAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Read, 'CommentThread');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CreateCommentThreadAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs();
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'CommentThread',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(AbilityAction.Create, 'CommentThread');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateCommentThreadAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<CommentThreadArgs>();
|
||||
const commentThread =
|
||||
await this.prismaService.client.commentThread.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(commentThread, '', NotFoundException);
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'CommentThread',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Update,
|
||||
subject('CommentThread', commentThread),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteCommentThreadAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<CommentThreadArgs>();
|
||||
const commentThread =
|
||||
await this.prismaService.client.commentThread.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(commentThread, '', NotFoundException);
|
||||
|
||||
return ability.can(
|
||||
AbilityAction.Delete,
|
||||
subject('CommentThread', commentThread),
|
||||
);
|
||||
}
|
||||
}
|
||||
11
server/src/core/activity/activity.module.ts
Normal file
11
server/src/core/activity/activity.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { ActivityResolver } from './resolvers/activity.resolver';
|
||||
import { ActivityService } from './services/activity.service';
|
||||
import { ActivityTargetService } from './services/activity-target.service';
|
||||
|
||||
@Module({
|
||||
providers: [ActivityResolver, ActivityService, ActivityTargetService],
|
||||
exports: [ActivityService, ActivityTargetService],
|
||||
})
|
||||
export class ActivityModule {}
|
||||
@ -1,19 +1,19 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { CommentThreadService } from 'src/core/comment/services/comment-thread.service';
|
||||
import { ActivityService } from 'src/core/activity/services/activity.service';
|
||||
import { AbilityFactory } from 'src/ability/ability.factory';
|
||||
|
||||
import { CommentThreadResolver } from './comment-thread.resolver';
|
||||
import { ActivityResolver } from './activity.resolver';
|
||||
|
||||
describe('CommentThreadResolver', () => {
|
||||
let resolver: CommentThreadResolver;
|
||||
describe('ActivityResolver', () => {
|
||||
let resolver: ActivityResolver;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
CommentThreadResolver,
|
||||
ActivityResolver,
|
||||
{
|
||||
provide: CommentThreadService,
|
||||
provide: ActivityService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
@ -23,7 +23,7 @@ describe('CommentThreadResolver', () => {
|
||||
],
|
||||
}).compile();
|
||||
|
||||
resolver = module.get<CommentThreadResolver>(CommentThreadResolver);
|
||||
resolver = module.get<ActivityResolver>(ActivityResolver);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
156
server/src/core/activity/resolvers/activity.resolver.ts
Normal file
156
server/src/core/activity/resolvers/activity.resolver.ts
Normal file
@ -0,0 +1,156 @@
|
||||
import { Resolver, Args, Mutation, Query } from '@nestjs/graphql';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
|
||||
import { accessibleBy } from '@casl/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import {
|
||||
PrismaSelector,
|
||||
PrismaSelect,
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { AbilityGuard } from 'src/guards/ability.guard';
|
||||
import { CheckAbilities } from 'src/decorators/check-abilities.decorator';
|
||||
import {
|
||||
CreateActivityAbilityHandler,
|
||||
DeleteActivityAbilityHandler,
|
||||
ReadActivityAbilityHandler,
|
||||
UpdateActivityAbilityHandler,
|
||||
} from 'src/ability/handlers/activity.ability-handler';
|
||||
import { UserAbility } from 'src/decorators/user-ability.decorator';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { AffectedRows } from 'src/core/@generated/prisma/affected-rows.output';
|
||||
import { Activity } from 'src/core/@generated/activity/activity.model';
|
||||
import { ActivityService } from 'src/core/activity/services/activity.service';
|
||||
import { CreateOneActivityArgs } from 'src/core/@generated/activity/create-one-activity.args';
|
||||
import { Workspace } from 'src/core/@generated/workspace/workspace.model';
|
||||
import { UpdateOneActivityArgs } from 'src/core/@generated/activity/update-one-activity.args';
|
||||
import { FindManyActivityArgs } from 'src/core/@generated/activity/find-many-activity.args';
|
||||
import { DeleteManyActivityArgs } from 'src/core/@generated/activity/delete-many-activity.args';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => Activity)
|
||||
export class ActivityResolver {
|
||||
constructor(private readonly activityService: ActivityService) {}
|
||||
|
||||
@Mutation(() => Activity, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(CreateActivityAbilityHandler)
|
||||
async createOneActivity(
|
||||
@Args() args: CreateOneActivityArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
@PrismaSelector({ modelName: 'Activity' })
|
||||
prismaSelect: PrismaSelect<'Activity'>,
|
||||
): Promise<Partial<Activity>> {
|
||||
const createdActivity = await this.activityService.create({
|
||||
data: {
|
||||
...args.data,
|
||||
...{ workspace: { connect: { id: workspace.id } } },
|
||||
activityTargets: args.data?.activityTargets?.createMany
|
||||
? {
|
||||
createMany: {
|
||||
data: args.data.activityTargets.createMany.data.map(
|
||||
(target) => ({ ...target, workspaceId: workspace.id }),
|
||||
),
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
} as Prisma.ActivityCreateArgs);
|
||||
|
||||
return createdActivity;
|
||||
}
|
||||
|
||||
@Mutation(() => Activity, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(UpdateActivityAbilityHandler)
|
||||
async updateOneActivity(
|
||||
@Args() args: UpdateOneActivityArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
@PrismaSelector({ modelName: 'Activity' })
|
||||
prismaSelect: PrismaSelect<'Activity'>,
|
||||
): Promise<Partial<Activity>> {
|
||||
// TODO: Do a proper check with recursion testing on args in a more generic place
|
||||
for (const key in args.data) {
|
||||
if (args.data[key]) {
|
||||
for (const subKey in args.data[key]) {
|
||||
if (JSON.stringify(args.data[key][subKey]) === '{}') {
|
||||
delete args.data[key][subKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(args.data[key]) === '{}') {
|
||||
delete args.data[key];
|
||||
}
|
||||
}
|
||||
const updatedActivity = await this.activityService.update({
|
||||
where: args.where,
|
||||
data: {
|
||||
...args.data,
|
||||
activityTargets: args.data?.activityTargets
|
||||
? {
|
||||
createMany: args.data.activityTargets.createMany
|
||||
? {
|
||||
data: args.data.activityTargets.createMany.data.map(
|
||||
(target) => ({
|
||||
...target,
|
||||
workspaceId: workspace.id,
|
||||
}),
|
||||
),
|
||||
}
|
||||
: undefined,
|
||||
deleteMany: args.data.activityTargets.deleteMany ?? undefined,
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
} as Prisma.ActivityUpdateArgs);
|
||||
|
||||
return updatedActivity;
|
||||
}
|
||||
|
||||
@Query(() => [Activity])
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(ReadActivityAbilityHandler)
|
||||
async findManyActivities(
|
||||
@Args() args: FindManyActivityArgs,
|
||||
@UserAbility() ability: AppAbility,
|
||||
@PrismaSelector({ modelName: 'Activity' })
|
||||
prismaSelect: PrismaSelect<'Activity'>,
|
||||
): Promise<Partial<Activity>[]> {
|
||||
const result = await this.activityService.findMany({
|
||||
where: {
|
||||
...args.where,
|
||||
AND: [accessibleBy(ability).Activity],
|
||||
},
|
||||
orderBy: args.orderBy,
|
||||
cursor: args.cursor,
|
||||
take: args.take,
|
||||
skip: args.skip,
|
||||
distinct: args.distinct,
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Mutation(() => AffectedRows, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(DeleteActivityAbilityHandler)
|
||||
async deleteManyActivities(
|
||||
@Args() args: DeleteManyActivityArgs,
|
||||
): Promise<AffectedRows> {
|
||||
return this.activityService.deleteMany({
|
||||
where: args.where,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -3,15 +3,15 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { prismaMock } from 'src/database/client-mock/jest-prisma-singleton';
|
||||
|
||||
import { CommentThreadTargetService } from './comment-thread-target.service';
|
||||
import { ActivityTargetService } from './activity-target.service';
|
||||
|
||||
describe('CommentThreadTargetService', () => {
|
||||
let service: CommentThreadTargetService;
|
||||
describe('ActivityTargetService', () => {
|
||||
let service: ActivityTargetService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
CommentThreadTargetService,
|
||||
ActivityTargetService,
|
||||
{
|
||||
provide: PrismaService,
|
||||
useValue: prismaMock,
|
||||
@ -19,9 +19,7 @@ describe('CommentThreadTargetService', () => {
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CommentThreadTargetService>(
|
||||
CommentThreadTargetService,
|
||||
);
|
||||
service = module.get<ActivityTargetService>(ActivityTargetService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
40
server/src/core/activity/services/activity-target.service.ts
Normal file
40
server/src/core/activity/services/activity-target.service.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class ActivityTargetService {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
// Find
|
||||
findFirst = this.prismaService.client.activityTarget.findFirst;
|
||||
findFirstOrThrow = this.prismaService.client.activityTarget.findFirstOrThrow;
|
||||
|
||||
findUnique = this.prismaService.client.activityTarget.findUnique;
|
||||
findUniqueOrThrow =
|
||||
this.prismaService.client.activityTarget.findUniqueOrThrow;
|
||||
|
||||
findMany = this.prismaService.client.activityTarget.findMany;
|
||||
|
||||
// Create
|
||||
create = this.prismaService.client.activityTarget.create;
|
||||
createMany = this.prismaService.client.activityTarget.createMany;
|
||||
|
||||
// Update
|
||||
update = this.prismaService.client.activityTarget.update;
|
||||
upsert = this.prismaService.client.activityTarget.upsert;
|
||||
updateMany = this.prismaService.client.activityTarget.updateMany;
|
||||
|
||||
// Delete
|
||||
delete = this.prismaService.client.activityTarget.delete;
|
||||
deleteMany = this.prismaService.client.activityTarget.deleteMany;
|
||||
|
||||
// Aggregate
|
||||
aggregate = this.prismaService.client.activityTarget.aggregate;
|
||||
|
||||
// Count
|
||||
count = this.prismaService.client.activityTarget.count;
|
||||
|
||||
// GroupBy
|
||||
groupBy = this.prismaService.client.activityTarget.groupBy;
|
||||
}
|
||||
@ -3,15 +3,15 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { prismaMock } from 'src/database/client-mock/jest-prisma-singleton';
|
||||
|
||||
import { CommentThreadService } from './comment-thread.service';
|
||||
import { ActivityService } from './activity.service';
|
||||
|
||||
describe('CommentThreadService', () => {
|
||||
let service: CommentThreadService;
|
||||
describe('ActivityService', () => {
|
||||
let service: ActivityService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
CommentThreadService,
|
||||
ActivityService,
|
||||
{
|
||||
provide: PrismaService,
|
||||
useValue: prismaMock,
|
||||
@ -19,7 +19,7 @@ describe('CommentThreadService', () => {
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CommentThreadService>(CommentThreadService);
|
||||
service = module.get<ActivityService>(ActivityService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
39
server/src/core/activity/services/activity.service.ts
Normal file
39
server/src/core/activity/services/activity.service.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class ActivityService {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
// Find
|
||||
findFirst = this.prismaService.client.activity.findFirst;
|
||||
findFirstOrThrow = this.prismaService.client.activity.findFirstOrThrow;
|
||||
|
||||
findUnique = this.prismaService.client.activity.findUnique;
|
||||
findUniqueOrThrow = this.prismaService.client.activity.findUniqueOrThrow;
|
||||
|
||||
findMany = this.prismaService.client.activity.findMany;
|
||||
|
||||
// Create
|
||||
create = this.prismaService.client.activity.create;
|
||||
createMany = this.prismaService.client.activity.createMany;
|
||||
|
||||
// Update
|
||||
update = this.prismaService.client.activity.update;
|
||||
upsert = this.prismaService.client.activity.upsert;
|
||||
updateMany = this.prismaService.client.activity.updateMany;
|
||||
|
||||
// Delete
|
||||
delete = this.prismaService.client.activity.delete;
|
||||
deleteMany = this.prismaService.client.activity.deleteMany;
|
||||
|
||||
// Aggregate
|
||||
aggregate = this.prismaService.client.activity.aggregate;
|
||||
|
||||
// Count
|
||||
count = this.prismaService.client.activity.count;
|
||||
|
||||
// GroupBy
|
||||
groupBy = this.prismaService.client.activity.groupBy;
|
||||
}
|
||||
@ -1,19 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { CommentService } from './services/comment.service';
|
||||
import { CommentResolver } from './resolvers/comment.resolver';
|
||||
import { CommentThreadTargetService } from './services/comment-thread-target.service';
|
||||
import { CommentThreadResolver } from './resolvers/comment-thread.resolver';
|
||||
import { CommentThreadService } from './services/comment-thread.service';
|
||||
import { CommentService } from './comment.service';
|
||||
import { CommentResolver } from './comment.resolver';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
CommentService,
|
||||
CommentThreadService,
|
||||
CommentThreadTargetService,
|
||||
CommentResolver,
|
||||
CommentThreadResolver,
|
||||
],
|
||||
exports: [CommentService, CommentThreadService, CommentThreadTargetService],
|
||||
providers: [CommentService, CommentResolver],
|
||||
exports: [CommentService],
|
||||
})
|
||||
export class CommentModule {}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { CommentService } from 'src/core/comment/services/comment.service';
|
||||
import { CommentService } from 'src/core/comment/comment.service';
|
||||
import { AbilityFactory } from 'src/ability/ability.factory';
|
||||
|
||||
import { CommentResolver } from './comment.resolver';
|
||||
@ -8,7 +8,7 @@ import { Workspace } from 'src/core/@generated/workspace/workspace.model';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import { CreateOneCommentArgs } from 'src/core/@generated/comment/create-one-comment.args';
|
||||
import { Comment } from 'src/core/@generated/comment/comment.model';
|
||||
import { CommentService } from 'src/core/comment/services/comment.service';
|
||||
import { CommentService } from 'src/core/comment/comment.service';
|
||||
import {
|
||||
PrismaSelector,
|
||||
PrismaSelect,
|
||||
@ -1,150 +0,0 @@
|
||||
import { Resolver, Args, Mutation, Query } from '@nestjs/graphql';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
|
||||
import { accessibleBy } from '@casl/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
import { Workspace } from 'src/core/@generated/workspace/workspace.model';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import { CommentThread } from 'src/core/@generated/comment-thread/comment-thread.model';
|
||||
import { CreateOneCommentThreadArgs } from 'src/core/@generated/comment-thread/create-one-comment-thread.args';
|
||||
import { FindManyCommentThreadArgs } from 'src/core/@generated/comment-thread/find-many-comment-thread.args';
|
||||
import { CommentThreadService } from 'src/core/comment/services/comment-thread.service';
|
||||
import { UpdateOneCommentThreadArgs } from 'src/core/@generated/comment-thread/update-one-comment-thread.args';
|
||||
import {
|
||||
PrismaSelector,
|
||||
PrismaSelect,
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { AbilityGuard } from 'src/guards/ability.guard';
|
||||
import { CheckAbilities } from 'src/decorators/check-abilities.decorator';
|
||||
import {
|
||||
CreateCommentThreadAbilityHandler,
|
||||
DeleteCommentThreadAbilityHandler,
|
||||
ReadCommentThreadAbilityHandler,
|
||||
UpdateCommentThreadAbilityHandler,
|
||||
} from 'src/ability/handlers/comment-thread.ability-handler';
|
||||
import { UserAbility } from 'src/decorators/user-ability.decorator';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { AffectedRows } from 'src/core/@generated/prisma/affected-rows.output';
|
||||
import { DeleteManyCommentThreadArgs } from 'src/core/@generated/comment-thread/delete-many-comment-thread.args';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => CommentThread)
|
||||
export class CommentThreadResolver {
|
||||
constructor(private readonly commentThreadService: CommentThreadService) {}
|
||||
|
||||
@Mutation(() => CommentThread, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(CreateCommentThreadAbilityHandler)
|
||||
async createOneCommentThread(
|
||||
@Args() args: CreateOneCommentThreadArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
@PrismaSelector({ modelName: 'CommentThread' })
|
||||
prismaSelect: PrismaSelect<'CommentThread'>,
|
||||
): Promise<Partial<CommentThread>> {
|
||||
const createdCommentThread = await this.commentThreadService.create({
|
||||
data: {
|
||||
...args.data,
|
||||
...{ workspace: { connect: { id: workspace.id } } },
|
||||
commentThreadTargets: args.data?.commentThreadTargets?.createMany
|
||||
? {
|
||||
createMany: {
|
||||
data: args.data.commentThreadTargets.createMany.data.map(
|
||||
(target) => ({ ...target, workspaceId: workspace.id }),
|
||||
),
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
} as Prisma.CommentThreadCreateArgs);
|
||||
|
||||
return createdCommentThread;
|
||||
}
|
||||
|
||||
@Mutation(() => CommentThread, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(UpdateCommentThreadAbilityHandler)
|
||||
async updateOneCommentThread(
|
||||
@Args() args: UpdateOneCommentThreadArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
@PrismaSelector({ modelName: 'CommentThread' })
|
||||
prismaSelect: PrismaSelect<'CommentThread'>,
|
||||
): Promise<Partial<CommentThread>> {
|
||||
// TODO: Do a proper check with recursion testing on args in a more generic place
|
||||
for (const key in args.data) {
|
||||
if (args.data[key]) {
|
||||
for (const subKey in args.data[key]) {
|
||||
if (JSON.stringify(args.data[key][subKey]) === '{}') {
|
||||
delete args.data[key][subKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(args.data[key]) === '{}') {
|
||||
delete args.data[key];
|
||||
}
|
||||
}
|
||||
const updatedCommentThread = await this.commentThreadService.update({
|
||||
where: args.where,
|
||||
data: {
|
||||
...args.data,
|
||||
commentThreadTargets: args.data?.commentThreadTargets?.createMany
|
||||
? {
|
||||
createMany: {
|
||||
data: args.data.commentThreadTargets.createMany.data.map(
|
||||
(target) => ({ ...target, workspaceId: workspace.id }),
|
||||
),
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
} as Prisma.CommentThreadUpdateArgs);
|
||||
|
||||
return updatedCommentThread;
|
||||
}
|
||||
|
||||
@Query(() => [CommentThread])
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(ReadCommentThreadAbilityHandler)
|
||||
async findManyCommentThreads(
|
||||
@Args() args: FindManyCommentThreadArgs,
|
||||
@UserAbility() ability: AppAbility,
|
||||
@PrismaSelector({ modelName: 'CommentThread' })
|
||||
prismaSelect: PrismaSelect<'CommentThread'>,
|
||||
): Promise<Partial<CommentThread>[]> {
|
||||
const result = await this.commentThreadService.findMany({
|
||||
where: {
|
||||
...args.where,
|
||||
AND: [accessibleBy(ability).CommentThread],
|
||||
},
|
||||
orderBy: args.orderBy,
|
||||
cursor: args.cursor,
|
||||
take: args.take,
|
||||
skip: args.skip,
|
||||
distinct: args.distinct,
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Mutation(() => AffectedRows, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(DeleteCommentThreadAbilityHandler)
|
||||
async deleteManyCommentThreads(
|
||||
@Args() args: DeleteManyCommentThreadArgs,
|
||||
): Promise<AffectedRows> {
|
||||
return this.commentThreadService.deleteMany({
|
||||
where: args.where,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class CommentThreadTargetService {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
// Find
|
||||
findFirst = this.prismaService.client.commentThreadTarget.findFirst;
|
||||
findFirstOrThrow =
|
||||
this.prismaService.client.commentThreadTarget.findFirstOrThrow;
|
||||
|
||||
findUnique = this.prismaService.client.commentThreadTarget.findUnique;
|
||||
findUniqueOrThrow =
|
||||
this.prismaService.client.commentThreadTarget.findUniqueOrThrow;
|
||||
|
||||
findMany = this.prismaService.client.commentThreadTarget.findMany;
|
||||
|
||||
// Create
|
||||
create = this.prismaService.client.commentThreadTarget.create;
|
||||
createMany = this.prismaService.client.commentThreadTarget.createMany;
|
||||
|
||||
// Update
|
||||
update = this.prismaService.client.commentThreadTarget.update;
|
||||
upsert = this.prismaService.client.commentThreadTarget.upsert;
|
||||
updateMany = this.prismaService.client.commentThreadTarget.updateMany;
|
||||
|
||||
// Delete
|
||||
delete = this.prismaService.client.commentThreadTarget.delete;
|
||||
deleteMany = this.prismaService.client.commentThreadTarget.deleteMany;
|
||||
|
||||
// Aggregate
|
||||
aggregate = this.prismaService.client.commentThreadTarget.aggregate;
|
||||
|
||||
// Count
|
||||
count = this.prismaService.client.commentThreadTarget.count;
|
||||
|
||||
// GroupBy
|
||||
groupBy = this.prismaService.client.commentThreadTarget.groupBy;
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class CommentThreadService {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
// Find
|
||||
findFirst = this.prismaService.client.commentThread.findFirst;
|
||||
findFirstOrThrow = this.prismaService.client.commentThread.findFirstOrThrow;
|
||||
|
||||
findUnique = this.prismaService.client.commentThread.findUnique;
|
||||
findUniqueOrThrow = this.prismaService.client.commentThread.findUniqueOrThrow;
|
||||
|
||||
findMany = this.prismaService.client.commentThread.findMany;
|
||||
|
||||
// Create
|
||||
create = this.prismaService.client.commentThread.create;
|
||||
createMany = this.prismaService.client.commentThread.createMany;
|
||||
|
||||
// Update
|
||||
update = this.prismaService.client.commentThread.update;
|
||||
upsert = this.prismaService.client.commentThread.upsert;
|
||||
updateMany = this.prismaService.client.commentThread.updateMany;
|
||||
|
||||
// Delete
|
||||
delete = this.prismaService.client.commentThread.delete;
|
||||
deleteMany = this.prismaService.client.commentThread.deleteMany;
|
||||
|
||||
// Aggregate
|
||||
aggregate = this.prismaService.client.commentThread.aggregate;
|
||||
|
||||
// Count
|
||||
count = this.prismaService.client.commentThread.count;
|
||||
|
||||
// GroupBy
|
||||
groupBy = this.prismaService.client.commentThread.groupBy;
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { CommentThreadService } from 'src/core/comment/services/comment-thread.service';
|
||||
import { CommentService } from 'src/core/comment/services/comment.service';
|
||||
import { CommentService } from 'src/core/comment/comment.service';
|
||||
import { ActivityService } from 'src/core/activity/services/activity.service';
|
||||
|
||||
import { CompanyRelationsResolver } from './company-relations.resolver';
|
||||
import { CompanyService } from './company.service';
|
||||
@ -18,7 +18,7 @@ describe('CompanyRelationsResolver', () => {
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: CommentThreadService,
|
||||
provide: ActivityService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
|
||||
@ -1,36 +1,36 @@
|
||||
import { Resolver, ResolveField, Root, Int } from '@nestjs/graphql';
|
||||
|
||||
import { CommentThread } from 'src/core/@generated/comment-thread/comment-thread.model';
|
||||
import { Comment } from 'src/core/@generated/comment/comment.model';
|
||||
import { Company } from 'src/core/@generated/company/company.model';
|
||||
import { CommentThreadService } from 'src/core/comment/services/comment-thread.service';
|
||||
import { CommentService } from 'src/core/comment/services/comment.service';
|
||||
import { CommentService } from 'src/core/comment/comment.service';
|
||||
import {
|
||||
PrismaSelect,
|
||||
PrismaSelector,
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { ActivityService } from 'src/core/activity/services/activity.service';
|
||||
import { Activity } from 'src/core/@generated/activity/activity.model';
|
||||
|
||||
@Resolver(() => Company)
|
||||
export class CompanyRelationsResolver {
|
||||
constructor(
|
||||
private readonly commentThreadService: CommentThreadService,
|
||||
private readonly activityService: ActivityService,
|
||||
private readonly commentService: CommentService,
|
||||
) {}
|
||||
|
||||
@ResolveField(() => [CommentThread], {
|
||||
@ResolveField(() => [Activity], {
|
||||
nullable: false,
|
||||
})
|
||||
async commentThreads(
|
||||
async activities(
|
||||
@Root() company: Company,
|
||||
@PrismaSelector({ modelName: 'CommentThread' })
|
||||
prismaSelect: PrismaSelect<'CommentThread'>,
|
||||
): Promise<Partial<CommentThread>[]> {
|
||||
return this.commentThreadService.findMany({
|
||||
@PrismaSelector({ modelName: 'Activity' })
|
||||
prismaSelect: PrismaSelect<'Activity'>,
|
||||
): Promise<Partial<Activity>[]> {
|
||||
return this.activityService.findMany({
|
||||
where: {
|
||||
commentThreadTargets: {
|
||||
activityTargets: {
|
||||
some: {
|
||||
commentableId: company.id,
|
||||
commentableType: 'Company',
|
||||
commentableId: company.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -48,11 +48,11 @@ export class CompanyRelationsResolver {
|
||||
): Promise<Partial<Comment>[]> {
|
||||
return this.commentService.findMany({
|
||||
where: {
|
||||
commentThread: {
|
||||
commentThreadTargets: {
|
||||
activity: {
|
||||
activityTargets: {
|
||||
some: {
|
||||
commentableId: company.id,
|
||||
commentableType: 'Company',
|
||||
commentableId: company.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -64,13 +64,13 @@ export class CompanyRelationsResolver {
|
||||
@ResolveField(() => Int, {
|
||||
nullable: false,
|
||||
})
|
||||
async _commentThreadCount(@Root() company: Company): Promise<number> {
|
||||
return this.commentThreadService.count({
|
||||
async _activityCount(@Root() company: Company): Promise<number> {
|
||||
return this.activityService.count({
|
||||
where: {
|
||||
commentThreadTargets: {
|
||||
activityTargets: {
|
||||
some: {
|
||||
commentableId: company.id,
|
||||
commentableType: 'Company',
|
||||
commentableId: company.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { CommentModule } from 'src/core/comment/comment.module';
|
||||
import { ActivityModule } from 'src/core/activity/activity.module';
|
||||
|
||||
import { CompanyService } from './company.service';
|
||||
import { CompanyResolver } from './company.resolver';
|
||||
import { CompanyRelationsResolver } from './company-relations.resolver';
|
||||
|
||||
@Module({
|
||||
imports: [CommentModule],
|
||||
imports: [CommentModule, ActivityModule],
|
||||
providers: [CompanyService, CompanyResolver, CompanyRelationsResolver],
|
||||
exports: [CompanyService],
|
||||
})
|
||||
|
||||
@ -11,6 +11,7 @@ import { AnalyticsModule } from './analytics/analytics.module';
|
||||
import { FileModule } from './file/file.module';
|
||||
import { ClientConfigModule } from './client-config/client-config.module';
|
||||
import { AttachmentModule } from './attachment/attachment.module';
|
||||
import { ActivityModule } from './activity/activity.module';
|
||||
import { ViewModule } from './view/view.module';
|
||||
|
||||
@Module({
|
||||
@ -26,6 +27,7 @@ import { ViewModule } from './view/view.module';
|
||||
FileModule,
|
||||
ClientConfigModule,
|
||||
AttachmentModule,
|
||||
ActivityModule,
|
||||
ViewModule,
|
||||
],
|
||||
exports: [
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { CommentThreadService } from 'src/core/comment/services/comment-thread.service';
|
||||
import { CommentService } from 'src/core/comment/services/comment.service';
|
||||
import { CommentService } from 'src/core/comment/comment.service';
|
||||
import { ActivityService } from 'src/core/activity/services/activity.service';
|
||||
|
||||
import { PersonRelationsResolver } from './person-relations.resolver';
|
||||
import { PersonService } from './person.service';
|
||||
@ -18,7 +18,7 @@ describe('PersonRelationsResolver', () => {
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: CommentThreadService,
|
||||
provide: ActivityService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
|
||||
@ -1,36 +1,36 @@
|
||||
import { Resolver, Root, ResolveField, Int } from '@nestjs/graphql';
|
||||
|
||||
import { CommentThread } from 'src/core/@generated/comment-thread/comment-thread.model';
|
||||
import { Comment } from 'src/core/@generated/comment/comment.model';
|
||||
import { Person } from 'src/core/@generated/person/person.model';
|
||||
import { CommentThreadService } from 'src/core/comment/services/comment-thread.service';
|
||||
import { CommentService } from 'src/core/comment/services/comment.service';
|
||||
import { CommentService } from 'src/core/comment/comment.service';
|
||||
import {
|
||||
PrismaSelect,
|
||||
PrismaSelector,
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { Activity } from 'src/core/@generated/activity/activity.model';
|
||||
import { ActivityService } from 'src/core/activity/services/activity.service';
|
||||
|
||||
@Resolver(() => Person)
|
||||
export class PersonRelationsResolver {
|
||||
constructor(
|
||||
private readonly commentThreadService: CommentThreadService,
|
||||
private readonly activityService: ActivityService,
|
||||
private readonly commentService: CommentService,
|
||||
) {}
|
||||
|
||||
@ResolveField(() => [CommentThread], {
|
||||
@ResolveField(() => [Activity], {
|
||||
nullable: false,
|
||||
})
|
||||
async commentThreads(
|
||||
async activities(
|
||||
@Root() person: Person,
|
||||
@PrismaSelector({ modelName: 'CommentThread' })
|
||||
prismaSelect: PrismaSelect<'CommentThread'>,
|
||||
): Promise<Partial<CommentThread>[]> {
|
||||
return await this.commentThreadService.findMany({
|
||||
@PrismaSelector({ modelName: 'Activity' })
|
||||
prismaSelect: PrismaSelect<'Activity'>,
|
||||
): Promise<Partial<Activity>[]> {
|
||||
return await this.activityService.findMany({
|
||||
where: {
|
||||
commentThreadTargets: {
|
||||
activityTargets: {
|
||||
some: {
|
||||
commentableId: person.id,
|
||||
commentableType: 'Person',
|
||||
commentableId: person.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -48,11 +48,11 @@ export class PersonRelationsResolver {
|
||||
): Promise<Partial<Comment>[]> {
|
||||
return this.commentService.findMany({
|
||||
where: {
|
||||
commentThread: {
|
||||
commentThreadTargets: {
|
||||
activity: {
|
||||
activityTargets: {
|
||||
some: {
|
||||
commentableId: person.id,
|
||||
commentableType: 'Person',
|
||||
commentableId: person.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -64,13 +64,13 @@ export class PersonRelationsResolver {
|
||||
@ResolveField(() => Int, {
|
||||
nullable: false,
|
||||
})
|
||||
async _commentThreadCount(@Root() person: Person): Promise<number> {
|
||||
return this.commentThreadService.count({
|
||||
async _activityCount(@Root() person: Person): Promise<number> {
|
||||
return this.activityService.count({
|
||||
where: {
|
||||
commentThreadTargets: {
|
||||
activityTargets: {
|
||||
some: {
|
||||
commentableId: person.id,
|
||||
commentableType: 'Person',
|
||||
commentableId: person.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { CommentModule } from 'src/core/comment/comment.module';
|
||||
import { ActivityModule } from 'src/core/activity/activity.module';
|
||||
|
||||
import { PersonService } from './person.service';
|
||||
import { PersonResolver } from './person.resolver';
|
||||
import { PersonRelationsResolver } from './person-relations.resolver';
|
||||
|
||||
@Module({
|
||||
imports: [CommentModule, CommentModule],
|
||||
imports: [CommentModule, ActivityModule],
|
||||
providers: [PersonService, PersonResolver, PersonRelationsResolver],
|
||||
exports: [PersonService],
|
||||
})
|
||||
|
||||
@ -18,7 +18,6 @@ import { UpdateOnePersonArgs } from 'src/core/@generated/person/update-one-perso
|
||||
import { CreateOnePersonArgs } from 'src/core/@generated/person/create-one-person.args';
|
||||
import { AffectedRows } from 'src/core/@generated/prisma/affected-rows.output';
|
||||
import { DeleteManyPersonArgs } from 'src/core/@generated/person/delete-many-person.args';
|
||||
import { Workspace } from 'src/core/@generated/workspace/workspace.model';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import {
|
||||
PrismaSelect,
|
||||
@ -34,6 +33,7 @@ import {
|
||||
} from 'src/ability/handlers/person.ability-handler';
|
||||
import { UserAbility } from 'src/decorators/user-ability.decorator';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { Workspace } from 'src/core/@generated/workspace/workspace.model';
|
||||
|
||||
import { PersonService } from './person.service';
|
||||
|
||||
|
||||
@ -109,11 +109,11 @@ export class WorkspaceService {
|
||||
refreshToken,
|
||||
attachment,
|
||||
comment,
|
||||
commentThreadTarget,
|
||||
commentThread,
|
||||
activityTarget,
|
||||
activity,
|
||||
} = this.prismaService.client;
|
||||
|
||||
const commentThreads = await commentThread.findMany({
|
||||
const activitys = await activity.findMany({
|
||||
where: { authorId: userId },
|
||||
});
|
||||
|
||||
@ -142,12 +142,12 @@ export class WorkspaceService {
|
||||
comment.deleteMany({
|
||||
where,
|
||||
}),
|
||||
...commentThreads.map(({ id: commentThreadId }) =>
|
||||
commentThreadTarget.deleteMany({
|
||||
where: { commentThreadId },
|
||||
...activitys.map(({ id: activityId }) =>
|
||||
activityTarget.deleteMany({
|
||||
where: { activityId },
|
||||
}),
|
||||
),
|
||||
commentThread.deleteMany({
|
||||
activity.deleteMany({
|
||||
where,
|
||||
}),
|
||||
refreshToken.deleteMany({
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
-- Create the new tables first, without any foreign key constraints
|
||||
-- Activities Table
|
||||
CREATE TABLE "activities" (
|
||||
"id" TEXT NOT NULL,
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `comment_thread_targets` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `comment_threads` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "attachments" DROP CONSTRAINT "attachments_activityId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comment_thread_targets" DROP CONSTRAINT "comment_thread_targets_commentThreadId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comment_thread_targets" DROP CONSTRAINT "comment_thread_targets_workspaceId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comment_threads" DROP CONSTRAINT "comment_threads_assigneeId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comment_threads" DROP CONSTRAINT "comment_threads_authorId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comment_threads" DROP CONSTRAINT "comment_threads_workspaceId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_commentThreadId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "activity_targets" ADD COLUMN "commentableId" TEXT,
|
||||
ADD COLUMN "commentableType" "CommentableType",
|
||||
ALTER COLUMN "personId" DROP NOT NULL,
|
||||
ALTER COLUMN "companyId" DROP NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "comments" ADD COLUMN "activityId" TEXT;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "comment_thread_targets";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "comment_threads";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activities" ADD CONSTRAINT "activities_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activities" ADD CONSTRAINT "activities_assigneeId_fkey" FOREIGN KEY ("assigneeId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activities" ADD CONSTRAINT "activities_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_activityId_fkey" FOREIGN KEY ("activityId") REFERENCES "activities"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activity_targets" ADD CONSTRAINT "activity_targets_activityId_fkey" FOREIGN KEY ("activityId") REFERENCES "activities"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activity_targets" ADD CONSTRAINT "activity_targets_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activity_targets" ADD CONSTRAINT "activity_targets_personId_fkey" FOREIGN KEY ("personId") REFERENCES "people"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "activity_targets" ADD CONSTRAINT "activity_targets_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_activityId_fkey" FOREIGN KEY ("activityId") REFERENCES "activities"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@ -20,20 +20,20 @@ generator nestgraphql {
|
||||
fields_Validator_from = "class-validator"
|
||||
|
||||
// All relations, only allow connect
|
||||
decorate_all_type = "!(CommentThreadTarget*Input|UserSettingsUpdateOneRequiredWithoutUserNestedInput)"
|
||||
decorate_all_type = "!(ActivityTarget*Input|UserSettingsUpdateOneRequiredWithoutUserNestedInput)"
|
||||
decorate_all_field = "*(create|connectOrCreate|update|upsert|delete|createMany|updateMany|deleteMany)"
|
||||
decorate_all_name = "HideField"
|
||||
decorate_all_from = "@nestjs/graphql"
|
||||
decorate_all_arguments = "[]"
|
||||
|
||||
// CommentThread: Only Allow targets createOrConnect / createMany
|
||||
decorate_commentThreadTargets_type = "*CommentThreadTarget*Input"
|
||||
decorate_commentThreadTargets_field = "*(update|upsert|updateMany)"
|
||||
decorate_commentThreadTargets_name = "HideField"
|
||||
decorate_commentThreadTargets_from = "@nestjs/graphql"
|
||||
decorate_commentThreadTargets_arguments = "[]"
|
||||
// Activity: Only Allow targets createOrConnect / createMany
|
||||
decorate_activityTargets_type = "*ActivityTarget*Input"
|
||||
decorate_activityTargets_field = "*(update|upsert|updateMany)"
|
||||
decorate_activityTargets_name = "HideField"
|
||||
decorate_activityTargets_from = "@nestjs/graphql"
|
||||
decorate_activityTargets_arguments = "[]"
|
||||
|
||||
// CommentThread: Only Allow targets createOrConnect / createMany
|
||||
// User Settings: Only Allow targets createOrConnect / createMany
|
||||
decorate_userSettings_type = "*UserSettingsUpdateOneRequiredWithoutUserNestedInput"
|
||||
decorate_userSettings_field = "!(update)"
|
||||
decorate_userSettings_name = "HideField"
|
||||
@ -106,10 +106,10 @@ model User {
|
||||
refreshTokens RefreshToken[]
|
||||
comments Comment[]
|
||||
|
||||
authoredCommentThreads CommentThread[] @relation(name: "authoredCommentThreads")
|
||||
assignedCommentThreads CommentThread[] @relation(name: "assignedCommentThreads")
|
||||
settings UserSettings @relation(fields: [settingsId], references: [id])
|
||||
settingsId String @unique
|
||||
authoredActivities Activity[] @relation(name: "authoredActivities")
|
||||
assignedActivities Activity[] @relation(name: "assignedActivities")
|
||||
settings UserSettings @relation(fields: [settingsId], references: [id])
|
||||
settingsId String @unique
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
@ -164,20 +164,20 @@ model Workspace {
|
||||
workspaceMember WorkspaceMember[]
|
||||
companies Company[]
|
||||
people Person[]
|
||||
commentThreads CommentThread[]
|
||||
activities Activity[]
|
||||
comments Comment[]
|
||||
pipelines Pipeline[]
|
||||
pipelineStages PipelineStage[]
|
||||
pipelineProgresses PipelineProgress[]
|
||||
activityTargets ActivityTarget[]
|
||||
viewFields ViewField[]
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
Attachment Attachment[]
|
||||
CommentThreadTarget CommentThreadTarget[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
Attachment Attachment[]
|
||||
|
||||
@@map("workspaces")
|
||||
}
|
||||
@ -234,8 +234,9 @@ model Company {
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ActivityTarget ActivityTarget[]
|
||||
|
||||
@@map("companies")
|
||||
}
|
||||
@ -277,8 +278,9 @@ model Person {
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ActivityTarget ActivityTarget[]
|
||||
|
||||
@@map("people")
|
||||
}
|
||||
@ -311,30 +313,28 @@ enum ActivityType {
|
||||
Task
|
||||
}
|
||||
|
||||
model CommentThread {
|
||||
model Activity {
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
id String @id @default(uuid())
|
||||
|
||||
commentThreadTargets CommentThreadTarget[]
|
||||
comments Comment[]
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
|
||||
authorId String
|
||||
author User @relation(fields: [authorId], references: [id], name: "authoredCommentThreads")
|
||||
|
||||
body String?
|
||||
title String?
|
||||
type ActivityType @default(Note)
|
||||
|
||||
id String @id @default(uuid())
|
||||
body String?
|
||||
title String?
|
||||
type ActivityType @default(Note)
|
||||
reminderAt DateTime?
|
||||
dueAt DateTime?
|
||||
completedAt DateTime?
|
||||
assignee User? @relation(fields: [assigneeId], references: [id], name: "assignedCommentThreads")
|
||||
assigneeId String?
|
||||
|
||||
activityTargets ActivityTarget[]
|
||||
comments Comment[]
|
||||
attachments Attachment[]
|
||||
author User @relation(fields: [authorId], references: [id], name: "authoredActivities")
|
||||
authorId String
|
||||
assignee User? @relation(fields: [assigneeId], references: [id], name: "assignedActivities")
|
||||
assigneeId String?
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
@ -342,9 +342,12 @@ model CommentThread {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
attachments Attachment[]
|
||||
@@map("activities")
|
||||
}
|
||||
|
||||
@@map("comment_threads")
|
||||
enum CommentableType {
|
||||
Person
|
||||
Company
|
||||
}
|
||||
|
||||
model Comment {
|
||||
@ -354,12 +357,13 @@ model Comment {
|
||||
/// @Validator.IsString()
|
||||
body String
|
||||
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId String
|
||||
commentThread CommentThread @relation(fields: [commentThreadId], references: [id], onDelete: Cascade)
|
||||
activity Activity? @relation(fields: [activityId], references: [id], onDelete: Cascade)
|
||||
activityId String?
|
||||
commentThreadId String
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
|
||||
@ -372,24 +376,25 @@ model Comment {
|
||||
@@map("comments")
|
||||
}
|
||||
|
||||
enum CommentableType {
|
||||
Person
|
||||
Company
|
||||
}
|
||||
|
||||
model CommentThreadTarget {
|
||||
model ActivityTarget {
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
id String @id @default(uuid())
|
||||
|
||||
commentThread CommentThread @relation(fields: [commentThreadId], references: [id], onDelete: Cascade)
|
||||
commentThreadId String
|
||||
/// @TypeGraphQL.omit(input: true, output: false)
|
||||
workspace Workspace? @relation(fields: [workspaceId], references: [id])
|
||||
activity Activity @relation(fields: [activityId], references: [id], onDelete: Cascade)
|
||||
activityId String
|
||||
commentableType CommentableType?
|
||||
commentableId String?
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String?
|
||||
commentableType CommentableType
|
||||
commentableId String
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
|
||||
personId String?
|
||||
person Person? @relation(fields: [personId], references: [id])
|
||||
|
||||
companyId String?
|
||||
company Company? @relation(fields: [companyId], references: [id])
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
@ -397,7 +402,7 @@ model CommentThreadTarget {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@map("comment_thread_targets")
|
||||
@@map("activity_targets")
|
||||
}
|
||||
|
||||
model Pipeline {
|
||||
@ -515,17 +520,16 @@ model Attachment {
|
||||
type AttachmentType
|
||||
name String
|
||||
|
||||
authorId String
|
||||
author User @relation(fields: [authorId], references: [id], name: "authoredAttachments")
|
||||
|
||||
activityId String
|
||||
activity CommentThread @relation(fields: [activityId], references: [id])
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: false)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
|
||||
author User @relation(fields: [authorId], references: [id], name: "authoredAttachments")
|
||||
authorId String
|
||||
activity Activity @relation(fields: [activityId], references: [id])
|
||||
activityId String
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: false)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
export const seedComments = async (prisma: PrismaClient) => {
|
||||
await prisma.commentThread.upsert({
|
||||
await prisma.activity.upsert({
|
||||
where: { id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400' },
|
||||
update: {},
|
||||
create: {
|
||||
@ -13,15 +13,15 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.commentThreadTarget.upsert({
|
||||
await prisma.activityTarget.upsert({
|
||||
where: { id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb600' },
|
||||
update: {},
|
||||
create: {
|
||||
id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb600',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
commentableType: 'Company',
|
||||
commentableId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
commentThreadId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
|
||||
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
},
|
||||
});
|
||||
|
||||
@ -32,6 +32,7 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb200',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
body: 'Hi Félix ! How do you like your Twenty workspace?',
|
||||
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
|
||||
commentThreadId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
|
||||
authorId: 'twenty-ge256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
},
|
||||
@ -44,12 +45,13 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
id: 'twenty-fe256b40-3ec3-4fe3-8997-b76aa0bfb200',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
body: 'I love it!',
|
||||
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
|
||||
commentThreadId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
|
||||
authorId: 'twenty-gk256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.commentThread.upsert({
|
||||
await prisma.activity.upsert({
|
||||
where: { id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfc408' },
|
||||
update: {},
|
||||
create: {
|
||||
@ -64,15 +66,15 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.commentThreadTarget.upsert({
|
||||
await prisma.activityTarget.upsert({
|
||||
where: { id: 'twenty-fe256b39-3ec3-4fe3-8997-a76aa0bfb600' },
|
||||
update: {},
|
||||
create: {
|
||||
id: 'twenty-fe256b39-3ec3-4fe3-8997-a76aa0bfb600',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
commentableType: 'Person',
|
||||
commentableId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
|
||||
commentThreadId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfc408',
|
||||
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfc408',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
},
|
||||
});
|
||||
|
||||
@ -83,12 +85,13 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb100',
|
||||
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
body: 'I really like this comment thread feature!',
|
||||
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfc408',
|
||||
commentThreadId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfc408',
|
||||
authorId: 'twenty-ge256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.commentThread.upsert({
|
||||
await prisma.activity.upsert({
|
||||
where: { id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aaabfb408' },
|
||||
update: {},
|
||||
create: {
|
||||
@ -100,15 +103,15 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.commentThreadTarget.upsert({
|
||||
await prisma.activityTarget.upsert({
|
||||
where: { id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-a76aa0bfba00' },
|
||||
update: {},
|
||||
create: {
|
||||
id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-a76aa0bfba00',
|
||||
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
|
||||
commentableType: 'Company',
|
||||
commentableId: 'twenty-dev-a674fa6c-1455-4c57-afaf-dd5dc086361e',
|
||||
commentThreadId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aaabfb408',
|
||||
activityId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aaabfb408',
|
||||
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
|
||||
},
|
||||
});
|
||||
|
||||
@ -119,6 +122,7 @@ export const seedComments = async (prisma: PrismaClient) => {
|
||||
id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aa0bfb000',
|
||||
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
|
||||
body: 'I really like this comment thread feature!',
|
||||
activityId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aaabfb408',
|
||||
commentThreadId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aaabfb408',
|
||||
authorId: 'twenty-dev-gk256b39-3ec3-4fe3-8997-b76aa0boa408',
|
||||
},
|
||||
|
||||
@ -9,9 +9,9 @@ export type ModelSelectMap = {
|
||||
Company: Prisma.CompanySelect;
|
||||
Person: Prisma.PersonSelect;
|
||||
RefreshToken: Prisma.RefreshTokenSelect;
|
||||
CommentThread: Prisma.CommentThreadSelect;
|
||||
Activity: Prisma.ActivitySelect;
|
||||
Comment: Prisma.CommentSelect;
|
||||
CommentThreadTarget: Prisma.CommentThreadTargetSelect;
|
||||
ActivityTarget: Prisma.ActivityTargetSelect;
|
||||
Pipeline: Prisma.PipelineSelect;
|
||||
PipelineStage: Prisma.PipelineStageSelect;
|
||||
PipelineProgress: Prisma.PipelineProgressSelect;
|
||||
|
||||
Reference in New Issue
Block a user