Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
adminStoresRoutes,
adminProductsRoutes,
adminBannersRoutes,
adminTagRoutes,
} from "./modules/admin/index.js";
import { bannerRoutes } from "./modules/global/banners/banners.routes.js";

Expand Down Expand Up @@ -134,6 +135,7 @@ app.use("/api/admin/categories", adminCategoryRoutes);
app.use("/api/admin/stores", adminStoresRoutes);
app.use("/api/admin/products", adminProductsRoutes);
app.use("/api/admin/banners", adminBannersRoutes);
app.use("/api/admin/tags", adminTagRoutes);

// Rutas de distancias
app.use("/api/distances", distanceRoutes);
Expand Down
3 changes: 2 additions & 1 deletion src/modules/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from "./categories/admin-category.routes.js";
export * from "./users/admin-users.routes.js";
export * from "./stores/admin-stores.routes.js";
export * from "./products/admin-products.routes.js";
export * from "./banners/admin-banners.routes.js";
export * from "./banners/admin-banners.routes.js";
export * from "./tags/admin-tag.routes.js";
45 changes: 45 additions & 0 deletions src/modules/admin/tags/admin-tag.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { validateId } from "../../../lib/validators.js";
import {
createAdminTagService,
getAllAdminTagsService,
updateAdminTagService,
deleteAdminTagService
} from "./admin-tag.service.js";

export const createAdminTag = async (req, res, next) => {
try {
const result = await createAdminTagService(req.body?.name);
return res.status(201).json(result);
} catch (error) {
next(error);
}
};

export const getAdminTags = async (req, res, next) => {
try {
const result = await getAllAdminTagsService();
return res.status(200).json(result);
} catch (error) {
next(error);
}
};

export const updateAdminTag = async (req, res, next) => {
try {
const id = validateId(req.params.id);
const result = await updateAdminTagService(id, req.body?.name);
return res.status(200).json(result);
} catch (error) {
next(error);
}
};

export const deleteAdminTag = async (req, res, next) => {
try {
const id = validateId(req.params.id);
await deleteAdminTagService(id);
return res.status(204).send();
} catch (error) {
next(error);
}
};
186 changes: 186 additions & 0 deletions src/modules/admin/tags/admin-tag.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import { Router } from "express";
import authenticate from "../../../config/jwt.config.js";
import { requireRole } from "../../../middlewares/auth.middleware.js";
import {
createAdminTag,
getAdminTags,
updateAdminTag,
deleteAdminTag
} from "./admin-tag.controller.js";
import { ROLES } from "../../../constants/roles.constant.js";

const router = Router();

/**
* @swagger
* /api/admin/tags:
* post:
* summary: Crear etiqueta de producto (Admin)
* tags: [Admin]
* security:
* - cookieAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* properties:
* name:
* type: string
* maxLength: 20
* example: Orgánico
* responses:
* 201:
* description: Etiqueta creada correctamente
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: integer
* name:
* type: string
* status:
* type: boolean
* createdAt:
* type: string
* format: date-time
* 400:
* description: Nombre inválido o etiqueta activa duplicada
* 401:
* description: No autenticado
* 403:
* description: Sin permisos de administrador
*/
router.post("/", authenticate, requireRole(ROLES.ADMIN), createAdminTag);

/**
* @swagger
* /api/admin/tags:
* get:
* summary: Listar etiquetas de producto (Admin)
* tags: [Admin]
* security:
* - cookieAuth: []
* responses:
* 200:
* description: Lista de etiquetas activas
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* id:
* type: integer
* name:
* type: string
* status:
* type: boolean
* productCount:
* type: integer
* createdAt:
* type: string
* format: date-time
* updatedAt:
* type: string
* format: date-time
* 401:
* description: No autenticado
* 403:
* description: Sin permisos de administrador
*/
router.get("/", authenticate, requireRole(ROLES.ADMIN), getAdminTags);

/**
* @swagger
* /api/admin/tags/{id}:
* patch:
* summary: Editar nombre de etiqueta de producto (Admin)
* tags: [Admin]
* security:
* - cookieAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* properties:
* name:
* type: string
* maxLength: 20
* example: Vegano
* responses:
* 200:
* description: Etiqueta actualizada correctamente
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: integer
* name:
* type: string
* status:
* type: boolean
* createdAt:
* type: string
* format: date-time
* updatedAt:
* type: string
* format: date-time
* 400:
* description: Nombre inválido o etiqueta activa duplicada
* 401:
* description: No autenticado
* 403:
* description: Sin permisos de administrador
* 404:
* description: Etiqueta no encontrada
*/
router.patch("/:id", authenticate, requireRole(ROLES.ADMIN), updateAdminTag);

/**
* @swagger
* /api/admin/tags/{id}:
* delete:
* summary: Eliminar etiqueta de producto (Admin)
* tags: [Admin]
* security:
* - cookieAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* responses:
* 204:
* description: Etiqueta eliminada correctamente
* 400:
* description: ID inválido
* 401:
* description: No autenticado
* 403:
* description: Sin permisos de administrador
* 404:
* description: Etiqueta no encontrada
*/
router.delete("/:id", authenticate, requireRole(ROLES.ADMIN), deleteAdminTag);

export { router as adminTagRoutes };
Loading
Loading