Repository navigation
Banners en homepage y su gestión por admins #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "Banners" ( | ||
| "id_banner" SERIAL NOT NULL, | ||
| "title" VARCHAR(120) NOT NULL, | ||
|
Check warning on line 4 in prisma/migrations/20260521004958_add_banners/migration.sql
|
||
| "description" TEXT, | ||
| "image_url" VARCHAR(500) NOT NULL, | ||
|
Check warning on line 6 in prisma/migrations/20260521004958_add_banners/migration.sql
|
||
| "link_url" VARCHAR(500), | ||
|
Check warning on line 7 in prisma/migrations/20260521004958_add_banners/migration.sql
|
||
| "start_at" TIMESTAMPTZ NOT NULL, | ||
| "end_at" TIMESTAMPTZ, | ||
| "is_active" BOOLEAN NOT NULL DEFAULT true, | ||
| "status" BOOLEAN NOT NULL DEFAULT true, | ||
| "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" TIMESTAMPTZ NOT NULL, | ||
|
|
||
| CONSTRAINT "Banners_pkey" PRIMARY KEY ("id_banner") | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| export const adminBannerSchemas = { | ||
| AdminBannerCreateBody: { | ||
| type: "object", | ||
| required: ["title", "imageUrl", "startAt"], | ||
| properties: { | ||
| title: { type: "string", minLength: 1, maxLength: 120, example: "Semana Eco" }, | ||
| description: { type: "string", nullable: true, example: "Descuentos hasta 30%" }, | ||
| imageUrl: { type: "string", example: "https://cdn.example.com/banners/eco.jpg" }, | ||
| linkUrl: { type: "string", nullable: true, example: "https://frontend.example.com/ofertas" }, | ||
| startAt: { type: "string", format: "date-time" }, | ||
| endAt: { type: "string", format: "date-time", nullable: true }, | ||
| isActive: { type: "boolean", example: true } | ||
| } | ||
| }, | ||
| AdminBannerUpdateBody: { | ||
| type: "object", | ||
| properties: { | ||
| title: { type: "string", minLength: 1, maxLength: 120, example: "Semana Eco" }, | ||
| description: { type: "string", nullable: true, example: "Descuentos hasta 30%" }, | ||
| imageUrl: { type: "string", example: "https://cdn.example.com/banners/eco.jpg" }, | ||
| linkUrl: { type: "string", nullable: true, example: "https://frontend.example.com/ofertas" }, | ||
| startAt: { type: "string", format: "date-time" }, | ||
| endAt: { type: "string", format: "date-time", nullable: true }, | ||
| isActive: { type: "boolean", example: true } | ||
| } | ||
| }, | ||
| AdminBannerToggleBody: { | ||
| type: "object", | ||
| required: ["isActive"], | ||
| properties: { | ||
| isActive: { type: "boolean", example: false } | ||
| } | ||
| }, | ||
| AdminBannerResponse: { | ||
| type: "object", | ||
| properties: { | ||
| id: { type: "integer", example: 12 }, | ||
| title: { type: "string", example: "Semana Eco" }, | ||
| description: { type: "string", nullable: true, example: "Descuentos hasta 30%" }, | ||
| imageUrl: { type: "string", example: "https://cdn.example.com/banners/eco.jpg" }, | ||
| linkUrl: { type: "string", nullable: true, example: "https://frontend.example.com/ofertas" }, | ||
| startAt: { type: "string", format: "date-time" }, | ||
| endAt: { type: "string", format: "date-time", nullable: true }, | ||
| isActive: { type: "boolean", example: true }, | ||
| status: { type: "boolean", example: true }, | ||
| createdAt: { type: "string", format: "date-time" }, | ||
| updatedAt: { type: "string", format: "date-time" } | ||
| } | ||
| }, | ||
| AdminBannerListResponse: { | ||
| type: "object", | ||
| properties: { | ||
| data: { | ||
| type: "array", | ||
| items: { $ref: "#/components/schemas/AdminBannerResponse" } | ||
| }, | ||
| pagination: { | ||
| type: "object", | ||
| properties: { | ||
| total: { type: "integer", example: 3 }, | ||
| page: { type: "integer", example: 1 }, | ||
| limit: { type: "integer", example: 20 }, | ||
| totalPages: { type: "integer", example: 1 } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| export const bannerSchemas = { | ||
| BannerPublicResponse: { | ||
| type: "object", | ||
| properties: { | ||
| id: { type: "integer", example: 12 }, | ||
| title: { type: "string", example: "Semana Eco" }, | ||
| description: { type: "string", nullable: true, example: "Descuentos hasta 30%" }, | ||
| imageUrl: { type: "string", example: "https://cdn.example.com/banners/eco.jpg" }, | ||
| linkUrl: { type: "string", nullable: true, example: "https://frontend.example.com/ofertas" }, | ||
| startAt: { type: "string", format: "date-time" }, | ||
| endAt: { type: "string", format: "date-time", nullable: true }, | ||
| isActive: { type: "boolean", example: true }, | ||
| createdAt: { type: "string", format: "date-time" } | ||
| } | ||
| }, | ||
| BannerPublicListResponse: { | ||
| type: "array", | ||
| items: { $ref: "#/components/schemas/BannerPublicResponse" } | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { validateId } from "../../../lib/validators.js"; | ||
| import { | ||
| createAdminBannerService, | ||
| getAdminBannersService, | ||
| toggleAdminBannerActiveService, | ||
| updateAdminBannerService, | ||
| } from "./admin-banners.service.js"; | ||
|
|
||
| export const createAdminBanner = async (req, res, next) => { | ||
| try { | ||
| const result = await createAdminBannerService(req.body); | ||
| return res.status(201).json(result); | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }; | ||
|
|
||
| export const getAdminBanners = async (req, res, next) => { | ||
| try { | ||
| const { search, active, status } = req.query; | ||
| const result = await getAdminBannersService({ search, active, status }, req.pagination); | ||
| return res.status(200).json(result); | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }; | ||
|
|
||
| export const updateAdminBanner = async (req, res, next) => { | ||
| try { | ||
| const id = validateId(req.params.id); | ||
| const result = await updateAdminBannerService(id, req.body); | ||
| return res.status(200).json(result); | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }; | ||
|
|
||
| export const toggleAdminBannerActive = async (req, res, next) => { | ||
| try { | ||
| const id = validateId(req.params.id); | ||
| const result = await toggleAdminBannerActiveService(id, req.body?.isActive); | ||
| return res.status(200).json(result); | ||
| } catch (error) { | ||
| next(error); | ||
| } | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.