83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
// import { PrismaClient } from '@prisma/client'
|
|
// const prisma = new PrismaClient()
|
|
|
|
// //CREAR NUEVO TAG
|
|
|
|
// export const createTag = async (tagData: { name: string; slug: string; color?: string }) => {
|
|
// try {
|
|
// const normalizedTagSlug = tagData.slug.toLowerCase()
|
|
// const existingTagMinus = await prisma.tag.findUnique({
|
|
// where: { slug: normalizedTagSlug }
|
|
// })
|
|
|
|
// if (existingTagMinus) {
|
|
// console.error(`Error al crear el Tag: El SLUG "${tagData.slug}" ya está en uso.`)
|
|
// throw new Error(`Error al crear el Tag: El SLUG "${tagData.slug}" ya está en uso.`)
|
|
// }
|
|
|
|
// const newTag = await prisma.tag.create({
|
|
// data: { ...tagData, slug: normalizedTagSlug }
|
|
// })
|
|
|
|
// return newTag
|
|
// } catch (error) {
|
|
// console.error('Error al crear el Tag:', error)
|
|
// throw new Error('Error al crear el Tag')
|
|
// }
|
|
// }
|
|
|
|
// // OBTENER TODOS LOS TAGS
|
|
|
|
// export const getAllTags = async () => {
|
|
// try {
|
|
// const tags = await prisma.tag.findMany()
|
|
// return tags
|
|
// } catch (error) {
|
|
// console.error('Error al obtener todos los Tags:', error)
|
|
// throw new Error('Error al obtener todos los Tags')
|
|
// }
|
|
// }
|
|
|
|
// // OBTENER UN TAG POR SU ID
|
|
|
|
// export const getTagById = async (tagId: string) => {
|
|
// try {
|
|
// const tag = await prisma.tag.findUnique({
|
|
// where: { id: tagId }
|
|
// })
|
|
// return tag
|
|
// } catch (error) {
|
|
// console.error('Error al obtener el Tag por ID:', error)
|
|
// throw new Error('Error al obtener el Tag por ID')
|
|
// }
|
|
// }
|
|
|
|
// //ACTUALIZAR UN TAG
|
|
|
|
// export const updateTag = async (tagData: { id: string; name?: string; slug?: string; color?: string }) => {
|
|
// try {
|
|
// const updatedTag = await prisma.tag.update({
|
|
// where: { id: tagData.id },
|
|
// data: { name: tagData.name, slug: tagData.slug, color: tagData.color }
|
|
// })
|
|
// return updatedTag
|
|
// } catch (error) {
|
|
// console.error('Error al actualizar el Tag:', error)
|
|
// throw new Error('Error al actualizar el Tag')
|
|
// }
|
|
// }
|
|
|
|
// // ELIMINAR UN TAG
|
|
|
|
// export const deleteTag = async (tagId: string) => {
|
|
// try {
|
|
// const deletedTag = await prisma.tag.delete({
|
|
// where: { id: tagId }
|
|
// })
|
|
// return deletedTag
|
|
// } catch (error) {
|
|
// console.error('Error al eliminar el Tag:', error)
|
|
// throw new Error('Error al eliminar el Tag')
|
|
// }
|
|
// }
|