mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-23 03:51:36 +03:00
feat: create ViewField model (#961)
* feat: create ViewField model - Created ViewField prisma model - Added ViewField server resolvers for findMany/updateOne - Added getViewFields/updateViewField graphql queries Closes #849 * chore: update node version in .nvmrc files
This commit is contained in:
parent
e90f44bbfb
commit
9027406fdf
@ -1 +1 @@
|
||||
18.6.0
|
||||
18.16.0
|
@ -293,7 +293,7 @@ export type CommentThreadTarget = {
|
||||
createdAt: Scalars['DateTime'];
|
||||
id: Scalars['ID'];
|
||||
updatedAt: Scalars['DateTime'];
|
||||
workspace: Workspace;
|
||||
workspace?: Maybe<Workspace>;
|
||||
};
|
||||
|
||||
export type CommentThreadTargetCreateManyCommentThreadInput = {
|
||||
@ -712,6 +712,17 @@ export enum FileFolder {
|
||||
WorkspaceLogo = 'WorkspaceLogo'
|
||||
}
|
||||
|
||||
export type IntFilter = {
|
||||
equals?: InputMaybe<Scalars['Int']>;
|
||||
gt?: InputMaybe<Scalars['Int']>;
|
||||
gte?: InputMaybe<Scalars['Int']>;
|
||||
in?: InputMaybe<Array<Scalars['Int']>>;
|
||||
lt?: InputMaybe<Scalars['Int']>;
|
||||
lte?: InputMaybe<Scalars['Int']>;
|
||||
not?: InputMaybe<NestedIntFilter>;
|
||||
notIn?: InputMaybe<Array<Scalars['Int']>>;
|
||||
};
|
||||
|
||||
export type IntNullableFilter = {
|
||||
equals?: InputMaybe<Scalars['Int']>;
|
||||
gt?: InputMaybe<Scalars['Int']>;
|
||||
@ -765,6 +776,7 @@ export type Mutation = {
|
||||
updateOnePerson?: Maybe<Person>;
|
||||
updateOnePipelineProgress?: Maybe<PipelineProgress>;
|
||||
updateOnePipelineStage?: Maybe<PipelineStage>;
|
||||
updateOneViewField: ViewField;
|
||||
updateUser: User;
|
||||
updateWorkspace: Workspace;
|
||||
uploadAttachment: Scalars['String'];
|
||||
@ -880,6 +892,12 @@ export type MutationUpdateOnePipelineStageArgs = {
|
||||
};
|
||||
|
||||
|
||||
export type MutationUpdateOneViewFieldArgs = {
|
||||
data: ViewFieldUpdateInput;
|
||||
where: ViewFieldWhereUniqueInput;
|
||||
};
|
||||
|
||||
|
||||
export type MutationUpdateUserArgs = {
|
||||
data: UserUpdateInput;
|
||||
where: UserWhereUniqueInput;
|
||||
@ -985,6 +1003,17 @@ export type NestedEnumPipelineProgressableTypeFilter = {
|
||||
notIn?: InputMaybe<Array<PipelineProgressableType>>;
|
||||
};
|
||||
|
||||
export type NestedIntFilter = {
|
||||
equals?: InputMaybe<Scalars['Int']>;
|
||||
gt?: InputMaybe<Scalars['Int']>;
|
||||
gte?: InputMaybe<Scalars['Int']>;
|
||||
in?: InputMaybe<Array<Scalars['Int']>>;
|
||||
lt?: InputMaybe<Scalars['Int']>;
|
||||
lte?: InputMaybe<Scalars['Int']>;
|
||||
not?: InputMaybe<NestedIntFilter>;
|
||||
notIn?: InputMaybe<Array<Scalars['Int']>>;
|
||||
};
|
||||
|
||||
export type NestedIntNullableFilter = {
|
||||
equals?: InputMaybe<Scalars['Int']>;
|
||||
gt?: InputMaybe<Scalars['Int']>;
|
||||
@ -1500,6 +1529,7 @@ export type Query = {
|
||||
findManyPipelineProgress: Array<PipelineProgress>;
|
||||
findManyPipelineStage: Array<PipelineStage>;
|
||||
findManyUser: Array<User>;
|
||||
findManyViewField: Array<ViewField>;
|
||||
findManyWorkspaceMember: Array<WorkspaceMember>;
|
||||
findUniqueCompany: Company;
|
||||
findUniquePerson: Person;
|
||||
@ -1586,6 +1616,16 @@ export type QueryFindManyUserArgs = {
|
||||
};
|
||||
|
||||
|
||||
export type QueryFindManyViewFieldArgs = {
|
||||
cursor?: InputMaybe<ViewFieldWhereUniqueInput>;
|
||||
distinct?: InputMaybe<Array<ViewFieldScalarFieldEnum>>;
|
||||
orderBy?: InputMaybe<Array<ViewFieldOrderByWithRelationInput>>;
|
||||
skip?: InputMaybe<Scalars['Int']>;
|
||||
take?: InputMaybe<Scalars['Int']>;
|
||||
where?: InputMaybe<ViewFieldWhereInput>;
|
||||
};
|
||||
|
||||
|
||||
export type QueryFindManyWorkspaceMemberArgs = {
|
||||
cursor?: InputMaybe<WorkspaceMemberWhereUniqueInput>;
|
||||
distinct?: InputMaybe<Array<WorkspaceMemberScalarFieldEnum>>;
|
||||
@ -1867,6 +1907,66 @@ export type Verify = {
|
||||
user: User;
|
||||
};
|
||||
|
||||
export type ViewField = {
|
||||
__typename?: 'ViewField';
|
||||
fieldName: Scalars['String'];
|
||||
id: Scalars['ID'];
|
||||
index: Scalars['Int'];
|
||||
isVisible: Scalars['Boolean'];
|
||||
objectName: Scalars['String'];
|
||||
sizeInPx: Scalars['Int'];
|
||||
};
|
||||
|
||||
export type ViewFieldOrderByWithRelationInput = {
|
||||
fieldName?: InputMaybe<SortOrder>;
|
||||
id?: InputMaybe<SortOrder>;
|
||||
index?: InputMaybe<SortOrder>;
|
||||
isVisible?: InputMaybe<SortOrder>;
|
||||
objectName?: InputMaybe<SortOrder>;
|
||||
sizeInPx?: InputMaybe<SortOrder>;
|
||||
};
|
||||
|
||||
export enum ViewFieldScalarFieldEnum {
|
||||
FieldName = 'fieldName',
|
||||
Id = 'id',
|
||||
Index = 'index',
|
||||
IsVisible = 'isVisible',
|
||||
ObjectName = 'objectName',
|
||||
SizeInPx = 'sizeInPx',
|
||||
WorkspaceId = 'workspaceId'
|
||||
}
|
||||
|
||||
export type ViewFieldUpdateInput = {
|
||||
fieldName?: InputMaybe<Scalars['String']>;
|
||||
id?: InputMaybe<Scalars['String']>;
|
||||
index?: InputMaybe<Scalars['Int']>;
|
||||
isVisible?: InputMaybe<Scalars['Boolean']>;
|
||||
objectName?: InputMaybe<Scalars['String']>;
|
||||
sizeInPx?: InputMaybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
export type ViewFieldUpdateManyWithoutWorkspaceNestedInput = {
|
||||
connect?: InputMaybe<Array<ViewFieldWhereUniqueInput>>;
|
||||
disconnect?: InputMaybe<Array<ViewFieldWhereUniqueInput>>;
|
||||
set?: InputMaybe<Array<ViewFieldWhereUniqueInput>>;
|
||||
};
|
||||
|
||||
export type ViewFieldWhereInput = {
|
||||
AND?: InputMaybe<Array<ViewFieldWhereInput>>;
|
||||
NOT?: InputMaybe<Array<ViewFieldWhereInput>>;
|
||||
OR?: InputMaybe<Array<ViewFieldWhereInput>>;
|
||||
fieldName?: InputMaybe<StringFilter>;
|
||||
id?: InputMaybe<StringFilter>;
|
||||
index?: InputMaybe<IntFilter>;
|
||||
isVisible?: InputMaybe<BoolFilter>;
|
||||
objectName?: InputMaybe<StringFilter>;
|
||||
sizeInPx?: InputMaybe<IntFilter>;
|
||||
};
|
||||
|
||||
export type ViewFieldWhereUniqueInput = {
|
||||
id?: InputMaybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type Workspace = {
|
||||
__typename?: 'Workspace';
|
||||
Attachment?: Maybe<Array<Attachment>>;
|
||||
@ -1885,6 +1985,7 @@ export type Workspace = {
|
||||
pipelineStages?: Maybe<Array<PipelineStage>>;
|
||||
pipelines?: Maybe<Array<Pipeline>>;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
viewFields?: Maybe<Array<ViewField>>;
|
||||
workspaceMember?: Maybe<Array<WorkspaceMember>>;
|
||||
};
|
||||
|
||||
@ -1959,6 +2060,7 @@ export type WorkspaceUpdateInput = {
|
||||
pipelineStages?: InputMaybe<PipelineStageUpdateManyWithoutWorkspaceNestedInput>;
|
||||
pipelines?: InputMaybe<PipelineUpdateManyWithoutWorkspaceNestedInput>;
|
||||
updatedAt?: InputMaybe<Scalars['DateTime']>;
|
||||
viewFields?: InputMaybe<ViewFieldUpdateManyWithoutWorkspaceNestedInput>;
|
||||
workspaceMember?: InputMaybe<WorkspaceMemberUpdateManyWithoutWorkspaceNestedInput>;
|
||||
};
|
||||
|
||||
@ -2342,6 +2444,21 @@ export type RemoveProfilePictureMutationVariables = Exact<{
|
||||
|
||||
export type RemoveProfilePictureMutation = { __typename?: 'Mutation', updateUser: { __typename?: 'User', id: string, avatarUrl?: string | null } };
|
||||
|
||||
export type GetViewFieldsQueryVariables = Exact<{
|
||||
where?: InputMaybe<ViewFieldWhereInput>;
|
||||
}>;
|
||||
|
||||
|
||||
export type GetViewFieldsQuery = { __typename?: 'Query', viewFields: Array<{ __typename?: 'ViewField', id: string, fieldName: string, isVisible: boolean, sizeInPx: number, index: number }> };
|
||||
|
||||
export type UpdateViewFieldMutationVariables = Exact<{
|
||||
data: ViewFieldUpdateInput;
|
||||
where: ViewFieldWhereUniqueInput;
|
||||
}>;
|
||||
|
||||
|
||||
export type UpdateViewFieldMutation = { __typename?: 'Mutation', updateOneViewField: { __typename?: 'ViewField', id: string, fieldName: string, isVisible: boolean, sizeInPx: number, index: number } };
|
||||
|
||||
export type GetWorkspaceMembersQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
@ -4470,6 +4587,83 @@ export function useRemoveProfilePictureMutation(baseOptions?: Apollo.MutationHoo
|
||||
export type RemoveProfilePictureMutationHookResult = ReturnType<typeof useRemoveProfilePictureMutation>;
|
||||
export type RemoveProfilePictureMutationResult = Apollo.MutationResult<RemoveProfilePictureMutation>;
|
||||
export type RemoveProfilePictureMutationOptions = Apollo.BaseMutationOptions<RemoveProfilePictureMutation, RemoveProfilePictureMutationVariables>;
|
||||
export const GetViewFieldsDocument = gql`
|
||||
query GetViewFields($where: ViewFieldWhereInput) {
|
||||
viewFields: findManyViewField(where: $where) {
|
||||
id
|
||||
fieldName
|
||||
isVisible
|
||||
sizeInPx
|
||||
index
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useGetViewFieldsQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useGetViewFieldsQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useGetViewFieldsQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useGetViewFieldsQuery({
|
||||
* variables: {
|
||||
* where: // value for 'where'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useGetViewFieldsQuery(baseOptions?: Apollo.QueryHookOptions<GetViewFieldsQuery, GetViewFieldsQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<GetViewFieldsQuery, GetViewFieldsQueryVariables>(GetViewFieldsDocument, options);
|
||||
}
|
||||
export function useGetViewFieldsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetViewFieldsQuery, GetViewFieldsQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<GetViewFieldsQuery, GetViewFieldsQueryVariables>(GetViewFieldsDocument, options);
|
||||
}
|
||||
export type GetViewFieldsQueryHookResult = ReturnType<typeof useGetViewFieldsQuery>;
|
||||
export type GetViewFieldsLazyQueryHookResult = ReturnType<typeof useGetViewFieldsLazyQuery>;
|
||||
export type GetViewFieldsQueryResult = Apollo.QueryResult<GetViewFieldsQuery, GetViewFieldsQueryVariables>;
|
||||
export const UpdateViewFieldDocument = gql`
|
||||
mutation UpdateViewField($data: ViewFieldUpdateInput!, $where: ViewFieldWhereUniqueInput!) {
|
||||
updateOneViewField(data: $data, where: $where) {
|
||||
id
|
||||
fieldName
|
||||
isVisible
|
||||
sizeInPx
|
||||
index
|
||||
}
|
||||
}
|
||||
`;
|
||||
export type UpdateViewFieldMutationFn = Apollo.MutationFunction<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>;
|
||||
|
||||
/**
|
||||
* __useUpdateViewFieldMutation__
|
||||
*
|
||||
* To run a mutation, you first call `useUpdateViewFieldMutation` within a React component and pass it any options that fit your needs.
|
||||
* When your component renders, `useUpdateViewFieldMutation` returns a tuple that includes:
|
||||
* - A mutate function that you can call at any time to execute the mutation
|
||||
* - An object with fields that represent the current status of the mutation's execution
|
||||
*
|
||||
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
|
||||
*
|
||||
* @example
|
||||
* const [updateViewFieldMutation, { data, loading, error }] = useUpdateViewFieldMutation({
|
||||
* variables: {
|
||||
* data: // value for 'data'
|
||||
* where: // value for 'where'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useUpdateViewFieldMutation(baseOptions?: Apollo.MutationHookOptions<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useMutation<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>(UpdateViewFieldDocument, options);
|
||||
}
|
||||
export type UpdateViewFieldMutationHookResult = ReturnType<typeof useUpdateViewFieldMutation>;
|
||||
export type UpdateViewFieldMutationResult = Apollo.MutationResult<UpdateViewFieldMutation>;
|
||||
export type UpdateViewFieldMutationOptions = Apollo.BaseMutationOptions<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>;
|
||||
export const GetWorkspaceMembersDocument = gql`
|
||||
query GetWorkspaceMembers {
|
||||
workspaceMembers: findManyWorkspaceMember {
|
||||
|
13
front/src/modules/views/queries/select.ts
Normal file
13
front/src/modules/views/queries/select.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_VIEW_FIELDS = gql`
|
||||
query GetViewFields($where: ViewFieldWhereInput) {
|
||||
viewFields: findManyViewField(where: $where) {
|
||||
id
|
||||
fieldName
|
||||
isVisible
|
||||
sizeInPx
|
||||
index
|
||||
}
|
||||
}
|
||||
`;
|
16
front/src/modules/views/queries/update.ts
Normal file
16
front/src/modules/views/queries/update.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const UPDATE_VIEW_FIELD = gql`
|
||||
mutation UpdateViewField(
|
||||
$data: ViewFieldUpdateInput!
|
||||
$where: ViewFieldWhereUniqueInput!
|
||||
) {
|
||||
updateOneViewField(data: $data, where: $where) {
|
||||
id
|
||||
fieldName
|
||||
isVisible
|
||||
sizeInPx
|
||||
index
|
||||
}
|
||||
}
|
||||
`;
|
@ -1 +1 @@
|
||||
18.10.0
|
||||
18.16.0
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
PipelineProgress,
|
||||
Attachment,
|
||||
UserSettings,
|
||||
ViewField,
|
||||
} from '@prisma/client';
|
||||
|
||||
import { AbilityAction } from './ability.action';
|
||||
@ -36,6 +37,7 @@ type SubjectsAbility = Subjects<{
|
||||
PipelineProgress: PipelineProgress;
|
||||
Attachment: Attachment;
|
||||
UserSettings: UserSettings;
|
||||
ViewField: ViewField;
|
||||
}>;
|
||||
|
||||
export type AppAbility = PureAbility<
|
||||
@ -128,6 +130,10 @@ export class AbilityFactory {
|
||||
workspaceId: workspace.id,
|
||||
});
|
||||
|
||||
// ViewField
|
||||
can(AbilityAction.Read, 'ViewField', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Update, 'ViewField', { workspaceId: workspace.id });
|
||||
|
||||
return build();
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,10 @@ import {
|
||||
ReadAttachmentAbilityHandler,
|
||||
UpdateAttachmentAbilityHandler,
|
||||
} from './handlers/attachment.ability-handler';
|
||||
import {
|
||||
ReadViewFieldAbilityHandler,
|
||||
UpdateViewFieldAbilityHandler,
|
||||
} from './handlers/view-field.ability-handler';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@ -178,6 +182,9 @@ import {
|
||||
CreatePipelineProgressAbilityHandler,
|
||||
UpdatePipelineProgressAbilityHandler,
|
||||
DeletePipelineProgressAbilityHandler,
|
||||
// ViewField
|
||||
ReadViewFieldAbilityHandler,
|
||||
UpdateViewFieldAbilityHandler,
|
||||
],
|
||||
exports: [
|
||||
AbilityFactory,
|
||||
@ -259,6 +266,9 @@ import {
|
||||
CreatePipelineProgressAbilityHandler,
|
||||
UpdatePipelineProgressAbilityHandler,
|
||||
DeletePipelineProgressAbilityHandler,
|
||||
// ViewField
|
||||
ReadViewFieldAbilityHandler,
|
||||
UpdateViewFieldAbilityHandler,
|
||||
],
|
||||
})
|
||||
export class AbilityModule {}
|
||||
|
56
server/src/ability/handlers/view-field.ability-handler.ts
Normal file
56
server/src/ability/handlers/view-field.ability-handler.ts
Normal file
@ -0,0 +1,56 @@
|
||||
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 { AbilityAction } from 'src/ability/ability.action';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { relationAbilityChecker } from 'src/ability/ability.util';
|
||||
import { ViewFieldWhereInput } from 'src/core/@generated/view-field/view-field-where.input';
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { assert } from 'src/utils/assert';
|
||||
|
||||
class ViewFieldArgs {
|
||||
where?: ViewFieldWhereInput;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ReadViewFieldAbilityHandler implements IAbilityHandler {
|
||||
handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Read, 'ViewField');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateViewFieldAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<ViewFieldArgs>();
|
||||
const viewField = await this.prismaService.client.viewField.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(viewField, '', NotFoundException);
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'ViewField',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(AbilityAction.Update, subject('ViewField', viewField));
|
||||
}
|
||||
}
|
@ -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 { ViewModule } from './view/view.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -25,6 +26,7 @@ import { AttachmentModule } from './attachment/attachment.module';
|
||||
FileModule,
|
||||
ClientConfigModule,
|
||||
AttachmentModule,
|
||||
ViewModule,
|
||||
],
|
||||
exports: [
|
||||
AuthModule,
|
||||
|
32
server/src/core/view/resolvers/view-field.resolver.spec.ts
Normal file
32
server/src/core/view/resolvers/view-field.resolver.spec.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { ViewFieldService } from 'src/core/view/services/view-field.service';
|
||||
|
||||
import { ViewFieldResolver } from './view-field.resolver';
|
||||
import { AbilityFactory } from 'src/ability/ability.factory';
|
||||
|
||||
describe('ViewFieldResolver', () => {
|
||||
let resolver: ViewFieldResolver;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ViewFieldResolver,
|
||||
{
|
||||
provide: ViewFieldService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: AbilityFactory,
|
||||
useValue: {},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
resolver = module.get<ViewFieldResolver>(ViewFieldResolver);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(resolver).toBeDefined();
|
||||
});
|
||||
});
|
68
server/src/core/view/resolvers/view-field.resolver.ts
Normal file
68
server/src/core/view/resolvers/view-field.resolver.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { accessibleBy } from '@casl/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import {
|
||||
ReadViewFieldAbilityHandler,
|
||||
UpdateViewFieldAbilityHandler,
|
||||
} from 'src/ability/handlers/view-field.ability-handler';
|
||||
import { FindManyViewFieldArgs } from 'src/core/@generated/view-field/find-many-view-field.args';
|
||||
import { UpdateOneViewFieldArgs } from 'src/core/@generated/view-field/update-one-view-field.args';
|
||||
import { ViewField } from 'src/core/@generated/view-field/view-field.model';
|
||||
import { ViewFieldService } from 'src/core/view/services/view-field.service';
|
||||
import { CheckAbilities } from 'src/decorators/check-abilities.decorator';
|
||||
import {
|
||||
PrismaSelect,
|
||||
PrismaSelector,
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { UserAbility } from 'src/decorators/user-ability.decorator';
|
||||
import { AbilityGuard } from 'src/guards/ability.guard';
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => ViewField)
|
||||
export class ViewFieldResolver {
|
||||
constructor(private readonly viewFieldService: ViewFieldService) {}
|
||||
|
||||
@Query(() => [ViewField])
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(ReadViewFieldAbilityHandler)
|
||||
async findManyViewField(
|
||||
@Args() args: FindManyViewFieldArgs,
|
||||
@UserAbility() ability: AppAbility,
|
||||
@PrismaSelector({ modelName: 'ViewField' })
|
||||
prismaSelect: PrismaSelect<'ViewField'>,
|
||||
): Promise<Partial<ViewField>[]> {
|
||||
return this.viewFieldService.findMany({
|
||||
where: args.where
|
||||
? {
|
||||
AND: [args.where, accessibleBy(ability).ViewField],
|
||||
}
|
||||
: accessibleBy(ability).ViewField,
|
||||
orderBy: args.orderBy,
|
||||
cursor: args.cursor,
|
||||
take: args.take,
|
||||
skip: args.skip,
|
||||
distinct: args.distinct,
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
}
|
||||
|
||||
@Mutation(() => ViewField)
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(UpdateViewFieldAbilityHandler)
|
||||
async updateOneViewField(
|
||||
@Args() args: UpdateOneViewFieldArgs,
|
||||
@PrismaSelector({ modelName: 'ViewField' })
|
||||
prismaSelect: PrismaSelect<'ViewField'>,
|
||||
) {
|
||||
return this.viewFieldService.update({
|
||||
where: args.where,
|
||||
data: args.data,
|
||||
select: prismaSelect.value,
|
||||
} as Prisma.ViewFieldUpdateArgs);
|
||||
}
|
||||
}
|
28
server/src/core/view/services/view-field.service.spec.ts
Normal file
28
server/src/core/view/services/view-field.service.spec.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { prismaMock } from 'src/database/client-mock/jest-prisma-singleton';
|
||||
|
||||
import { ViewFieldService } from './view-field.service';
|
||||
|
||||
describe('ViewFieldService', () => {
|
||||
let service: ViewFieldService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ViewFieldService,
|
||||
{
|
||||
provide: PrismaService,
|
||||
useValue: prismaMock,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ViewFieldService>(ViewFieldService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
39
server/src/core/view/services/view-field.service.ts
Normal file
39
server/src/core/view/services/view-field.service.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class ViewFieldService {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
// Find
|
||||
findFirst = this.prismaService.client.viewField.findFirst;
|
||||
findFirstOrThrow = this.prismaService.client.viewField.findFirstOrThrow;
|
||||
|
||||
findUnique = this.prismaService.client.viewField.findUnique;
|
||||
findUniqueOrThrow = this.prismaService.client.viewField.findUniqueOrThrow;
|
||||
|
||||
findMany = this.prismaService.client.viewField.findMany;
|
||||
|
||||
// Create
|
||||
create = this.prismaService.client.viewField.create;
|
||||
createMany = this.prismaService.client.viewField.createMany;
|
||||
|
||||
// Update
|
||||
update = this.prismaService.client.viewField.update;
|
||||
upsert = this.prismaService.client.viewField.upsert;
|
||||
updateMany = this.prismaService.client.viewField.updateMany;
|
||||
|
||||
// Delete
|
||||
delete = this.prismaService.client.viewField.delete;
|
||||
deleteMany = this.prismaService.client.viewField.deleteMany;
|
||||
|
||||
// Aggregate
|
||||
aggregate = this.prismaService.client.viewField.aggregate;
|
||||
|
||||
// Count
|
||||
count = this.prismaService.client.viewField.count;
|
||||
|
||||
// GroupBy
|
||||
groupBy = this.prismaService.client.viewField.groupBy;
|
||||
}
|
9
server/src/core/view/view.module.ts
Normal file
9
server/src/core/view/view.module.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { ViewFieldService } from './services/view-field.service';
|
||||
import { ViewFieldResolver } from './resolvers/view-field.resolver';
|
||||
|
||||
@Module({
|
||||
providers: [ViewFieldService, ViewFieldResolver],
|
||||
})
|
||||
export class ViewModule {}
|
@ -0,0 +1,15 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "viewFields" (
|
||||
"id" TEXT NOT NULL,
|
||||
"fieldName" TEXT NOT NULL,
|
||||
"index" INTEGER NOT NULL,
|
||||
"isVisible" BOOLEAN NOT NULL,
|
||||
"objectName" TEXT NOT NULL,
|
||||
"sizeInPx" INTEGER NOT NULL,
|
||||
"workspaceId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "viewFields_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "viewFields" ADD CONSTRAINT "viewFields_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -169,6 +169,7 @@ model Workspace {
|
||||
pipelines Pipeline[]
|
||||
pipelineStages PipelineStage[]
|
||||
pipelineProgresses PipelineProgress[]
|
||||
viewFields ViewField[]
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
@ -532,3 +533,22 @@ model Attachment {
|
||||
|
||||
@@map("attachments")
|
||||
}
|
||||
|
||||
model ViewField {
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
id String @id @default(uuid())
|
||||
|
||||
fieldName String
|
||||
index Int
|
||||
isVisible Boolean
|
||||
objectName String
|
||||
sizeInPx Int
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
|
||||
@@map("viewFields")
|
||||
}
|
||||
|
@ -16,4 +16,5 @@ export type ModelSelectMap = {
|
||||
PipelineStage: Prisma.PipelineStageSelect;
|
||||
PipelineProgress: Prisma.PipelineProgressSelect;
|
||||
Attachment: Prisma.AttachmentSelect;
|
||||
ViewField: Prisma.ViewFieldSelect;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user