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 { ContentStatus } from '@prisma/client';
|
||||||
import { Type } from 'class-transformer';
|
import { Transform, Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
|
IsBoolean,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
IsInt,
|
IsInt,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@@ -176,6 +177,12 @@ export class UpdatePortfolioDto {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
sortOrder?: number;
|
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()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
@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 updated = await this.prisma.$transaction(async (tx) => {
|
||||||
const data: Prisma.portfoliosUncheckedUpdateInput = {
|
const data: Prisma.portfoliosUncheckedUpdateInput = {
|
||||||
slug,
|
slug,
|
||||||
@@ -302,7 +306,9 @@ export class PortfoliosService {
|
|||||||
if (featuredMediaId !== undefined) {
|
if (featuredMediaId !== undefined) {
|
||||||
data.featured_media_id = featuredMediaId;
|
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;
|
data.sort_order = dto.sortOrder;
|
||||||
}
|
}
|
||||||
if (publishedAt !== undefined) {
|
if (publishedAt !== undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user