ыввы
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
-- RedefineTables
|
||||
PRAGMA defer_foreign_keys=ON;
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_CatalogSliderSlide" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"sortOrder" INTEGER NOT NULL,
|
||||
"caption" TEXT NOT NULL DEFAULT '',
|
||||
"textColor" TEXT NOT NULL DEFAULT '#ffffff',
|
||||
"galleryImageId" TEXT NOT NULL,
|
||||
CONSTRAINT "CatalogSliderSlide_galleryImageId_fkey" FOREIGN KEY ("galleryImageId") REFERENCES "GalleryImage" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_CatalogSliderSlide" ("caption", "galleryImageId", "id", "sortOrder") SELECT "caption", "galleryImageId", "id", "sortOrder" FROM "CatalogSliderSlide";
|
||||
DROP TABLE "CatalogSliderSlide";
|
||||
ALTER TABLE "new_CatalogSliderSlide" RENAME TO "CatalogSliderSlide";
|
||||
CREATE INDEX "CatalogSliderSlide_sortOrder_idx" ON "CatalogSliderSlide"("sortOrder");
|
||||
PRAGMA foreign_keys=ON;
|
||||
PRAGMA defer_foreign_keys=OFF;
|
||||
Binary file not shown.
@@ -68,6 +68,7 @@ model CatalogSliderSlide {
|
||||
id String @id @default(cuid())
|
||||
sortOrder Int
|
||||
caption String @default("")
|
||||
textColor String @default("#ffffff")
|
||||
galleryImageId String
|
||||
galleryImage GalleryImage @relation(fields: [galleryImageId], references: [id], onDelete: Cascade)
|
||||
|
||||
|
||||
@@ -13,7 +13,35 @@ export async function registerAdminGalleryRoutes(fastify) {
|
||||
const items = await prisma.galleryImage.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
return { items }
|
||||
|
||||
const urls = items.map((i) => i.url)
|
||||
const usedUrls = new Set()
|
||||
|
||||
const productImages = await prisma.productImage.findMany({
|
||||
where: { url: { in: urls } },
|
||||
select: { url: true },
|
||||
})
|
||||
for (const pi of productImages) {
|
||||
usedUrls.add(pi.url)
|
||||
}
|
||||
|
||||
const legacyProducts = await prisma.product.findMany({
|
||||
where: { imageUrl: { in: urls } },
|
||||
select: { imageUrl: true },
|
||||
})
|
||||
for (const p of legacyProducts) {
|
||||
if (p.imageUrl) usedUrls.add(p.imageUrl)
|
||||
}
|
||||
|
||||
return {
|
||||
items: items.map((i) => ({
|
||||
id: i.id,
|
||||
url: i.url,
|
||||
isResized: i.isResized,
|
||||
createdAt: i.createdAt,
|
||||
inUse: usedUrls.has(i.url),
|
||||
})),
|
||||
}
|
||||
})
|
||||
|
||||
fastify.post('/api/admin/gallery/upload', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
|
||||
|
||||
@@ -14,6 +14,7 @@ export async function registerCatalogSliderRoutes(fastify) {
|
||||
id: s.id,
|
||||
url: s.galleryImage.url,
|
||||
caption: s.caption,
|
||||
textColor: s.textColor,
|
||||
})),
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -34,6 +35,7 @@ export async function registerCatalogSliderRoutes(fastify) {
|
||||
galleryImageId: s.galleryImageId,
|
||||
url: s.galleryImage.url,
|
||||
caption: s.caption,
|
||||
textColor: s.textColor,
|
||||
})),
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -70,7 +72,8 @@ export async function registerCatalogSliderRoutes(fastify) {
|
||||
return reply.code(400).send({ error: `Изображение не найдено: ${galleryImageId}` })
|
||||
}
|
||||
const caption = row?.caption == null ? '' : String(row.caption).slice(0, 500)
|
||||
normalized.push({ galleryImageId, caption, sortOrder: i })
|
||||
const textColor = String(row?.textColor || '#ffffff').trim()
|
||||
normalized.push({ galleryImageId, caption, textColor, sortOrder: i })
|
||||
}
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
@@ -80,6 +83,7 @@ export async function registerCatalogSliderRoutes(fastify) {
|
||||
data: {
|
||||
sortOrder: n.sortOrder,
|
||||
caption: n.caption,
|
||||
textColor: n.textColor,
|
||||
galleryImageId: n.galleryImageId,
|
||||
},
|
||||
})
|
||||
@@ -96,6 +100,7 @@ export async function registerCatalogSliderRoutes(fastify) {
|
||||
galleryImageId: s.galleryImageId,
|
||||
url: s.galleryImage.url,
|
||||
caption: s.caption,
|
||||
textColor: s.textColor,
|
||||
})),
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user