feat: add Bytescale image uploads
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Doctor" ADD COLUMN "image" TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Department" ADD COLUMN "image" TEXT;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "NewsImage" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"url" TEXT NOT NULL,
|
||||
"newsMediaId" INTEGER NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "NewsImage_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "NewsImage" ADD CONSTRAINT "NewsImage_newsMediaId_fkey" FOREIGN KEY ("newsMediaId") REFERENCES "NewsMedia"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -21,6 +21,7 @@ model Doctor {
|
||||
id Int @id @default(autoincrement())
|
||||
doctorId String @unique
|
||||
name String
|
||||
image String?
|
||||
designation String?
|
||||
workingStatus String?
|
||||
qualification String?
|
||||
@@ -36,6 +37,8 @@ model Department {
|
||||
id Int @id @default(autoincrement())
|
||||
departmentId String @unique
|
||||
name String
|
||||
image String?
|
||||
|
||||
|
||||
para1 String?
|
||||
para2 String?
|
||||
@@ -188,17 +191,25 @@ model EmailConfig {
|
||||
}
|
||||
|
||||
model NewsMedia {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
id Int @id @default(autoincrement())
|
||||
headline String
|
||||
content String?
|
||||
firstPara String?
|
||||
secondPara String?
|
||||
author String?
|
||||
date DateTime?
|
||||
images NewsImage[]
|
||||
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
model NewsImage {
|
||||
id Int @id @default(autoincrement())
|
||||
url String
|
||||
newsMediaId Int
|
||||
newsMedia NewsMedia @relation(fields: [newsMediaId], references: [id], onDelete: Cascade)
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export const getAllDepartments = async (req, res) => {
|
||||
const response = departments.map((dep) => ({
|
||||
departmentId: dep.departmentId,
|
||||
name: dep.name,
|
||||
image: dep.image ?? "",
|
||||
para1: dep.para1 ?? "",
|
||||
para2: dep.para2 ?? "",
|
||||
para3: dep.para3 ?? "",
|
||||
@@ -56,6 +57,7 @@ export const getDepartmentByName = async (req, res) => {
|
||||
const response = {
|
||||
departmentId: department.departmentId,
|
||||
name: department.name,
|
||||
image: department.image ?? "",
|
||||
para1: department.para1 ?? "",
|
||||
para2: department.para2 ?? "",
|
||||
para3: department.para3 ?? "",
|
||||
@@ -78,8 +80,16 @@ export const getDepartmentByName = async (req, res) => {
|
||||
|
||||
export async function createDepartment(req, res) {
|
||||
try {
|
||||
const {departmentId, name, para1, para2, para3, facilities, services} =
|
||||
req.body;
|
||||
const {
|
||||
departmentId,
|
||||
name,
|
||||
image,
|
||||
para1,
|
||||
para2,
|
||||
para3,
|
||||
facilities,
|
||||
services,
|
||||
} = req.body;
|
||||
|
||||
if (!departmentId || !name) {
|
||||
return res
|
||||
@@ -91,6 +101,7 @@ export async function createDepartment(req, res) {
|
||||
data: {
|
||||
departmentId,
|
||||
name,
|
||||
image,
|
||||
para1,
|
||||
para2,
|
||||
para3,
|
||||
@@ -116,12 +127,13 @@ export const updateDepartment = async (req, res) => {
|
||||
try {
|
||||
const {departmentId} = req.params;
|
||||
|
||||
const {name, para1, para2, para3, facilities, services} = req.body;
|
||||
const {name, image, para1, para2, para3, facilities, services} = req.body;
|
||||
|
||||
const department = await prisma.department.update({
|
||||
where: {departmentId},
|
||||
data: {
|
||||
name,
|
||||
image,
|
||||
para1,
|
||||
para2,
|
||||
para3,
|
||||
|
||||
@@ -20,6 +20,7 @@ export const getAllDoctors = async (req, res) => {
|
||||
SL_NO: String(index + 1),
|
||||
doctorId: doc.doctorId,
|
||||
name: doc.name,
|
||||
image: doc.image ?? "",
|
||||
designation: doc.designation,
|
||||
workingStatus: doc.workingStatus,
|
||||
qualification: doc.qualification,
|
||||
@@ -87,6 +88,7 @@ export const getDoctorByDoctorId = async (req, res) => {
|
||||
const response = {
|
||||
doctorId: doctor.doctorId,
|
||||
name: doctor.name,
|
||||
image: doctor.image ?? "",
|
||||
designation: doctor.designation,
|
||||
workingStatus: doctor.workingStatus,
|
||||
qualification: doctor.qualification,
|
||||
@@ -164,6 +166,7 @@ export const createDoctor = async (req, res) => {
|
||||
const {
|
||||
doctorId,
|
||||
name,
|
||||
image,
|
||||
designation,
|
||||
workingStatus,
|
||||
qualification,
|
||||
@@ -174,6 +177,7 @@ export const createDoctor = async (req, res) => {
|
||||
data: {
|
||||
doctorId,
|
||||
name,
|
||||
image,
|
||||
designation,
|
||||
workingStatus,
|
||||
qualification,
|
||||
@@ -221,8 +225,14 @@ export const createDoctor = async (req, res) => {
|
||||
export const updateDoctor = async (req, res) => {
|
||||
try {
|
||||
const {doctorId} = req.params;
|
||||
const {name, designation, workingStatus, qualification, departments} =
|
||||
req.body;
|
||||
const {
|
||||
name,
|
||||
designation,
|
||||
image,
|
||||
workingStatus,
|
||||
qualification,
|
||||
departments,
|
||||
} = req.body;
|
||||
|
||||
const doctor = await prisma.doctor.findUnique({
|
||||
where: {doctorId},
|
||||
@@ -236,7 +246,7 @@ export const updateDoctor = async (req, res) => {
|
||||
|
||||
await prisma.doctor.update({
|
||||
where: {id: doctor.id},
|
||||
data: {name, designation, workingStatus, qualification},
|
||||
data: {name, designation, image, workingStatus, qualification},
|
||||
});
|
||||
|
||||
const oldRelations = await prisma.doctorDepartment.findMany({
|
||||
|
||||
@@ -7,8 +7,13 @@ export const getAllNews = async (req, res) => {
|
||||
const page = parseInt(req.query.page);
|
||||
const limit = parseInt(req.query.limit);
|
||||
|
||||
const includeImages = {
|
||||
images: true,
|
||||
};
|
||||
|
||||
if (!page && !limit) {
|
||||
const news = await prisma.newsMedia.findMany({
|
||||
include: includeImages,
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
@@ -20,6 +25,10 @@ export const getAllNews = async (req, res) => {
|
||||
SecondPara: n.secondPara,
|
||||
Date: n.date,
|
||||
Author: n.author,
|
||||
Images: n.images.map((img) => ({
|
||||
id: img.id,
|
||||
image: img.url,
|
||||
})),
|
||||
}));
|
||||
|
||||
return res.status(200).json({
|
||||
@@ -36,6 +45,7 @@ export const getAllNews = async (req, res) => {
|
||||
|
||||
const [news, total] = await Promise.all([
|
||||
prisma.newsMedia.findMany({
|
||||
include: includeImages,
|
||||
orderBy: { createdAt: "desc" },
|
||||
skip,
|
||||
take: currentLimit,
|
||||
@@ -51,6 +61,10 @@ export const getAllNews = async (req, res) => {
|
||||
SecondPara: n.secondPara,
|
||||
Date: n.date,
|
||||
Author: n.author,
|
||||
Images: n.images.map((img) => ({
|
||||
id: img.id,
|
||||
image: img.url,
|
||||
})),
|
||||
}));
|
||||
|
||||
return res.status(200).json({
|
||||
@@ -80,6 +94,7 @@ export const getNewsById = async (req, res) => {
|
||||
|
||||
const n = await prisma.newsMedia.findUnique({
|
||||
where: { id: Number(id) },
|
||||
include: { images: true },
|
||||
});
|
||||
|
||||
if (!n) {
|
||||
@@ -97,6 +112,10 @@ export const getNewsById = async (req, res) => {
|
||||
SecondPara: n.secondPara,
|
||||
Date: n.date,
|
||||
Author: n.author,
|
||||
Images: n.images.map((img) => ({
|
||||
id: img.id,
|
||||
image: img.url,
|
||||
})),
|
||||
};
|
||||
|
||||
return res.status(200).json({
|
||||
@@ -116,7 +135,15 @@ export const getNewsById = async (req, res) => {
|
||||
|
||||
export const createNews = async (req, res) => {
|
||||
try {
|
||||
const { headline, content, firstPara, secondPara, date, author } = req.body;
|
||||
const {
|
||||
headline,
|
||||
content,
|
||||
firstPara,
|
||||
secondPara,
|
||||
date,
|
||||
author,
|
||||
imageUrls,
|
||||
} = req.body;
|
||||
|
||||
if (!headline) {
|
||||
return res.status(400).json({
|
||||
@@ -133,7 +160,13 @@ export const createNews = async (req, res) => {
|
||||
secondPara,
|
||||
date: date ? new Date(date) : null,
|
||||
author,
|
||||
images: imageUrls
|
||||
? {
|
||||
create: imageUrls.map((url) => ({ url })),
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
include: { images: true },
|
||||
});
|
||||
|
||||
return res.status(201).json({
|
||||
@@ -155,13 +188,21 @@ export const createNews = async (req, res) => {
|
||||
export const updateNews = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { imageUrls, ...otherData } = req.body;
|
||||
|
||||
const news = await prisma.newsMedia.update({
|
||||
where: { id: Number(id) },
|
||||
data: {
|
||||
...req.body,
|
||||
...otherData,
|
||||
date: req.body.date ? new Date(req.body.date) : undefined,
|
||||
images: imageUrls
|
||||
? {
|
||||
deleteMany: {},
|
||||
create: imageUrls.map((url) => ({ url })),
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
include: { images: true },
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
|
||||
Reference in New Issue
Block a user