Add moveToTop on portfolio update so items pin to absolute list top.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
af0573c089
commit
37bce1e9fa
@@ -1,7 +1,8 @@
|
||||
import { ContentStatus } from '@prisma/client';
|
||||
import { Type } from 'class-transformer';
|
||||
import { Transform, Type } from 'class-transformer';
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
@@ -176,6 +177,12 @@ export class UpdatePortfolioDto {
|
||||
@IsInt()
|
||||
sortOrder?: number;
|
||||
|
||||
/** Pin this portfolio to the top of the list (max sort_order + 1). */
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => value === true || value === 'true')
|
||||
@IsBoolean()
|
||||
moveToTop?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
||||
|
||||
@@ -280,6 +280,10 @@ export class PortfoliosService {
|
||||
}
|
||||
}
|
||||
|
||||
const pinnedSortOrder = dto.moveToTop
|
||||
? await this.nextSortOrder(businessId)
|
||||
: undefined;
|
||||
|
||||
const updated = await this.prisma.$transaction(async (tx) => {
|
||||
const data: Prisma.portfoliosUncheckedUpdateInput = {
|
||||
slug,
|
||||
@@ -302,7 +306,9 @@ export class PortfoliosService {
|
||||
if (featuredMediaId !== undefined) {
|
||||
data.featured_media_id = featuredMediaId;
|
||||
}
|
||||
if (dto.sortOrder !== undefined) {
|
||||
if (pinnedSortOrder !== undefined) {
|
||||
data.sort_order = pinnedSortOrder;
|
||||
} else if (dto.sortOrder !== undefined) {
|
||||
data.sort_order = dto.sortOrder;
|
||||
}
|
||||
if (publishedAt !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user