1721/feature/drag and drop favorites (#2097)
* prisma schema updated: added index in favorite * update abilitiy added for favorite * update one favorite resolver added * update on favorite mutation added * updateFavoriteOrder added * Draglist added in favorite * nav item convert to div from button: because it was not working dragable with button * changed index to position * position added in getFavorites query * added recoil state for favorites * reordering updated according to new method * Use accurate type --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -201,6 +201,7 @@ export class AbilityFactory {
|
||||
// Favorite
|
||||
can(AbilityAction.Read, 'Favorite', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'Favorite');
|
||||
can(AbilityAction.Update, 'Favorite', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Delete, 'Favorite', { workspaceId: workspace.id });
|
||||
|
||||
return build();
|
||||
|
||||
@ -103,6 +103,7 @@ import {
|
||||
CreateFavoriteAbilityHandler,
|
||||
ReadFavoriteAbilityHandler,
|
||||
DeleteFavoriteAbilityHandler,
|
||||
UpdateFavoriteAbilityHandler,
|
||||
} from './handlers/favorite.ability-handler';
|
||||
import {
|
||||
CreateViewSortAbilityHandler,
|
||||
@ -219,6 +220,7 @@ import {
|
||||
//Favorite
|
||||
ReadFavoriteAbilityHandler,
|
||||
CreateFavoriteAbilityHandler,
|
||||
UpdateFavoriteAbilityHandler,
|
||||
DeleteFavoriteAbilityHandler,
|
||||
// View
|
||||
ReadViewAbilityHandler,
|
||||
|
||||
@ -57,6 +57,34 @@ export class CreateFavoriteAbilityHandler implements IAbilityHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateFavoriteAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<FavoriteArgs>();
|
||||
|
||||
const favorite = await this.prismaService.client.favorite.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(favorite, '', NotFoundException);
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'Favorite',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(AbilityAction.Update, 'Favorite');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteFavoriteAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
@ -17,21 +17,28 @@ import {
|
||||
CreateFavoriteAbilityHandler,
|
||||
DeleteFavoriteAbilityHandler,
|
||||
ReadFavoriteAbilityHandler,
|
||||
UpdateFavoriteAbilityHandler,
|
||||
} from 'src/ability/handlers/favorite.ability-handler';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import { FavoriteService } from 'src/core/favorite/services/favorite.service';
|
||||
import { FavoriteWhereInput } from 'src/core/@generated/favorite/favorite-where.input';
|
||||
import { SortOrder } from 'src/core/@generated/prisma/sort-order.enum';
|
||||
import { UpdateOneFavoriteArgs } from 'src/core/@generated/favorite/update-one-favorite.args';
|
||||
|
||||
@InputType()
|
||||
class FavoriteMutationForPersonArgs {
|
||||
@Field(() => String)
|
||||
personId: string;
|
||||
@Field(() => Number)
|
||||
position: number;
|
||||
}
|
||||
|
||||
@InputType()
|
||||
class FavoriteMutationForCompanyArgs {
|
||||
@Field(() => String)
|
||||
companyId: string;
|
||||
@Field(() => Number)
|
||||
position: number;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -49,6 +56,7 @@ export class FavoriteResolver {
|
||||
where: {
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
orderBy: [{ position: SortOrder.asc }],
|
||||
include: {
|
||||
person: true,
|
||||
company: {
|
||||
@ -86,6 +94,7 @@ export class FavoriteResolver {
|
||||
connect: { id: args.personId },
|
||||
},
|
||||
workspaceId: workspace.id,
|
||||
position: args.position,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
@ -115,11 +124,29 @@ export class FavoriteResolver {
|
||||
connect: { id: args.companyId },
|
||||
},
|
||||
workspaceId: workspace.id,
|
||||
position: args.position,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
}
|
||||
|
||||
@Mutation(() => Favorite, {
|
||||
nullable: false,
|
||||
})
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(UpdateFavoriteAbilityHandler)
|
||||
async updateOneFavorites(
|
||||
@Args() args: UpdateOneFavoriteArgs,
|
||||
@PrismaSelector({ modelName: 'Favorite' })
|
||||
prismaSelect: PrismaSelect<'Favorite'>,
|
||||
): Promise<Partial<Favorite>> {
|
||||
return this.favoriteService.update({
|
||||
data: args.data,
|
||||
where: args.where,
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
}
|
||||
|
||||
@Mutation(() => Favorite, {
|
||||
nullable: false,
|
||||
})
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `position` to the `favorites` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "favorites" ADD COLUMN "position" DOUBLE PRECISION NOT NULL;
|
||||
@ -789,6 +789,7 @@ model Favorite {
|
||||
/// @TypeGraphQL.omit(input: true, output: false)
|
||||
workspaceMember WorkspaceMember? @relation(fields: [workspaceMemberId], references: [id])
|
||||
workspaceMemberId String?
|
||||
position Float
|
||||
|
||||
@@map("favorites")
|
||||
}
|
||||
@ -892,19 +893,19 @@ model ViewField {
|
||||
model ApiKey {
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
expiresAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
expiresAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
deletedAt DateTime?
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
revokedAt DateTime?
|
||||
revokedAt DateTime?
|
||||
|
||||
@@map("api_keys")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user