From 01ad69a4b075db87b868be92e140bcc229998988 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Mon, 2 Mar 2026 23:07:30 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=94=20feat:=20add=20banner=20priority?= =?UTF-8?q?=20ordering=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prisma/dbml/schema.dbml | 1 + .../migration.sql | 11 +++++++++++ .../migration.sql | 16 ++++++++++++++++ prisma/schema.prisma | 1 + .../GET/findAllActiveHeroBanner.repository.ts | 8 ++++++++ 5 files changed, 37 insertions(+) create mode 100644 prisma/migrations/20260302155255_add_order_in_hero_banner/migration.sql create mode 100644 prisma/migrations/20260302160211_rename_order_column/migration.sql diff --git a/prisma/dbml/schema.dbml b/prisma/dbml/schema.dbml index 5cede02..6996dca 100644 --- a/prisma/dbml/schema.dbml +++ b/prisma/dbml/schema.dbml @@ -495,6 +495,7 @@ Table email_system_histories { Table hero_banner { id String [pk] + orderPriority Int [unique] isClickable Boolean [not null, default: false] title String description String diff --git a/prisma/migrations/20260302155255_add_order_in_hero_banner/migration.sql b/prisma/migrations/20260302155255_add_order_in_hero_banner/migration.sql new file mode 100644 index 0000000..0d0e645 --- /dev/null +++ b/prisma/migrations/20260302155255_add_order_in_hero_banner/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - A unique constraint covering the columns `[order]` on the table `hero_banner` will be added. If there are existing duplicate values, this will fail. + +*/ +-- AlterTable +ALTER TABLE "hero_banner" ADD COLUMN "order" INTEGER; + +-- CreateIndex +CREATE UNIQUE INDEX "hero_banner_order_key" ON "hero_banner"("order"); diff --git a/prisma/migrations/20260302160211_rename_order_column/migration.sql b/prisma/migrations/20260302160211_rename_order_column/migration.sql new file mode 100644 index 0000000..532f842 --- /dev/null +++ b/prisma/migrations/20260302160211_rename_order_column/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the column `order` on the `hero_banner` table. All the data in the column will be lost. + - A unique constraint covering the columns `[orderPriority]` on the table `hero_banner` will be added. If there are existing duplicate values, this will fail. + +*/ +-- DropIndex +DROP INDEX "hero_banner_order_key"; + +-- AlterTable +ALTER TABLE "hero_banner" DROP COLUMN "order", +ADD COLUMN "orderPriority" INTEGER; + +-- CreateIndex +CREATE UNIQUE INDEX "hero_banner_orderPriority_key" ON "hero_banner"("orderPriority"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5e1d9ba..4c9b2be 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -556,6 +556,7 @@ model EmailSystemHistory { model HeroBanner { id String @id @db.Uuid + orderPriority Int? @unique isClickable Boolean @default(false) title String? @db.VarChar(225) description String? @db.Text diff --git a/src/modules/heroBanner/repositories/GET/findAllActiveHeroBanner.repository.ts b/src/modules/heroBanner/repositories/GET/findAllActiveHeroBanner.repository.ts index 6b899d9..e5cc8b1 100644 --- a/src/modules/heroBanner/repositories/GET/findAllActiveHeroBanner.repository.ts +++ b/src/modules/heroBanner/repositories/GET/findAllActiveHeroBanner.repository.ts @@ -12,6 +12,14 @@ export const findAllActiveHeroBannerRepository = async () => { gte: new Date(), }, }, + orderBy: [ + { + orderPriority: "asc", + }, + { + startDate: "asc", + }, + ], }); } catch (error) { throw new AppError(500, "Failed to fetch active hero banners", error);